1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Math/BsVector3.h" |
7 | #include "Math/BsVector2.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @addtogroup Physics |
12 | * @{ |
13 | */ |
14 | |
15 | /** Information about a single contact point during physics collision. */ |
16 | struct BS_SCRIPT_EXPORT(m:Physics,pl:true) ContactPoint |
17 | { |
18 | Vector3 position; /**< Contact point in world space. */ |
19 | Vector3 normal; /**< Normal pointing from the second shape to the first shape. */ |
20 | /** Impulse applied to the objects to keep them from penetrating. Divide by simulation step to get the force. */ |
21 | float impulse; |
22 | float separation; /**< Determines how far are the objects. Negative value denotes penetration. */ |
23 | }; |
24 | |
25 | /** Information about a collision between two physics objects. */ |
26 | struct CollisionDataRaw |
27 | { |
28 | Collider* colliders[2]; /**< Colliders involved in the collision. */ |
29 | |
30 | // Note: Not too happy this is heap allocated, use static allocator? |
31 | Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit. */ |
32 | }; |
33 | |
34 | /** Information about a collision between two physics objects. */ |
35 | struct BS_SCRIPT_EXPORT(m:Physics,pl:true) CollisionData |
36 | { |
37 | /** Components of the colliders that have collided. */ |
38 | HCollider collider[2]; |
39 | |
40 | // Note: Not too happy this is heap allocated, use static allocator? |
41 | Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit. */ |
42 | }; |
43 | |
44 | /** Determines what parent, if any, owns a physics object. */ |
45 | enum class PhysicsOwnerType |
46 | { |
47 | None, /** No parent, object is used directly. */ |
48 | Component, /** Object is used by a C++ Component. */ |
49 | Script /** Object is used by the scripting system. */ |
50 | }; |
51 | |
52 | /** Contains information about a parent for a physics object. */ |
53 | struct PhysicsObjectOwner |
54 | { |
55 | PhysicsOwnerType type = PhysicsOwnerType::None; /**< Type of owner. */ |
56 | void* ownerData = nullptr; /**< Data managed by the owner. */ |
57 | }; |
58 | |
59 | /** Determines which collision events will be reported by physics objects. */ |
60 | enum class BS_SCRIPT_EXPORT(m:Physics) CollisionReportMode |
61 | { |
62 | None, /**< No collision events will be triggered. */ |
63 | Report, /**< Collision events will be triggered when object enters and/or leaves collision. */ |
64 | /** |
65 | * Collision events will be triggered when object enters and/or leaves collision, but also every frame the object |
66 | * remains in collision. |
67 | */ |
68 | ReportPersistent, |
69 | }; |
70 | |
71 | /** Hit information from a physics query. */ |
72 | struct BS_SCRIPT_EXPORT(m:Physics,pl:true) PhysicsQueryHit |
73 | { |
74 | Vector3 point; /**< Position of the hit in world space. */ |
75 | Vector3 normal; /**< Normal to the surface that was hit. */ |
76 | Vector2 uv; /**< Barycentric coordinates of the triangle that was hit (only applicable when triangle meshes are hit). */ |
77 | float distance = 0.0f; /**< Distance from the query origin to the hit position. */ |
78 | UINT32 triangleIdx = 0; /**< Index of the triangle that was hit (only applicable when triangle meshes are hit). */ |
79 | |
80 | /** |
81 | * Unmapped index of the triangle that was hit (only applicable when triangle meshes are hit). |
82 | * It represents an index into the original MeshData used to create the PhysicsMesh associated with @p collider. |
83 | * In contrast, @p triangleIdx is only a valid index for the MeshData directly obtained from #collider which can |
84 | * differ from the original MeshData due to the internal implementation. |
85 | */ |
86 | UINT32 unmappedTriangleIdx = 0; |
87 | |
88 | /** |
89 | * Component of the collider that was hit. This may be null if the hit collider has no owner component, in which |
90 | * case refer to #colliderRaw. |
91 | */ |
92 | HCollider collider; |
93 | |
94 | BS_SCRIPT_EXPORT(ex:true) |
95 | Collider* colliderRaw = nullptr; /**< Collider that was hit. */ |
96 | }; |
97 | |
98 | /** @} */ |
99 | } |