BsPhysicsCommon.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "Math/BsVector3.h"
  6. #include "Math/BsVector2.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Physics
  10. * @{
  11. */
  12. /** Information about a single contact point during physics collision. */
  13. struct BS_SCRIPT_EXPORT(m:Physics,pl:true) ContactPoint
  14. {
  15. Vector3 position; /**< Contact point in world space. */
  16. Vector3 normal; /**< Normal pointing from the second shape to the first shape. */
  17. /** Impulse applied to the objects to keep them from penetrating. Divide by simulation step to get the force. */
  18. float impulse;
  19. float separation; /**< Determines how far are the objects. Negative value denotes penetration. */
  20. };
  21. /** Information about a collision between two physics objects. */
  22. struct CollisionDataRaw
  23. {
  24. Collider* colliders[2]; /**< Colliders involved in the collision. */
  25. // Note: Not too happy this is heap allocated, use static allocator?
  26. Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit. */
  27. };
  28. /** Information about a collision between two physics objects. */
  29. struct BS_SCRIPT_EXPORT(m:Physics,pl:true) CollisionData
  30. {
  31. /** Components of the colliders that have collided. */
  32. HCollider collider[2];
  33. // Note: Not too happy this is heap allocated, use static allocator?
  34. Vector<ContactPoint> contactPoints; /**< Information about all the contact points for the hit. */
  35. };
  36. /** Determines what parent, if any, owns a physics object. */
  37. enum class PhysicsOwnerType
  38. {
  39. None, /** No parent, object is used directly. */
  40. Component, /** Object is used by a C++ Component. */
  41. Script /** Object is used by the scripting system. */
  42. };
  43. /** Contains information about a parent for a physics object. */
  44. struct PhysicsObjectOwner
  45. {
  46. PhysicsOwnerType type = PhysicsOwnerType::None; /**< Type of owner. */
  47. void* ownerData = nullptr; /**< Data managed by the owner. */
  48. };
  49. /** Determines which collision events will be reported by physics objects. */
  50. enum class BS_SCRIPT_EXPORT(m:Physics) CollisionReportMode
  51. {
  52. None, /**< No collision events will be triggered. */
  53. Report, /**< Collision events will be triggered when object enters and/or leaves collision. */
  54. /**
  55. * Collision events will be triggered when object enters and/or leaves collision, but also every frame the object
  56. * remains in collision.
  57. */
  58. ReportPersistent,
  59. };
  60. /** Hit information from a physics query. */
  61. struct BS_SCRIPT_EXPORT(m:Physics,pl:true) PhysicsQueryHit
  62. {
  63. Vector3 point; /**< Position of the hit in world space. */
  64. Vector3 normal; /**< Normal to the surface that was hit. */
  65. Vector2 uv; /**< Barycentric coordinates of the triangle that was hit (only applicable when triangle meshes are hit). */
  66. float distance = 0.0f; /**< Distance from the query origin to the hit position. */
  67. UINT32 triangleIdx = 0; /**< Index of the triangle that was hit (only applicable when triangle meshes are hit). */
  68. /**
  69. * Component of the collider that was hit. This may be null if the hit collider has no owner component, in which
  70. * case refer to #colliderRaw.
  71. */
  72. HCollider collider;
  73. BS_SCRIPT_EXPORT(ex:true)
  74. Collider* colliderRaw = nullptr; /**< Collider that was hit. */
  75. };
  76. /** @} */
  77. }