This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IEngineTrace.h
executable file
·181 lines (147 loc) · 5.23 KB
/
IEngineTrace.h
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
enum TraceType_t /* Taken from GamerFood's TraceEngine. Credits to him! */
{
TRACE_EVERYTHING = 0,
TRACE_WORLD_ONLY, // NOTE: This does *not* test static props!!!
TRACE_ENTITIES_ONLY, // NOTE: This version will *not* test static props
TRACE_EVERYTHING_FILTER_PROPS, // NOTE: This version will pass the IHandleEntity for props through the filter, unlike all other filters
};
struct Ray_t
{
Ray_t( ) { }
VectorAligned m_Start;
VectorAligned m_Delta;
VectorAligned m_StartOffset;
VectorAligned m_Extents;
const matrix3x4_t *m_pWorldAxisTransform;
bool m_IsRay;
bool m_IsSwept;
void Init( Vector vecStart, Vector vecEnd )
{
m_Delta = VectorAligned( vecEnd - vecStart );
m_IsSwept = ( m_Delta.LengthSqr( ) != 0 );
m_Extents.Zero( );
m_pWorldAxisTransform = NULL;
m_IsRay = true;
m_StartOffset.Zero( );
m_Start = vecStart;
}
};
class ITraceFilter
{
public:
virtual bool ShouldHitEntity( C_BaseEntity* pEntityHandle, int contentsMask )
{
return !( pEntityHandle == pSkip );
}
virtual TraceType_t GetTraceType( )
{
return TRACE_EVERYTHING;
}
void* pSkip;
};
class CTraceFilter : public ITraceFilter
{
public:
virtual bool ShouldHitEntity( C_BaseEntity* pEntityHandle, int contentsMask )
{
return !( pEntityHandle == pSkip );
}
virtual TraceType_t GetTraceType( ) const
{
return TRACE_EVERYTHING;
}
void* pSkip;
};
class CTraceFilterSkipTwoEntities : public ITraceFilter
{
public:
CTraceFilterSkipTwoEntities( void *pPassEnt1, void *pPassEnt2 )
{
pPassEntity1 = pPassEnt1;
pPassEntity2 = pPassEnt2;
}
virtual bool ShouldHitEntity( C_BaseEntity *pEntityHandle, int contentsMask )
{
return !( pEntityHandle == pPassEntity1 || pEntityHandle == pPassEntity2 );
}
virtual TraceType_t GetTraceType( ) const
{
return TRACE_EVERYTHING;
}
void *pPassEntity1;
void *pPassEntity2;
};
typedef bool( *ShouldHitFunc_t )( IHandleEntity *pHandleEntity, int contentsMask );
class CTraceFilterSimple : public CTraceFilter
{
public:
// It does have a base, but we'll never network anything below here..
CTraceFilterSimple( const IHandleEntity *passentity, int collisionGroup, ShouldHitFunc_t pExtraShouldHitCheckFn = NULL );
virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask );
virtual void SetPassEntity( const IHandleEntity *pPassEntity ) { m_pPassEnt = pPassEntity; }
virtual void SetCollisionGroup( int iCollisionGroup ) { m_collisionGroup = iCollisionGroup; }
const IHandleEntity *GetPassEntity( void ){ return m_pPassEnt; }
private:
const IHandleEntity *m_pPassEnt;
int m_collisionGroup;
ShouldHitFunc_t m_pExtraShouldHitCheckFunction;
};
class CBaseTrace
{
public:
Vector startpos;
Vector endpos;
cplane_t plane;
float fraction;
int contents;
unsigned short dispFlags;
bool allsolid;
bool startsolid;
CBaseTrace( ) {}
};
struct csurface_t
{
const char* name;
short surfaceProps;
unsigned short flags;
};
class CGameTrace : public CBaseTrace
{
public:
bool DidHitWorld() const;
bool DidHitNonWorldEntity() const;
int GetEntityIndex() const;
bool DidHit() const;
bool IsVisible() const;
public:
float fractionleftsolid;
csurface_t surface;
int hitgroup;
short physicsbone;
unsigned short worldSurfaceIndex;
C_BaseEntity* m_pEnt;
int hitbox;
CGameTrace() { }
private:
CGameTrace( const CGameTrace& vOther );
};
typedef CGameTrace trace_t;
class IEngineTrace {
public:
// Returns the contents mask + entity at a particular world-space position
virtual int GetPointContents(const Vector &vecAbsPosition, int contentsMask = MASK_ALL, IHandleEntity** ppEntity = NULL) = 0;
// Returns the contents mask of the world only @ the world-space position (static props are ignored)
virtual int GetPointContents_WorldOnly(const Vector &vecAbsPosition, int contentsMask = MASK_ALL) = 0;
// Get the point contents, but only test the specific entity. This works
// on static props and brush models.
//
// If the entity isn't a static prop or a brush model, it returns CONTENTS_EMPTY and sets
// bFailed to true if bFailed is non-null.
virtual int GetPointContents_Collideable(ICollideable *pCollide, const Vector &vecAbsPosition) = 0;
// Traces a ray against a particular entity
virtual void ClipRayToEntity(const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace) = 0;
// Traces a ray against a particular entity
virtual void ClipRayToCollideable(const Ray_t &ray, unsigned int fMask, ICollideable *pCollide, trace_t *pTrace) = 0;
// A version that simply accepts a ray (can work as a traceline or tracehull)
virtual void TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace) = 0;
};