PhysicsCommon.cs 4.2 KB

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