dayzphysics.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. enum PhxInteractionLayers
  2. {
  3. NOCOLLISION,
  4. DEFAULT,
  5. BUILDING,
  6. CHARACTER,
  7. VEHICLE,
  8. DYNAMICITEM,
  9. DYNAMICITEM_NOCHAR,
  10. ROADWAY,
  11. VEHICLE_NOTERRAIN,
  12. CHARACTER_NO_GRAVITY,
  13. RAGDOLL_NO_CHARACTER,
  14. //! Redefinition of 'RAGDOLL_NO_CHARACTER'
  15. FIREGEOM,
  16. DOOR,
  17. RAGDOLL,
  18. WATERLAYER,
  19. TERRAIN,
  20. GHOST,
  21. WORLDBOUNDS,
  22. FENCE,
  23. AI,
  24. AI_NO_COLLISION,
  25. AI_COMPLEX,
  26. TINYCAPSULE,
  27. TRIGGER,
  28. TRIGGER_NOTERRAIN,
  29. ITEM_SMALL,
  30. ITEM_LARGE,
  31. CAMERA,
  32. TEMP
  33. };
  34. /*!
  35. Input parameters for RaycastRVProxy function.
  36. */
  37. class RaycastRVParams
  38. {
  39. vector begPos; //!< begin position of raycast (e.g. player position)
  40. vector endPos; //!< end position of raycast (e.g. player direction)
  41. Object ignore; //!< ignore this object in collision, used only if groundOnly is false
  42. Object with; //!< ignore object with this object, otherwise collision hits, used only if groundOnly is false
  43. float radius; //!< radius along the ray tested
  44. /*!
  45. Sets the raycast behaviour in terms of result.
  46. \see CollisionFlags
  47. */
  48. CollisionFlags flags;
  49. /*!
  50. type of intersection, possible values
  51. ObjIntersectFire(0),
  52. ObjIntersectView(1),
  53. ObjIntersectGeom(2),
  54. ObjIntersectIFire(3),
  55. ObjIntersectNone(4)
  56. */
  57. int type;
  58. bool sorted; //!< used only if groundOnly = false
  59. bool groundOnly; //!< raycasts only ground (ignores all objects). Default value is false if not needed.
  60. void RaycastRVParams( vector vBeg, vector vEnd, Object pIgnore = null, float fRadius = 0.0 )
  61. {
  62. begPos = vBeg;
  63. endPos = vEnd;
  64. ignore = pIgnore;
  65. radius = fRadius;
  66. // default values
  67. with = null;
  68. flags = CollisionFlags.NEARESTCONTACT;
  69. type = ObjIntersectView;
  70. sorted = false;
  71. groundOnly = false;
  72. }
  73. };
  74. /*!
  75. Contains result data of RaycastRVProxy function.
  76. */
  77. class RaycastRVResult
  78. {
  79. Object obj; //!< object,that we collide with (NULL if none), If hierLevel > 0 object is the proxy object
  80. Object parent; //!< if hierLevel > 0 most parent of the proxy object
  81. vector pos; //!< position of collision (in world coord)
  82. vector dir; //!< direction outside (in world coord) or (in case of line-object collision) direction and size of the intersection
  83. int hierLevel; //!< which hierarchy level is the collision detected at, == 0 = objects in landscape, > 0 = proxy
  84. int component; //!< index of component in corresponding geometry level
  85. SurfaceInfo surface; //!< surface material info handle
  86. bool entry; //!< is false if begining point was TriggerInsider
  87. bool exit; //!< is false if end point was inside
  88. };
  89. class CollisionOverlapCallback : Managed
  90. {
  91. bool OnContact(IEntity other, Contact contact)
  92. {
  93. return true;
  94. }
  95. };
  96. class DayZPhysics
  97. {
  98. private void DayZPhysics() {}
  99. private void ~DayZPhysics() {}
  100. /**
  101. \brief Raycasts world by given parameters
  102. \param begPos \p vector Begin position of raycast (e.g. player position)
  103. \param endPos \p vector End position of raycast (e.g. player direction)
  104. \param contactPos \p vector out, world position of first contact
  105. \param contactDir \p vector out, direction of first contact (available only when object is hitted)
  106. \param contactComponent \p int out, object component index (available only when object is hitted)
  107. \param results \p set<Object> out, set of objects hitted by raycast. Can be NULL if not needed
  108. \param with \p Object Ignores the object from collision. Used only when \p ground_only is false. Can be NULL if not needed
  109. \param ignore \p Object Ignores the object from collision. Used only when \p ground_only is false. Can be NULL if not needed
  110. \param sorted \p bool Default value is false, used only if \p ground_only = false
  111. \param ground_only \bool raycasts only ground (ignores all objects). Default value is false if not needed.
  112. \param iType \p int, type of intersection, possible values ObjIntersectFire(0), ObjIntersectView(1), ObjIntersectGeom(2), ObjIntersectIFire(3),
  113. ObjIntersectNone(4)
  114. \param radius \p float Radius of the ray, default value set to 0
  115. \returns \p bool return true if raycast hits ground or object
  116. @code
  117. // raycast test
  118. PlayerBase player = g_Game.GetPlayer();
  119. if (player)
  120. {
  121. vector begPos = player.GetPosition();
  122. vector endPos = begPos + (player.GetDirection() * 100);
  123. vector contactPos;
  124. vector contactDir;
  125. int contactComponent;
  126. set<Object> results = new set<Object>;
  127. Object with;
  128. Object ignore;
  129. bool sorted;
  130. bool ground_only;
  131. int iType;
  132. float radius;
  133. if ( GetGame().Raycast(begPos, endPos, contactPos, contactDir, contactComponent, results, with, ignore, sorted, ground_only, iType, radius) )
  134. {
  135. Print(begPos);
  136. Print(endPos);
  137. Print(contactPos);
  138. Print(contactDir);
  139. Print(contactComponent);
  140. Print(results);
  141. Print(with);
  142. Print(ignore);
  143. Print(sorted);
  144. Print(ground_only);
  145. Print(iType);
  146. Print(radius);
  147. Print( GetGame().Raycast(begPos, endPos, contactPos, contactDir, contactComponent, results, with, ignore, sorted, ground_only, iType, radius) );
  148. }
  149. }
  150. >> vector begPos = 0x00000000dd62df30 {<750.573,49.8043,2167.25>}
  151. >> vector endPos = 0x00000000dd62df3c {<849.589,49.8043,2181.25>}
  152. >> vector contactPos = 0x00000000dd62df48 {<751.068,49.8043,2167.32>}
  153. >> vector contactDir = 0x00000000dd62df54 {<0.987203,2.04891e-08,0.139505>}
  154. >> int contactComponent = 8
  155. >> set<Object> results = set<Object><a022d840>
  156. >> Object with = NULL
  157. >> Object ignore = NULL
  158. >> bool sorted = 0
  159. >> bool ground_only = 0
  160. >> int iType = 0
  161. >> float radius = 0
  162. >> 1
  163. @endcode
  164. */
  165. proto static bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, /*out*/ set<Object> results = NULL, Object with = NULL, Object ignore = NULL, bool sorted = false, bool ground_only = false, int iType = ObjIntersectView, float radius = 0.0, CollisionFlags flags = CollisionFlags.NEARESTCONTACT);
  166. //I am so sorry about this, I am unable to change RaycastRV above without breaking rest of DZ
  167. //proto static bool RaycastRVExt(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, /*out*/ array<string> resultSurfaces = NULL, /*out*/ array<Object> resultObjects = NULL, Object with = NULL, Object ignore = NULL, bool sorted = false, bool ground_only = false, int iType = ObjIntersectView, float radius = 0.0, CollisionFlags flags = CollisionFlags.NEARESTCONTACT);
  168. proto static bool GetHitSurface(Object other, vector begPos, vector endPos, string surface);
  169. proto static bool GetHitSurfaceAndLiquid(Object other, vector begPos, vector endPos, string surface, out int liquidType);
  170. proto static bool RaycastRVProxy( notnull RaycastRVParams in, out notnull array< ref RaycastRVResult> results, array< Object > excluded = null );
  171. proto static bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction);
  172. proto static bool SphereCastBullet(vector begPos, vector endPos, float radius, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction);
  173. proto static bool GeometryOverlapBullet(vector transform[4], dGeom geometry, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  174. proto static bool EntityOverlapBullet(vector transform[4], IEntity entity, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  175. proto static bool EntityOverlapSingleBullet(vector transform[4], IEntity entity, IEntity other, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  176. proto static bool SphereOverlapBullet(vector position, float radius, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  177. proto static bool CylinderOverlapBullet(vector transform[4], vector extents, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  178. proto static bool CapsuleOverlapBullet(vector transform[4], float radius, float height, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  179. proto static bool BoxOverlapBullet(vector transform[4], vector extents, PhxInteractionLayers layerMask, notnull CollisionOverlapCallback callback);
  180. }