2
0

PhysicsCommon.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Runtime.InteropServices;
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Physics
  7. * @{
  8. */
  9. /// <summary>
  10. /// Hit information from a physics query.
  11. /// </summary>
  12. public struct PhysicsQueryHit
  13. {
  14. /// <summary>
  15. /// Position of the hit in world space.
  16. /// </summary>
  17. public Vector3 point;
  18. /// <summary>
  19. /// Normal to the surface that was hit.
  20. /// </summary>
  21. public Vector3 normal;
  22. /// <summary>
  23. /// UV coordinates of the triangle that was hit (only applicable when triangle meshes are hit).
  24. /// </summary>
  25. public Vector2 uv;
  26. /// <summary>
  27. /// Distance from the query origin to the hit position.
  28. /// </summary>
  29. public float distance;
  30. /// <summary>
  31. /// Index of the triangle that was hit (only applicable when triangle meshes are hit).
  32. /// </summary>
  33. public int triangleIdx;
  34. /// <summary>
  35. /// Collider that was hit.
  36. /// </summary>
  37. public Collider collider;
  38. }
  39. /// <summary>
  40. /// Information about a single contact point during physics collision.
  41. /// </summary>
  42. [StructLayout(LayoutKind.Sequential)]
  43. public struct ContactPoint // Note: Must match C++ ContactPoint struct
  44. {
  45. /// <summary>
  46. /// Contact point in world space.
  47. /// </summary>
  48. public Vector3 position;
  49. /// <summary>
  50. /// Normal pointing from the second shape to the first shape.
  51. /// </summary>
  52. public Vector3 normal;
  53. /// <summary>
  54. /// Impulse applied to the objects to keep them from penetrating. Divide by simulation step to get the force.
  55. /// </summary>
  56. public float impulse;
  57. /// <summary>
  58. /// Determines how far are the objects. Negative value denotes penetration.
  59. /// </summary>
  60. public float separation;
  61. }
  62. /// <summary>
  63. /// Information about a collision between two physics objects.
  64. /// </summary>
  65. public struct CollisionData
  66. {
  67. internal CollisionData(ScriptCollisionData data)
  68. {
  69. if (data.colliderA != null)
  70. colliderA = data.colliderA.Component;
  71. else
  72. colliderA = null;
  73. if (data.colliderB != null)
  74. colliderB = data.colliderB.Component;
  75. else
  76. colliderB = null;
  77. contactPoints = data.contactPoints;
  78. }
  79. /// <summary>
  80. /// First of the colliders involved in the collision.
  81. /// </summary>
  82. public Collider colliderA;
  83. /// <summary>
  84. /// Second of the colliders involved in the collision.
  85. /// </summary>
  86. public Collider colliderB;
  87. /// <summary>
  88. /// Information about all the contact points for the hit.
  89. /// </summary>
  90. public ContactPoint[] contactPoints;
  91. }
  92. /// <summary>
  93. /// Interop class used for passing PhysicsQueryHit data from native to managed code. <see cref="PhysicsQueryHit"/>.
  94. /// </summary>
  95. [StructLayout(LayoutKind.Sequential)]
  96. internal struct ScriptPhysicsQueryHit // Note: Must match C++ struct ScriptPhysicsQueryHit
  97. {
  98. public Vector3 point;
  99. public Vector3 normal;
  100. public Vector2 uv;
  101. public float distance;
  102. public int triangleIdx;
  103. public NativeCollider collider;
  104. }
  105. /// <summary>
  106. /// Interop class used for passing CollisionData data from native to managed code. <see cref="CollisionData"/>.
  107. /// </summary>
  108. [StructLayout(LayoutKind.Sequential)]
  109. internal struct ScriptCollisionData // Note: Must match C++ CollisionData struct
  110. {
  111. public NativeCollider colliderA;
  112. public NativeCollider colliderB;
  113. public ContactPoint[] contactPoints;
  114. }
  115. /// <summary>
  116. /// Determines which collision events will be reported by physics objects.
  117. /// </summary>
  118. public enum CollisionReportMode
  119. {
  120. /// <summary>
  121. /// No collision events will be triggered.
  122. /// </summary>
  123. None,
  124. /// <summary>
  125. /// Collision events will be triggered when object enters and/or leaves collision.
  126. /// </summary>
  127. Report,
  128. /// <summary>
  129. /// Collision events will be triggered when object enters and/or leaves collision, but also every frame the object
  130. /// remains in collision.
  131. /// </summary>
  132. ReportPersistent,
  133. }
  134. /** @} */
  135. }