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