2
0

BsPhysicsCommon.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "BsVector3.h"
  6. #include "BsVector2.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Physics
  10. * @{
  11. */
  12. /** Information about a single contact point during physics collision. */
  13. struct 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 CollisionData
  23. {
  24. Collider* collidersRaw[2]; /**< Colliders involved in the collision. */
  25. /**
  26. * Components of the colliders that were hit. Can be null if collider is not owned by a component, in which case
  27. * use #collidersRaw directly.
  28. */
  29. HCollider collider[2];
  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. /** Determines what parent, if any, owns a physics object. */
  34. enum class PhysicsOwnerType
  35. {
  36. None, /** No parent, object is used directly. */
  37. Component, /** Object is used by a C++ Component. */
  38. Script /** Object is used by the scripting system. */
  39. };
  40. /** Contains information about a parent for a physics object. */
  41. struct PhysicsObjectOwner
  42. {
  43. PhysicsOwnerType type = PhysicsOwnerType::None; /**< Type of owner. */
  44. void* ownerData = nullptr; /**< Data managed by the owner. */
  45. };
  46. /** Determines which collision events will be reported by physics objects. */
  47. enum class CollisionReportMode
  48. {
  49. None, /**< No collision events will be triggered. */
  50. Report, /**< Collision events will be triggered when object enters and/or leaves collision. */
  51. /**
  52. * Collision events will be triggered when object enters and/or leaves collision, but also every frame the object
  53. * remains in collision.
  54. */
  55. ReportPersistent,
  56. };
  57. /** Hit information from a physics query. */
  58. struct PhysicsQueryHit
  59. {
  60. Vector3 point; /**< Position of the hit in world space. */
  61. Vector3 normal; /**< Normal to the surface that was hit. */
  62. Vector2 uv; /**< Barycentric coordinates of the triangle that was hit (only applicable when triangle meshes are hit). */
  63. float distance = 0.0f; /**< Distance from the query origin to the hit position. */
  64. UINT32 triangleIdx = 0; /**< Index of the triangle that was hit (only applicable when triangle meshes are hit). */
  65. Collider* colliderRaw = nullptr; /**< Collider that was hit. */
  66. /**
  67. * Component of the collider that was hit. This may be null if the hit collider has no owner component, in which
  68. * case refer to #colliderRaw.
  69. */
  70. HCollider collider;
  71. };
  72. /** @} */
  73. }