BsPhysicsCommon.h 3.1 KB

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