BsPhysics.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. #include "BsVector3.h"
  7. #include "BsVector2.h"
  8. #include "BsQuaternion.h"
  9. namespace BansheeEngine
  10. {
  11. struct PHYSICS_INIT_DESC;
  12. /** Flags for controlling physics behaviour globally. */
  13. enum class PhysicsFlag
  14. {
  15. /**
  16. * Automatically recovers character controllers that are interpenetrating geometry. This can happen if a controller
  17. * is spawned or teleported into geometry, its size/rotation is changed so it penetrates geometry, or simply
  18. * because of numerical imprecision.
  19. */
  20. CCT_OverlapRecovery = 1<<0,
  21. /**
  22. * Performs more accurate sweeps when moving the character controller, making it less likely to interpenetrate
  23. * geometry. When overlap recovery is turned on you can consider turning this off as it can compensate for the
  24. * less precise sweeps.
  25. */
  26. CCT_PreciseSweeps = 1<<1,
  27. /**
  28. * Large triangles can cause problems with character controller collision. If this option is enabled the triangles
  29. * larger than a certain size will be automatically tesselated into smaller triangles, in order to help with
  30. * precision.
  31. *
  32. * @see Physics::getMaxTesselationEdgeLength
  33. */
  34. CCT_Tesselation = 1<<2
  35. };
  36. /** @copydoc CharacterCollisionFlag */
  37. typedef Flags<PhysicsFlag> PhysicsFlags;
  38. BS_FLAGS_OPERATORS(PhysicsFlag)
  39. /** Hit information from a physics query. */
  40. struct PhysicsQueryHit
  41. {
  42. Vector3 point; /**< Position of the hit in world space. */
  43. Vector3 normal; /**< Normal to the surface that was hit. */
  44. Vector2 uv; /**< UV coordinates of the triangle that was hit (only applicable when triangle meshes are hit). */
  45. float distance; /**< Distance from the query origin to the hit position. */
  46. UINT32 triangleIdx; /**< Index of the triangle that was hit (only applicable when triangle meshes are hit). */
  47. HCollider collider; /**< Collider that was hit. */
  48. };
  49. class BS_CORE_EXPORT Physics : public Module<Physics>
  50. {
  51. public:
  52. Physics(const PHYSICS_INIT_DESC& init);
  53. virtual ~Physics() { }
  54. virtual void update() = 0;
  55. /******************************************************************************************************************/
  56. /************************************************* CREATION *******************************************************/
  57. /******************************************************************************************************************/
  58. virtual SPtr<PhysicsMaterial> createMaterial(float staticFriction, float dynamicFriction, float restitution) = 0;
  59. virtual SPtr<PhysicsMesh> createMesh(const MeshDataPtr& meshData, PhysicsMeshType type) = 0;
  60. virtual SPtr<Rigidbody> createRigidbody(const HSceneObject& linkedSO) = 0;
  61. virtual SPtr<BoxCollider> createBoxCollider(const Vector3& extents, const Vector3& position,
  62. const Quaternion& rotation) = 0;
  63. virtual SPtr<SphereCollider> createSphereCollider(float radius,
  64. const Vector3& position, const Quaternion& rotation) = 0;
  65. virtual SPtr<PlaneCollider> createPlaneCollider(const Vector3& position, const Quaternion& rotation) = 0;
  66. virtual SPtr<CapsuleCollider> createCapsuleCollider(float radius, float halfHeight,
  67. const Vector3& position, const Quaternion& rotation) = 0;
  68. virtual SPtr<MeshCollider> createMeshCollider(const Vector3& position, const Quaternion& rotation) = 0;
  69. virtual SPtr<FixedJoint> createFixedJoint() = 0;
  70. virtual SPtr<DistanceJoint> createDistanceJoint() = 0;
  71. virtual SPtr<HingeJoint> createHingeJoint() = 0;
  72. virtual SPtr<SphericalJoint> createSphericalJoint() = 0;
  73. virtual SPtr<SliderJoint> createSliderJoint() = 0;
  74. virtual SPtr<D6Joint> createD6Joint() = 0;
  75. /** @copydoc CharacterController::create */
  76. virtual SPtr<CharacterController> createCharacterController(const CHAR_CONTROLLER_DESC& desc) = 0;
  77. /******************************************************************************************************************/
  78. /************************************************* QUERIES ********************************************************/
  79. /******************************************************************************************************************/
  80. /**
  81. * Casts a ray into the scene and returns the closest found hit, if any.
  82. *
  83. * @param[in] ray Ray to cast into the scene.
  84. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  85. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  86. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  87. * detected.
  88. * @return True if something was hit, false otherwise.
  89. */
  90. virtual bool rayCast(const Ray& ray, PhysicsQueryHit& hit, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  91. /**
  92. * Casts a ray into the scene and returns the closest found hit, if any.
  93. *
  94. * @param[in] origin Origin of the ray to cast into the scene.
  95. * @param[in] direction Direction of the ray to cast into the scene.
  96. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  97. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  98. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  99. * detected.
  100. * @return True if something was hit, false otherwise.
  101. */
  102. virtual bool rayCast(const Vector3& origin, const Vector3& direction, PhysicsQueryHit& hit,
  103. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  104. /**
  105. * Performs a sweep into the scene using a box and returns the closest found hit, if any.
  106. *
  107. * @param[in] box Box to sweep through the scene.
  108. * @param[in] rotation Orientation of the box.
  109. * @param[in] direction Direction towards which to perform the sweep.
  110. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  111. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  112. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  113. * detected.
  114. * @return True if something was hit, false otherwise.
  115. */
  116. virtual bool boxCast(const AABox& box, const Quaternion& rotation, const Vector3& direction, PhysicsQueryHit& hit,
  117. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  118. /**
  119. * Performs a sweep into the scene using a sphere and returns the closest found hit, if any.
  120. *
  121. * @param[in] sphere Sphere to sweep through the scene.
  122. * @param[in] direction Direction towards which to perform the sweep.
  123. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  124. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  125. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  126. * detected.
  127. * @return True if something was hit, false otherwise.
  128. */
  129. virtual bool sphereCast(const Sphere& sphere, const Vector3& direction, PhysicsQueryHit& hit,
  130. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  131. /**
  132. * Performs a sweep into the scene using a capsule and returns the closest found hit, if any.
  133. *
  134. * @param[in] capsule Capsule to sweep through the scene.
  135. * @param[in] rotation Orientation of the capsule.
  136. * @param[in] direction Direction towards which to perform the sweep.
  137. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  138. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  139. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  140. * detected.
  141. * @return True if something was hit, false otherwise.
  142. */
  143. virtual bool capsuleCast(const Capsule& capsule, const Quaternion& rotation, const Vector3& direction,
  144. PhysicsQueryHit& hit, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  145. /**
  146. * Performs a sweep into the scene using a convex mesh and returns the closest found hit, if any.
  147. *
  148. * @param[in] mesh Mesh to sweep through the scene. Must be convex.
  149. * @param[in] position Starting position of the mesh.
  150. * @param[in] rotation Orientation of the mesh.
  151. * @param[in] direction Direction towards which to perform the sweep.
  152. * @param[out] hit Information recorded about a hit. Only valid if method returns true.
  153. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  154. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  155. * detected.
  156. * @return True if something was hit, false otherwise.
  157. */
  158. virtual bool convexCast(const HPhysicsMesh& mesh, const Vector3& position, const Quaternion& rotation,
  159. const Vector3& direction, PhysicsQueryHit& hit, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  160. /**
  161. * Casts a ray into the scene and returns all found hits.
  162. *
  163. * @param[in] ray Ray to cast into the scene.
  164. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  165. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  166. * detected.
  167. * @return List of all detected hits.
  168. */
  169. virtual Vector<PhysicsQueryHit> rayCastAll(const Ray& ray, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  170. /**
  171. * Casts a ray into the scene and returns all found hits.
  172. *
  173. * @param[in] origin Origin of the ray to cast into the scene.
  174. * @param[in] direction Direction of the ray to cast into the scene.
  175. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  176. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  177. * detected.
  178. * @return List of all detected hits.
  179. */
  180. virtual Vector<PhysicsQueryHit> rayCastAll(const Vector3& origin, const Vector3& direction,
  181. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  182. /**
  183. * Performs a sweep into the scene using a box and returns all found hits.
  184. *
  185. * @param[in] box Box to sweep through the scene.
  186. * @param[in] rotation Orientation of the box.
  187. * @param[in] direction Direction towards which to perform the sweep.
  188. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  189. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  190. * detected.
  191. * @return List of all detected hits.
  192. */
  193. virtual Vector<PhysicsQueryHit> boxCastAll(const AABox& box, const Quaternion& rotation,
  194. const Vector3& direction, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  195. /**
  196. * Performs a sweep into the scene using a sphere and returns all found hits.
  197. *
  198. * @param[in] sphere Sphere to sweep through the scene.
  199. * @param[in] direction Direction towards which to perform the sweep.
  200. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  201. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  202. * detected.
  203. * @return List of all detected hits.
  204. */
  205. virtual Vector<PhysicsQueryHit> sphereCastAll(const Sphere& sphere, const Vector3& direction,
  206. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  207. /**
  208. * Performs a sweep into the scene using a capsule and returns all found hits.
  209. *
  210. * @param[in] capsule Capsule to sweep through the scene.
  211. * @param[in] rotation Orientation of the capsule.
  212. * @param[in] direction Direction towards which to perform the sweep.
  213. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  214. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  215. * detected.
  216. * @return List of all detected hits.
  217. */
  218. virtual Vector<PhysicsQueryHit> capsuleCastAll(const Capsule& capsule, const Quaternion& rotation,
  219. const Vector3& direction, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  220. /**
  221. * Performs a sweep into the scene using a convex mesh and returns all found hits.
  222. *
  223. * @param[in] mesh Mesh to sweep through the scene. Must be convex.
  224. * @param[in] position Starting position of the mesh.
  225. * @param[in] rotation Orientation of the mesh.
  226. * @param[in] direction Direction towards which to perform the sweep.
  227. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  228. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  229. * detected.
  230. * @return List of all detected hits.
  231. */
  232. virtual Vector<PhysicsQueryHit> convexCastAll(const HPhysicsMesh& mesh, const Vector3& position,
  233. const Quaternion& rotation, const Vector3& direction, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  234. /**
  235. * Casts a ray into the scene and checks if it has hit anything. This can be significantly more efficient than other
  236. * types of cast* calls.
  237. *
  238. * @param[in] ray Ray to cast into the scene.
  239. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  240. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  241. * detected.
  242. * @return True if something was hit, false otherwise.
  243. */
  244. virtual bool rayCastAny(const Ray& ray, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  245. /**
  246. * Casts a ray into the scene and checks if it has hit anything. This can be significantly more efficient than other
  247. * types of cast* calls.
  248. *
  249. * @param[in] origin Origin of the ray to cast into the scene.
  250. * @param[in] direction Direction of the ray to cast into the scene.
  251. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  252. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  253. * detected.
  254. * @return True if something was hit, false otherwise.
  255. */
  256. virtual bool rayCastAny(const Vector3& origin, const Vector3& direction,
  257. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  258. /**
  259. * Performs a sweep into the scene using a box and checks if it has hit anything. This can be significantly more
  260. * efficient than other types of cast* calls.
  261. *
  262. * @param[in] box Box to sweep through the scene.
  263. * @param[in] rotation Orientation of the box.
  264. * @param[in] direction Direction towards which to perform the sweep.
  265. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  266. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  267. * detected.
  268. * @return True if something was hit, false otherwise.
  269. */
  270. virtual bool boxCastAny(const AABox& box, const Quaternion& rotation, const Vector3& direction,
  271. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  272. /**
  273. * Performs a sweep into the scene using a sphere and checks if it has hit anything. This can be significantly more
  274. * efficient than other types of cast* calls.
  275. *
  276. * @param[in] sphere Sphere to sweep through the scene.
  277. * @param[in] direction Direction towards which to perform the sweep.
  278. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  279. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  280. * detected.
  281. * @return True if something was hit, false otherwise.
  282. */
  283. virtual bool sphereCastAny(const Sphere& sphere, const Vector3& direction,
  284. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  285. /**
  286. * Performs a sweep into the scene using a capsule and checks if it has hit anything. This can be significantly more
  287. * efficient than other types of cast* calls.
  288. *
  289. * @param[in] capsule Capsule to sweep through the scene.
  290. * @param[in] rotation Orientation of the capsule.
  291. * @param[in] direction Direction towards which to perform the sweep.
  292. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  293. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  294. * detected.
  295. * @return True if something was hit, false otherwise.
  296. */
  297. virtual bool capsuleCastAny(const Capsule& capsule, const Quaternion& rotation, const Vector3& direction,
  298. UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  299. /**
  300. * Performs a sweep into the scene using a convex mesh and checks if it has hit anything. This can be significantly
  301. * more efficient than other types of cast* calls.
  302. *
  303. * @param[in] mesh Mesh to sweep through the scene. Must be convex.
  304. * @param[in] position Starting position of the mesh.
  305. * @param[in] rotation Orientation of the mesh.
  306. * @param[in] direction Direction towards which to perform the sweep.
  307. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  308. * @param[in] max Maximum distance at which to perform the query. Hits past this distance will not be
  309. * detected.
  310. * @return True if something was hit, false otherwise.
  311. */
  312. virtual bool convexCastAny(const HPhysicsMesh& mesh, const Vector3& position, const Quaternion& rotation,
  313. const Vector3& direction, UINT64 layer = BS_ALL_LAYERS, float max = FLT_MAX) = 0;
  314. /**
  315. * Returns a list of all colliders in the scene that overlap the provided box.
  316. *
  317. * @param[in] box Box to check for overlap.
  318. * @param[in] rotation Orientation of the box.
  319. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  320. * @return List of all colliders that overlap the box.
  321. */
  322. virtual Vector<HCollider> boxOverlap(const AABox& box, const Quaternion& rotation,
  323. UINT64 layer = BS_ALL_LAYERS) = 0;
  324. /**
  325. * Returns a list of all colliders in the scene that overlap the provided sphere.
  326. *
  327. * @param[in] Sphere Sphere to check for overlap.
  328. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  329. * @return List of all colliders that overlap the sphere.
  330. */
  331. virtual Vector<HCollider> sphereOverlap(const Sphere& sphere, UINT64 layer = BS_ALL_LAYERS) = 0;
  332. /**
  333. * Returns a list of all colliders in the scene that overlap the provided capsule.
  334. *
  335. * @param[in] capsule Capsule to check for overlap.
  336. * @param[in] rotation Orientation of the capsule.
  337. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  338. * @return List of all colliders that overlap the capsule.
  339. */
  340. virtual Vector<HCollider> capsuleOverlap(const Capsule& capsule, const Quaternion& rotation,
  341. UINT64 layer = BS_ALL_LAYERS) = 0;
  342. /**
  343. * Returns a list of all colliders in the scene that overlap the provided convex mesh.
  344. *
  345. * @param[in] mesh Mesh to check for overlap. Must be convex.
  346. * @param[in] position Position of the mesh.
  347. * @param[in] rotation Orientation of the mesh.
  348. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  349. * @return List of all colliders that overlap the mesh.
  350. */
  351. virtual Vector<HCollider> convexOverlap(const HPhysicsMesh& mesh, const Vector3& position,
  352. const Quaternion& rotation, UINT64 layer = BS_ALL_LAYERS) = 0;
  353. /**
  354. * Checks if the provided box overlaps any other collider in the scene.
  355. *
  356. * @param[in] box Box to check for overlap.
  357. * @param[in] rotation Orientation of the box.
  358. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  359. * @return True if there is overlap with another object, false otherwise.
  360. */
  361. virtual bool boxOverlapAny(const AABox& box, const Quaternion& rotation, UINT64 layer = BS_ALL_LAYERS) = 0;
  362. /**
  363. * Checks if the provided sphere overlaps any other collider in the scene.
  364. *
  365. * @param[in] sphere Sphere to check for overlap.
  366. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  367. * @return True if there is overlap with another object, false otherwise.
  368. */
  369. virtual bool sphereOverlapAny(const Sphere& sphere, UINT64 layer = BS_ALL_LAYERS) = 0;
  370. /**
  371. * Checks if the provided capsule overlaps any other collider in the scene.
  372. *
  373. * @param[in] capsule Capsule to check for overlap.
  374. * @param[in] rotation Orientation of the capsule.
  375. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  376. * @return True if there is overlap with another object, false otherwise.
  377. */
  378. virtual bool capsuleOverlapAny(const Capsule& capsule, const Quaternion& rotation,
  379. UINT64 layer = BS_ALL_LAYERS) = 0;
  380. /**
  381. * Checks if the provided convex mesh overlaps any other collider in the scene.
  382. *
  383. * @param[in] mesh Mesh to check for overlap. Must be convex.
  384. * @param[in] position Position of the mesh.
  385. * @param[in] rotation Orientation of the mesh.
  386. * @param[in] layer Layers to consider for the query. This allows you to ignore certain groups of objects.
  387. * @return True if there is overlap with another object, false otherwise.
  388. */
  389. virtual bool convexOverlapAny(const HPhysicsMesh& mesh, const Vector3& position, const Quaternion& rotation,
  390. UINT64 layer = BS_ALL_LAYERS) = 0;
  391. /******************************************************************************************************************/
  392. /************************************************* OPTIONS ********************************************************/
  393. /******************************************************************************************************************/
  394. virtual bool hasFlag(PhysicsFlags flag) const { return mFlags & flag; }
  395. virtual void setFlag(PhysicsFlags flag, bool enabled) { if (enabled) mFlags |= flag; else mFlags &= ~flag; }
  396. virtual Vector3 getGravity() const = 0;
  397. virtual void setGravity(const Vector3& gravity) = 0;
  398. virtual UINT32 addBroadPhaseRegion(const AABox& region) = 0;
  399. virtual void removeBroadPhaseRegion(UINT32 handle) = 0;
  400. virtual void clearBroadPhaseRegions() = 0;
  401. /**
  402. * Returns a maximum edge length before a triangle is tesselated.
  403. *
  404. * @see PhysicsFlags::CCT_Tesselation
  405. */
  406. virtual float getMaxTesselationEdgeLength() const = 0;
  407. /**
  408. * Sets a maximum edge length before a triangle is tesselated.
  409. *
  410. * @see PhysicsFlags::CCT_Tesselation
  411. */
  412. virtual void setMaxTesselationEdgeLength(float length) = 0;
  413. void toggleCollision(UINT64 groupA, UINT64 groupB, bool enabled);
  414. bool isCollisionEnabled(UINT64 groupA, UINT64 groupB) const;
  415. bool _isUpdateInProgress() const { return mUpdateInProgress; }
  416. static const UINT64 CollisionMapSize = 64;
  417. protected:
  418. friend class Rigidbody;
  419. void registerRigidbody(Rigidbody* body, UINT32 priority);
  420. void unregisterRigidbody(UINT32 id, UINT32 priority);
  421. void updatePriority(UINT32 id, UINT32 oldPriority, UINT32 newPriority);
  422. mutable Mutex mMutex;
  423. bool mCollisionMap[CollisionMapSize][CollisionMapSize];
  424. bool mUpdateInProgress = false;
  425. PhysicsFlags mFlags;
  426. Vector<Vector<Rigidbody*>> mRigidbodies; // TODO: Unused for now, but keeping it here just in case I change the design. Remove later.
  427. const static UINT32 MAX_PRIORITY = 128;
  428. };
  429. /** Provides easier access to Physics. */
  430. BS_CORE_EXPORT Physics& gPhysics();
  431. struct PHYSICS_INIT_DESC
  432. {
  433. float typicalLength = 1.0f;
  434. float typicalSpeed = 9.81f;
  435. Vector3 gravity = Vector3(0.0f, -9.81f, 0.0f);
  436. bool initCooking = true; // TODO: Disable this for Game build
  437. float timeStep = 1.0f / 60.0f;
  438. PhysicsFlags flags = PhysicsFlag::CCT_OverlapRecovery | PhysicsFlag::CCT_PreciseSweeps;
  439. };
  440. }