Make pTraceResult as pass arg
This commit is contained in:
parent
fde876b4e1
commit
fb519778e7
5 changed files with 140 additions and 293 deletions
|
|
@ -64,133 +64,53 @@ namespace RayTraceAPI
|
|||
MASK_NPC_MOVE = Solid | Window | NPCClip | PassBullets
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8)]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 24)]
|
||||
public struct TraceOptions
|
||||
{
|
||||
public ulong InteractsAs;
|
||||
public ulong InteractsWith;
|
||||
public ulong InteractsExclude;
|
||||
public int DrawBeam;
|
||||
|
||||
private int _pad;
|
||||
[FieldOffset(0)] public ulong InteractsWith;
|
||||
[FieldOffset(8)] public ulong InteractsExclude;
|
||||
[FieldOffset(16)] public int DrawBeam;
|
||||
|
||||
public TraceOptions()
|
||||
{
|
||||
InteractsAs = 0;
|
||||
InteractsWith = (ulong)InteractionLayers.MASK_SHOT_PHYSICS;
|
||||
InteractsExclude = 0;
|
||||
DrawBeam = 0;
|
||||
}
|
||||
|
||||
public TraceOptions(InteractionLayers interactsAs, InteractionLayers interactsWith,
|
||||
InteractionLayers interactsExclude = 0, bool drawBeam = false)
|
||||
public TraceOptions(InteractionLayers interactsWith, InteractionLayers interactsExclude = 0, bool drawBeam = false)
|
||||
{
|
||||
InteractsAs = (ulong)interactsAs;
|
||||
InteractsWith = (ulong)interactsWith;
|
||||
InteractsExclude = (ulong)interactsExclude;
|
||||
DrawBeam = drawBeam ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct TraceResult
|
||||
[StructLayout(LayoutKind.Explicit, Size = 44)]
|
||||
public struct TraceResult
|
||||
{
|
||||
public Vector3 StartPos;
|
||||
public Vector3 EndPos;
|
||||
public Vector3 HitPoint;
|
||||
public Vector3 Normal;
|
||||
[FieldOffset(0)] public float EndPosX;
|
||||
[FieldOffset(4)] public float EndPosY;
|
||||
[FieldOffset(8)] public float EndPosZ;
|
||||
[FieldOffset(16)] public nint HitEntity;
|
||||
[FieldOffset(24)] public float Fraction;
|
||||
[FieldOffset(28)] public int AllSolid;
|
||||
[FieldOffset(32)] public float NormalX;
|
||||
[FieldOffset(36)] public float NormalY;
|
||||
[FieldOffset(40)] public float NormalZ;
|
||||
|
||||
public float Fraction;
|
||||
public float HitOffset;
|
||||
|
||||
public int TriangleIndex;
|
||||
public short HitboxBoneIndex;
|
||||
private short _pad;
|
||||
|
||||
public int Contents;
|
||||
public int RayType;
|
||||
|
||||
public bool StartInSolid;
|
||||
public bool ExactHitPoint;
|
||||
|
||||
public nint HitEntity;
|
||||
public nint Hitbox;
|
||||
public nint Surface;
|
||||
public nint Body;
|
||||
public nint Shape;
|
||||
|
||||
public nint BodyTransform;
|
||||
public nint ShapeAttributes;
|
||||
|
||||
public readonly bool DidHit() => Fraction < 1.0f;
|
||||
public readonly bool IsAllSolid() => StartInSolid;
|
||||
public readonly bool HasExactHit() => ExactHitPoint;
|
||||
|
||||
public readonly int GetTriangleIndex() => TriangleIndex;
|
||||
public readonly int GetHitboxBoneIndex() => HitboxBoneIndex;
|
||||
public readonly int GetContents() => Contents;
|
||||
public readonly int GetRayType() => RayType;
|
||||
|
||||
public readonly Vector3 GetStartPos() => StartPos;
|
||||
public readonly Vector3 GetEndPos() => EndPos;
|
||||
public readonly Vector3 GetHitPoint() => HitPoint;
|
||||
public readonly Vector3 GetNormal() => Normal;
|
||||
|
||||
public readonly float GetFraction() => Fraction;
|
||||
public readonly float GetHitOffset() => HitOffset;
|
||||
|
||||
public readonly T* GetPtr<T>(nint ptr) where T : unmanaged
|
||||
{
|
||||
return (T*)ptr;
|
||||
}
|
||||
|
||||
public readonly ref T GetRef<T>(nint ptr) where T : unmanaged
|
||||
{
|
||||
if (ptr == 0)
|
||||
throw new NullReferenceException();
|
||||
|
||||
return ref *(T*)ptr;
|
||||
}
|
||||
|
||||
public readonly bool TryGetRef<T>(nint ptr, out T* value) where T : unmanaged
|
||||
{
|
||||
if (ptr == 0)
|
||||
{
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
value = (T*)ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
public readonly CEntityInstance HitEntityPtr() => new(HitEntity);
|
||||
|
||||
public readonly CTransform BodyTransformPtr() => new(BodyTransform);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VectorNative
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct QAngleNative
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
public Vector3 EndPos => new(EndPosX, EndPosY, EndPosZ);
|
||||
public Vector3 Normal => new(NormalX, NormalY, NormalZ);
|
||||
public bool DidHit => Fraction < 1.0f;
|
||||
public bool IsAllSolid => AllSolid != 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public interface CRayTraceInterface
|
||||
{
|
||||
public TraceResult TraceShape(Vector start, QAngle angles, CEntityInstance ignore, TraceOptions options);
|
||||
public TraceResult TraceEndShape(Vector start, Vector end, CEntityInstance ignore, TraceOptions options);
|
||||
public TraceResult TraceHullShape(Vector start, Vector end, Vector mins, Vector maxs, CEntityInstance ignore, TraceOptions options);
|
||||
public TraceResult TraceShapeEx(Vector start, Vector end, nint filter, nint ray);
|
||||
public bool TraceShape(Vector start, QAngle angles, CEntityInstance? ignore, TraceOptions options, out TraceResult result);
|
||||
public bool TraceEndShape(Vector start, Vector end, CEntityInstance? ignore, TraceOptions options, out TraceResult result);
|
||||
public bool TraceHullShape(Vector start, Vector end, Vector mins, Vector maxs, CEntityInstance? ignore, TraceOptions options, out TraceResult result);
|
||||
public bool TraceShapeEx(Vector start, Vector end, nint filter, nint ray, out TraceResult result);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,90 +60,100 @@ public class RayTraceImpl : BasePlugin
|
|||
|
||||
public class CRayTrace : CRayTraceInterface
|
||||
{
|
||||
public TraceResult TraceShape(Vector start, QAngle angles, CEntityInstance ignore, TraceOptions options)
|
||||
public bool TraceShape(Vector start, QAngle angles, CEntityInstance? ignore, TraceOptions options, out TraceResult result)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
result = default;
|
||||
|
||||
if (!NativeBridge.Loaded)
|
||||
return default;
|
||||
return false;
|
||||
|
||||
VectorNative startNative = new() { X = start.X, Y = start.Y, Z = start.Z };
|
||||
QAngleNative angNative = new() { X = angles.X, Y = angles.Y, Z = angles.Z };
|
||||
TraceOptions optCopy = options;
|
||||
TraceResult resultBuffer = default;
|
||||
TraceOptions optionsBuffer = options;
|
||||
|
||||
return NativeBridge.TraceShape!(
|
||||
NativeBridge.Handle,
|
||||
(nint)(&startNative),
|
||||
(nint)(&angNative),
|
||||
ignore.Handle,
|
||||
(nint)(&optCopy)
|
||||
);
|
||||
bool success = NativeBridge.TraceShape!(NativeBridge.Handle,
|
||||
start.Handle,
|
||||
angles.Handle,
|
||||
ignore?.Handle ?? nint.Zero,
|
||||
(nint)(&optionsBuffer),
|
||||
(nint)(&resultBuffer));
|
||||
|
||||
result = resultBuffer;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public TraceResult TraceEndShape(Vector start, Vector end, CEntityInstance ignore, TraceOptions options)
|
||||
public bool TraceEndShape(Vector start, Vector end, CEntityInstance? ignore, TraceOptions options, out TraceResult result)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
result = default;
|
||||
|
||||
if (!NativeBridge.Loaded)
|
||||
return default;
|
||||
return false;
|
||||
|
||||
VectorNative s = new() { X = start.X, Y = start.Y, Z = start.Z };
|
||||
VectorNative e = new() { X = end.X, Y = end.Y, Z = end.Z };
|
||||
TraceOptions opt = options;
|
||||
TraceResult resultBuffer = default;
|
||||
TraceOptions optionsBuffer = options;
|
||||
|
||||
return NativeBridge.TraceEndShape!(
|
||||
NativeBridge.Handle,
|
||||
(nint)(&s),
|
||||
(nint)(&e),
|
||||
ignore.Handle,
|
||||
(nint)(&opt)
|
||||
);
|
||||
bool success = NativeBridge.TraceEndShape!(NativeBridge.Handle,
|
||||
start.Handle,
|
||||
end.Handle,
|
||||
ignore?.Handle ?? nint.Zero,
|
||||
(nint)(&optionsBuffer),
|
||||
(nint)(&resultBuffer));
|
||||
|
||||
result = resultBuffer;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public TraceResult TraceHullShape(Vector start, Vector end, Vector mins, Vector maxs, CEntityInstance ignore, TraceOptions options)
|
||||
public bool TraceHullShape(Vector start, Vector end, Vector mins, Vector maxs, CEntityInstance? ignore, TraceOptions options, out TraceResult result)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
result = default;
|
||||
|
||||
if (!NativeBridge.Loaded)
|
||||
return default;
|
||||
return false;
|
||||
|
||||
VectorNative s = new() { X = start.X, Y = start.Y, Z = start.Z };
|
||||
VectorNative e = new() { X = end.X, Y = end.Y, Z = end.Z };
|
||||
VectorNative mi = new() { X = mins.X, Y = mins.Y, Z = mins.Z };
|
||||
VectorNative ma = new() { X = maxs.X, Y = maxs.Y, Z = maxs.Z };
|
||||
TraceOptions opt = options;
|
||||
TraceResult resultBuffer = default;
|
||||
TraceOptions optionsBuffer = options;
|
||||
|
||||
return NativeBridge.TraceHullShape!(
|
||||
NativeBridge.Handle,
|
||||
(nint)(&s),
|
||||
(nint)(&e),
|
||||
(nint)(&mi),
|
||||
(nint)(&ma),
|
||||
ignore.Handle,
|
||||
(nint)(&opt)
|
||||
);
|
||||
bool success = NativeBridge.TraceHullShape!(NativeBridge.Handle,
|
||||
start.Handle,
|
||||
end.Handle,
|
||||
mins.Handle,
|
||||
maxs.Handle,
|
||||
ignore?.Handle ?? nint.Zero,
|
||||
(nint)(&optionsBuffer),
|
||||
(nint)(&resultBuffer));
|
||||
|
||||
result = resultBuffer;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public TraceResult TraceShapeEx(Vector start, Vector end, nint filter, nint ray)
|
||||
public bool TraceShapeEx(Vector start, Vector end, nint filter, nint ray, out TraceResult result)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
result = default;
|
||||
|
||||
if (!NativeBridge.Loaded)
|
||||
return default;
|
||||
return false;
|
||||
|
||||
VectorNative s = new() { X = start.X, Y = start.Y, Z = start.Z };
|
||||
VectorNative e = new() { X = end.X, Y = end.Y, Z = end.Z };
|
||||
TraceResult resultBuffer = default;
|
||||
|
||||
return NativeBridge.TraceShapeEx!(
|
||||
NativeBridge.Handle,
|
||||
(nint)(&s),
|
||||
(nint)(&e),
|
||||
bool success = NativeBridge.TraceShapeEx!(NativeBridge.Handle,
|
||||
start.Handle,
|
||||
end.Handle,
|
||||
filter,
|
||||
ray
|
||||
);
|
||||
ray,
|
||||
(nint)(&resultBuffer));
|
||||
|
||||
result = resultBuffer;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -153,10 +163,10 @@ public static class NativeBridge
|
|||
public static nint Handle;
|
||||
public static bool Loaded;
|
||||
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, TraceResult>? TraceShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, TraceResult>? TraceEndShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, nint, nint, TraceResult>? TraceHullShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, TraceResult>? TraceShapeEx;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, nint, bool>? TraceShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, nint, bool>? TraceEndShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, nint, nint, nint, bool>? TraceHullShape;
|
||||
public static unsafe Func<nint, nint, nint, nint, nint, nint, bool>? TraceShapeEx;
|
||||
|
||||
public static bool Initialize()
|
||||
{
|
||||
|
|
@ -189,10 +199,10 @@ public static class NativeBridge
|
|||
ex = 5;
|
||||
}
|
||||
|
||||
TraceShape = VirtualFunction.Create<nint, nint, nint, nint, nint, TraceResult>(Handle, shape);
|
||||
TraceEndShape = VirtualFunction.Create<nint, nint, nint, nint, nint, TraceResult>(Handle, end);
|
||||
TraceHullShape = VirtualFunction.Create<nint, nint, nint, nint, nint, nint, nint, TraceResult>(Handle, hull);
|
||||
TraceShapeEx = VirtualFunction.Create<nint, nint, nint, nint, nint, TraceResult>(Handle, ex);
|
||||
TraceShape = VirtualFunction.Create<nint, nint, nint, nint, nint, nint, bool>(Handle, shape);
|
||||
TraceEndShape = VirtualFunction.Create<nint, nint, nint, nint, nint, nint, bool>(Handle, end);
|
||||
TraceHullShape = VirtualFunction.Create<nint, nint, nint, nint, nint, nint, nint, nint, bool>(Handle, hull);
|
||||
TraceShapeEx = VirtualFunction.Create<nint, nint, nint, nint, nint, nint, bool>(Handle, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ static_assert(
|
|||
|
||||
struct TraceOptions
|
||||
{
|
||||
uint64_t InteractsAs = 0;
|
||||
uint64_t InteractsWith = static_cast<uint64_t>(MASK_SHOT_PHYSICS);
|
||||
uint64_t InteractsExclude = 0;
|
||||
int DrawBeam = 0;
|
||||
|
|
@ -146,104 +145,25 @@ struct TraceResult
|
|||
{
|
||||
TraceResult()
|
||||
{
|
||||
m_flFraction = 1.0f;
|
||||
m_bStartInSolid = false;
|
||||
m_bExactHitPoint = false;
|
||||
m_pEnt = nullptr;
|
||||
m_pHitbox = nullptr;
|
||||
m_pSurfaceProperties = nullptr;
|
||||
HitEntity = nullptr;
|
||||
AllSolid = 0;
|
||||
Fraction = 1.0F;
|
||||
}
|
||||
|
||||
explicit TraceResult(const CGameTrace* pTrace, bool bResult)
|
||||
explicit TraceResult(const CGameTrace* pTrace)
|
||||
{
|
||||
m_bTraceShapeResult = bResult;
|
||||
m_pSurfaceProperties = pTrace->m_pSurfaceProperties;
|
||||
m_pEnt = pTrace->m_pEnt;
|
||||
m_pHitbox = pTrace->m_pHitbox;
|
||||
m_hBody = pTrace->m_hBody;
|
||||
m_hShape = pTrace->m_hShape;
|
||||
m_nContents = pTrace->m_nContents;
|
||||
m_BodyTransform = pTrace->m_BodyTransform;
|
||||
m_ShapeAttributes = pTrace->m_ShapeAttributes;
|
||||
m_vStartPos = pTrace->m_vStartPos;
|
||||
m_vEndPos = pTrace->m_vEndPos;
|
||||
m_vHitNormal = pTrace->m_vHitNormal;
|
||||
m_vHitPoint = pTrace->m_vHitPoint;
|
||||
m_flHitOffset = pTrace->m_flHitOffset;
|
||||
m_flFraction = pTrace->m_flFraction;
|
||||
m_nTriangle = pTrace->m_nTriangle;
|
||||
m_nHitboxBoneIndex = pTrace->m_nHitboxBoneIndex;
|
||||
m_eRayType = pTrace->m_eRayType;
|
||||
m_bStartInSolid = pTrace->m_bStartInSolid;
|
||||
m_bExactHitPoint = pTrace->m_bExactHitPoint;
|
||||
EndPos = pTrace->m_vEndPos;
|
||||
HitEntity = pTrace->m_pEnt;
|
||||
Fraction = pTrace->m_flFraction;
|
||||
AllSolid = pTrace->m_bStartInSolid;
|
||||
Normal = pTrace->m_vHitNormal;
|
||||
}
|
||||
|
||||
TraceResult(const TraceResult&) = delete;
|
||||
TraceResult& operator=(const TraceResult&) = delete;
|
||||
|
||||
TraceResult(TraceResult&&) = default;
|
||||
TraceResult& operator=(TraceResult&&) = default;
|
||||
|
||||
const Vector& StartPos() const { return m_vStartPos; }
|
||||
const Vector& EndPos() const { return m_vEndPos; }
|
||||
const Vector& HitPoint() const { return m_vHitPoint; }
|
||||
const Vector& Normal() const { return m_vHitNormal; }
|
||||
|
||||
float Fraction() const { return m_flFraction; }
|
||||
float HitOffset() const { return m_flHitOffset; }
|
||||
|
||||
bool DidHit() const { return m_flFraction < 1.0f; }
|
||||
bool IsAllSolid() const { return m_bStartInSolid; }
|
||||
bool HasExactHit() const { return m_bExactHitPoint; }
|
||||
|
||||
CEntityInstance* HitEntity() const { return m_pEnt; }
|
||||
|
||||
int TriangleIndex() const { return m_nTriangle; }
|
||||
int HitboxBoneIndex() const { return m_nHitboxBoneIndex; }
|
||||
|
||||
CHitBox* Hitbox() const { return const_cast<CHitBox*>(m_pHitbox); }
|
||||
|
||||
int Contents() const { return m_nContents; }
|
||||
RayType_t RayType() const { return m_eRayType; }
|
||||
|
||||
IPhysicsBody* Body() const { return m_hBody; }
|
||||
IPhysicsShape* Shape() const { return m_hShape; }
|
||||
|
||||
const CTransform& BodyTransform() const { return m_BodyTransform; }
|
||||
const RnCollisionAttr_t& ShapeAttributes() const { return m_ShapeAttributes; }
|
||||
|
||||
CPhysSurfaceProperties* Surface() const { return const_cast<CPhysSurfaceProperties*>(m_pSurfaceProperties); }
|
||||
|
||||
private:
|
||||
bool m_bTraceShapeResult; // return value from RayTrace::TraceShapeEx
|
||||
|
||||
const CPhysSurfaceProperties *m_pSurfaceProperties;
|
||||
CEntityInstance *m_pEnt;
|
||||
const CHitBox *m_pHitbox;
|
||||
|
||||
HPhysicsBody m_hBody;
|
||||
HPhysicsShape m_hShape;
|
||||
|
||||
uint64 m_nContents; // contents on other side of surface hit
|
||||
|
||||
CTransform m_BodyTransform;
|
||||
RnCollisionAttr_t m_ShapeAttributes;
|
||||
|
||||
Vector m_vStartPos; // start position
|
||||
Vector m_vEndPos; // final position
|
||||
Vector m_vHitNormal; // surface normal at impact
|
||||
Vector m_vHitPoint; // exact hit point if m_bExactHitPoint is true, otherwise equal to m_vEndPos
|
||||
|
||||
float m_flHitOffset; // surface normal hit offset
|
||||
float m_flFraction; // time completed, 1.0 = didn't hit anything
|
||||
|
||||
int32 m_nTriangle; // the index of the triangle that was hit
|
||||
int16 m_nHitboxBoneIndex; // the index of the hitbox bone that was hit
|
||||
|
||||
RayType_t m_eRayType;
|
||||
|
||||
bool m_bStartInSolid; // if true, the initial point was in a solid area
|
||||
bool m_bExactHitPoint; // if true, then m_vHitPoint is the exact hit point of the query and the shape
|
||||
Vector EndPos;
|
||||
CEntityInstance* HitEntity;
|
||||
float Fraction;
|
||||
int AllSolid;
|
||||
Vector Normal;
|
||||
};
|
||||
|
||||
class CRayTraceInterface
|
||||
|
|
@ -251,25 +171,29 @@ class CRayTraceInterface
|
|||
public:
|
||||
virtual ~CRayTraceInterface() = default;
|
||||
|
||||
virtual TraceResult TraceShape(const Vector& vecStart,
|
||||
virtual bool TraceShape(const Vector& vecStart,
|
||||
const QAngle& angAngles,
|
||||
CEntityInstance* pIgnoreEntity,
|
||||
TraceOptions* pTraceOptions) = 0;
|
||||
TraceOptions* pTraceOptions,
|
||||
TraceResult* pTraceResult) = 0;
|
||||
|
||||
virtual TraceResult TraceEndShape(const Vector& vecStart,
|
||||
virtual bool TraceEndShape(const Vector& vecStart,
|
||||
const Vector& vecEnd,
|
||||
CEntityInstance* pIgnoreEntity,
|
||||
TraceOptions* pTraceOptions) = 0;
|
||||
TraceOptions* pTraceOptions,
|
||||
TraceResult* pTraceResult) = 0;
|
||||
|
||||
virtual TraceResult TraceHullShape(const Vector& vecStart,
|
||||
virtual bool TraceHullShape(const Vector& vecStart,
|
||||
const Vector& vecEnd,
|
||||
const Vector& vecMins,
|
||||
const Vector& vecMaxs,
|
||||
CEntityInstance* pIgnoreEntity,
|
||||
TraceOptions* pTraceOptions) = 0;
|
||||
TraceOptions* pTraceOptions,
|
||||
TraceResult* pTraceResult) = 0;
|
||||
|
||||
virtual TraceResult TraceShapeEx(const Vector& vecStart,
|
||||
virtual bool TraceShapeEx(const Vector& vecStart,
|
||||
const Vector& vecEnd,
|
||||
CTraceFilter* pTraceFilter,
|
||||
Ray_t* pRay) = 0;
|
||||
Ray_t* pRay,
|
||||
TraceResult* pTraceResult) = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace RayTracePlugin::RayTrace
|
|||
beam->DispatchSpawn();
|
||||
}
|
||||
|
||||
TraceResult CRayTrace::TraceShape(const Vector& vecStart, const QAngle& angAngles, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions)
|
||||
bool CRayTrace::TraceShape(const Vector& vecStart, const QAngle& angAngles, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult)
|
||||
{
|
||||
CTraceFilterEx filter = pIgnoreEntity ? CTraceFilterEx(static_cast<CBaseEntity*>(pIgnoreEntity)) : CTraceFilterEx();
|
||||
|
||||
|
|
@ -53,9 +53,6 @@ namespace RayTracePlugin::RayTrace
|
|||
|
||||
if (pTraceOptions)
|
||||
{
|
||||
if (pTraceOptions->InteractsAs != 0)
|
||||
filter.m_nInteractsAs = pTraceOptions->InteractsAs;
|
||||
|
||||
if (pTraceOptions->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
|
||||
filter.m_nInteractsWith = pTraceOptions->InteractsWith;
|
||||
|
||||
|
|
@ -72,18 +69,18 @@ namespace RayTracePlugin::RayTrace
|
|||
};
|
||||
|
||||
Ray_t ray;
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray);
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray, pTraceResult);
|
||||
|
||||
if (pTraceOptions && pTraceOptions->DrawBeam)
|
||||
{
|
||||
Color col = res.DidHit() ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, res.DidHit() ? res.HitPoint() : vecEnd, col);
|
||||
Color col = res ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, (res && pTraceResult) ? pTraceResult->EndPos : vecEnd, col);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
TraceResult CRayTrace::TraceEndShape(const Vector& vecStart, const Vector& vecEnd, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions)
|
||||
bool CRayTrace::TraceEndShape(const Vector& vecStart, const Vector& vecEnd, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult)
|
||||
{
|
||||
CTraceFilterEx filter = pIgnoreEntity ? CTraceFilterEx(static_cast<CBaseEntity*>(pIgnoreEntity)) : CTraceFilterEx();
|
||||
|
||||
|
|
@ -93,9 +90,6 @@ namespace RayTracePlugin::RayTrace
|
|||
|
||||
if (pTraceOptions)
|
||||
{
|
||||
if (pTraceOptions->InteractsAs != 0)
|
||||
filter.m_nInteractsAs = pTraceOptions->InteractsAs;
|
||||
|
||||
if (pTraceOptions->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
|
||||
filter.m_nInteractsWith = pTraceOptions->InteractsWith;
|
||||
|
||||
|
|
@ -104,19 +98,19 @@ namespace RayTracePlugin::RayTrace
|
|||
}
|
||||
|
||||
Ray_t ray;
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray);
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray, pTraceResult);
|
||||
|
||||
if (pTraceOptions && pTraceOptions->DrawBeam)
|
||||
{
|
||||
Color col = res.DidHit() ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, res.DidHit() ? res.HitPoint() : vecEnd, col);
|
||||
Color col = res ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, (res && pTraceResult) ? pTraceResult->EndPos : vecEnd, col);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
TraceResult CRayTrace::TraceHullShape(const Vector& vecStart, const Vector& vecEnd, const Vector& vecMins,
|
||||
const Vector& vecMaxs, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions)
|
||||
bool CRayTrace::TraceHullShape(const Vector& vecStart, const Vector& vecEnd, const Vector& vecMins,
|
||||
const Vector& vecMaxs, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult)
|
||||
{
|
||||
CTraceFilterEx filter = pIgnoreEntity ? CTraceFilterEx(static_cast<CBaseEntity*>(pIgnoreEntity)) : CTraceFilterEx();
|
||||
|
||||
|
|
@ -126,9 +120,6 @@ namespace RayTracePlugin::RayTrace
|
|||
|
||||
if (pTraceOptions)
|
||||
{
|
||||
if (pTraceOptions->InteractsAs != 0)
|
||||
filter.m_nInteractsAs = pTraceOptions->InteractsAs;
|
||||
|
||||
if (pTraceOptions->InteractsWith != static_cast<uint64_t>(MASK_SHOT_PHYSICS))
|
||||
filter.m_nInteractsWith = pTraceOptions->InteractsWith;
|
||||
|
||||
|
|
@ -139,23 +130,23 @@ namespace RayTracePlugin::RayTrace
|
|||
Ray_t ray;
|
||||
ray.Init(vecMins, vecMaxs);
|
||||
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray);
|
||||
auto res = TraceShapeEx(vecStart, vecEnd, &filter, &ray, pTraceResult);
|
||||
|
||||
if (pTraceOptions && pTraceOptions->DrawBeam)
|
||||
{
|
||||
Color col = res.DidHit() ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, res.DidHit() ? res.HitPoint() : vecEnd, col);
|
||||
Color col = res ? colors::Red().ToValveColor() : colors::Green().ToValveColor();
|
||||
DrawBeam(vecStart, (res && pTraceResult) ? pTraceResult->EndPos : vecEnd, col);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
TraceResult CRayTrace::TraceShapeEx(const Vector& vecStart, const Vector& vecEnd, CTraceFilter* pTraceFilter, Ray_t* pRay)
|
||||
bool CRayTrace::TraceShapeEx(const Vector& vecStart, const Vector& vecEnd, CTraceFilter* pTraceFilter, Ray_t* pRay, TraceResult* pTraceResult)
|
||||
{
|
||||
if (!m_pCNavPhysicsInterface_TraceShape)
|
||||
{
|
||||
FP_ERROR("CNavPhysicsInterface::TraceShape is not bound!");
|
||||
return TraceResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector vecStartCopy = vecStart;
|
||||
|
|
@ -166,6 +157,8 @@ namespace RayTracePlugin::RayTrace
|
|||
bool (*)(void*, Ray_t&, Vector&, Vector&, CTraceFilter*, CGameTrace*)>()(
|
||||
nullptr, *pRay, vecStartCopy, vecEndCopy, pTraceFilter, &trace);
|
||||
|
||||
return TraceResult(&trace, bResult);
|
||||
*pTraceResult = TraceResult(&trace);
|
||||
|
||||
return bResult;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ namespace RayTracePlugin::RayTrace
|
|||
public:
|
||||
bool Initialize();
|
||||
public:
|
||||
TraceResult TraceShape(const Vector& vecStart, const QAngle& angAngles, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions) override;
|
||||
TraceResult TraceEndShape(const Vector& vecStart, const Vector& vecEnd, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions) override;
|
||||
TraceResult TraceHullShape(const Vector& vecStart, const Vector& vecEnd, const Vector& vecMins, const Vector& vecMaxs, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions) override;
|
||||
TraceResult TraceShapeEx(const Vector& vecStart, const Vector& vecEnd, CTraceFilter* pTraceFilter, Ray_t* pRay) override;
|
||||
bool TraceShape(const Vector& vecStart, const QAngle& angAngles, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult) override;
|
||||
bool TraceEndShape(const Vector& vecStart, const Vector& vecEnd, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult) override;
|
||||
bool TraceHullShape(const Vector& vecStart, const Vector& vecEnd, const Vector& vecMins, const Vector& vecMaxs, CEntityInstance* pIgnoreEntity, TraceOptions* pTraceOptions, TraceResult* pTraceResult) override;
|
||||
bool TraceShapeEx(const Vector& vecStart, const Vector& vecEnd, CTraceFilter* pTraceFilter, Ray_t* pRay, TraceResult* pTraceResult) override;
|
||||
protected:
|
||||
DynLibUtils::CMemory m_pCNavPhysicsInterface_TraceShape;
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue