1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 03:56:10 +08:00

Add CGameTrace, CTraceFilter, Ray_t & trace ray related enums/defines (#254)

This commit is contained in:
vanz696
2024-06-07 14:29:04 +03:00
committed by GitHub
parent 49a2b0b4ef
commit 6056e92838
7 changed files with 755 additions and 462 deletions

View File

@ -38,6 +38,15 @@ COLLISION DETECTION
#include "vcollide.h"
enum RayType_t : uint8
{
RAY_TYPE_LINE = 0,
RAY_TYPE_SPHERE,
RAY_TYPE_HULL,
RAY_TYPE_CAPSULE,
RAY_TYPE_MESH,
};
struct cmodel_t
{
Vector mins, maxs;
@ -59,70 +68,121 @@ struct csurface_t
//-----------------------------------------------------------------------------
struct Ray_t
{
VectorAligned m_Start; // starting point, centered within the extents
VectorAligned m_Delta; // direction + length of the ray
VectorAligned m_StartOffset; // Add this to m_Start to get the actual ray start
VectorAligned m_Extents; // Describes an axis aligned box extruded along a ray
const matrix3x4_t *m_pWorldAxisTransform;
bool m_IsRay; // are the extents zero?
bool m_IsSwept; // is delta != 0?
Ray_t() : m_pWorldAxisTransform( NULL ) {}
void Init( Vector const& start, Vector const& end )
Ray_t() { Init( Vector( 0.0f, 0.0f, 0.0f ) ); }
Ray_t( const Vector& vStartOffset ) { Init( vStartOffset ); }
Ray_t( const Vector& vCenter, float flRadius ) { Init( vCenter, flRadius ); }
Ray_t( const Vector& vMins, const Vector& vMaxs ) { Init( vMins, vMaxs ); }
Ray_t( const Vector& vCenterA, const Vector& vCenterB, float flRadius ) { Init( vCenterA, vCenterB, flRadius ); }
Ray_t( const Vector& vMins, const Vector& vMaxs, const Vector* pVertices, int nNumVertices ) { Init( vMins, vMaxs, pVertices, nNumVertices ); }
void Init( const Vector& vStartOffset )
{
Assert( &end );
VectorSubtract( end, start, m_Delta );
m_IsSwept = (m_Delta.LengthSqr() != 0);
VectorClear( m_Extents );
m_pWorldAxisTransform = NULL;
m_IsRay = true;
// Offset m_Start to be in the center of the box...
VectorClear( m_StartOffset );
VectorCopy( start, m_Start );
m_Line.m_vStartOffset = vStartOffset;
m_Line.m_flRadius = 0.0f;
m_eType = RAY_TYPE_LINE;
}
void Init( Vector const& start, Vector const& end, Vector const& mins, Vector const& maxs )
void Init( const Vector& vCenter, float flRadius )
{
Assert( &end );
VectorSubtract( end, start, m_Delta );
m_pWorldAxisTransform = NULL;
m_IsSwept = (m_Delta.LengthSqr() != 0);
VectorSubtract( maxs, mins, m_Extents );
m_Extents *= 0.5f;
m_IsRay = (m_Extents.LengthSqr() < 1e-6);
// Offset m_Start to be in the center of the box...
VectorAdd( mins, maxs, m_StartOffset );
m_StartOffset *= 0.5f;
VectorAdd( start, m_StartOffset, m_Start );
m_StartOffset *= -1.0f;
}
// compute inverse delta
Vector InvDelta() const
{
Vector vecInvDelta;
for ( int iAxis = 0; iAxis < 3; ++iAxis )
if ( flRadius > 0.0f )
{
if ( m_Delta[iAxis] != 0.0f )
m_Sphere.m_vCenter = vCenter;
m_Sphere.m_flRadius = flRadius;
m_eType = RAY_TYPE_SPHERE;
}
else
{
Init( vCenter );
}
}
void Init( const Vector& vMins, const Vector& vMaxs )
{
if ( vMins != vMaxs )
{
m_Hull.m_vMins = vMins;
m_Hull.m_vMaxs = vMaxs;
m_eType = RAY_TYPE_HULL;
}
else
{
Init( vMins );
}
}
void Init( const Vector& vCenterA, const Vector& vCenterB, float flRadius )
{
if ( vCenterA != vCenterB )
{
if ( flRadius > 0.0f )
{
vecInvDelta[iAxis] = 1.0f / m_Delta[iAxis];
m_Capsule.m_vCenter[0] = vCenterA;
m_Capsule.m_vCenter[1] = vCenterB;
m_Capsule.m_flRadius = flRadius;
m_eType = RAY_TYPE_CAPSULE;
}
else
{
vecInvDelta[iAxis] = FLT_MAX;
Init( vCenterA, vCenterB );
}
}
return vecInvDelta;
else
{
Init( vCenterA, flRadius );
}
}
private:
void Init( const Vector& vMins, const Vector& vMaxs, const Vector* pVertices, int nNumVertices )
{
m_Mesh.m_vMins = vMins;
m_Mesh.m_vMaxs = vMaxs;
m_Mesh.m_pVertices = pVertices;
m_Mesh.m_nNumVertices = nNumVertices;
m_eType = RAY_TYPE_MESH;
}
struct Line_t
{
Vector m_vStartOffset;
float m_flRadius;
};
struct Sphere_t
{
Vector m_vCenter;
float m_flRadius;
};
struct Hull_t
{
Vector m_vMins;
Vector m_vMaxs;
};
struct Capsule_t
{
Vector m_vCenter[2];
float m_flRadius;
};
struct Mesh_t
{
Vector m_vMins;
Vector m_vMaxs;
const Vector* m_pVertices;
int m_nNumVertices;
};
union
{
Line_t m_Line;
Sphere_t m_Sphere;
Hull_t m_Hull;
Capsule_t m_Capsule;
Mesh_t m_Mesh;
};
RayType_t m_eType;
};