-
Notifications
You must be signed in to change notification settings - Fork 2
/
matrix.hpp
364 lines (297 loc) · 8.13 KB
/
matrix.hpp
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#pragma once
#include "core.hpp"
#include "math.hpp"
#define Assert( _exp ) ((void)0)
#define DISPSURF_FLAG_SURFACE (1<<0)
#define DISPSURF_FLAG_WALKABLE (1<<1)
#define DISPSURF_FLAG_BUILDABLE (1<<2)
#define DISPSURF_FLAG_SURFPROP1 (1<<3)
#define DISPSURF_FLAG_SURFPROP2 (1<<4)
class IClientEntity;
class IHandleEntity;
class VectorAligned : public Vector
{
public:
VectorAligned() {}
VectorAligned(const Vector& vec)
{
this->x = vec.x;
this->y = vec.y;
this->z = vec.z;
}
float w;
};
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.LengthSquared() != 0);
m_Extents.Zero;
m_pWorldAxisTransform = NULL;
m_IsRay = true;
m_StartOffset.Zero;
m_Start = vecStart;
}
void Init(Vector const& start, Vector const& end, Vector const& mins, Vector const& maxs)
{
Assert(&end);
Math::VectorSubtract(end, start, m_Delta);
m_pWorldAxisTransform = NULL;
m_IsSwept = (m_Delta.LengthSquared() != 0);
Math::VectorSubtract(maxs, mins, m_Extents);
m_Extents *= 0.5f;
m_IsRay = (m_Extents.LengthSquared() < 1e-6);
// Offset m_Start to be in the center of the box...
Math::VectorAdd(mins, maxs, m_StartOffset);
m_StartOffset *= 0.5f;
Math::VectorAdd(start, m_StartOffset, m_Start);
m_StartOffset *= -1.0f;
}
};
struct cplane_t
{
Vector normal;
float dist;
uint8_t type; // for fast side tests
uint8_t signbits; // signx + (signy<<1) + (signz<<1)
uint8_t pad[2];
};
enum TraceType_t
{
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
};
class ITraceFilter
{
public:
virtual bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
{
return !(pEntityHandle == pSkip);
}
virtual TraceType_t GetTraceType()
{
return TRACE_EVERYTHING;
}
void* pSkip;
};
class CTraceFilter : public ITraceFilter
{
public:
virtual bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
{
return !(pEntityHandle == pSkip);
}
virtual TraceType_t GetTraceType() const
{
return TRACE_EVERYTHING;
}
void* pSkip;
//bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
//{
// ClientClass* pEntCC = ((CBaseEntity*)pEntityHandle)->GetClientClass();
// if (pEntCC && strcmp(ccIgnore, ""))
// {
// if (pEntCC->m_pNetworkName == ccIgnore)
// return false;
// }
// return !(pEntityHandle == pSkip);
//}
//virtual TraceType_t GetTraceType() const
//{
// return TraceType_t::TRACE_EVERYTHING;
//}
//inline void SetIgnoreClass(char* Class)
//{
// ccIgnore = Class;
//}
//void* pSkip;
//char* ccIgnore = "";
};
class CTraceFilterOneEntity : public ITraceFilter
{
public:
bool ShouldHitEntity(void* pEntityHandle, int contentsMask)
{
return (pEntityHandle == pEntity);
}
TraceType_t GetTraceType() const
{
return TRACE_EVERYTHING;
}
void* pEntity;
};
class CTraceFilterPlayersOnlyNoWorld : public CTraceFilter
{
public:
virtual bool ShouldHitEntity(IHandleEntity* pEntityHandle, int contentsMask)
{
if (!pEntityHandle || pEntityHandle == pSkip)
return false;
if (((IClientEntity*)pEntityHandle) && AllowTeammates)
return true;
return false;
}
virtual TraceType_t GetTraceType()
{
return TRACE_ENTITIES_ONLY;
}
bool AllowTeammates;
};
class CTraceCBaseEntity : public ITraceFilter
{
public:
bool ShouldHitCBaseEntity(IClientEntity* pCBaseEntityHandle, int contentsMask)
{
return (pCBaseEntityHandle == pHit);
}
virtual TraceType_t GetTraceType() const
{
return TRACE_ENTITIES_ONLY;
}
void* pHit;
};
class CTraceFilterWorldOnly : public ITraceFilter
{
public:
bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
{
return (pEntityHandle && (*(int*)((uintptr_t)pEntityHandle + 0x64)) == 0);
}
TraceType_t GetTraceType()
{
return TRACE_WORLD_ONLY;
}
};
class CTraceFilterWorldAndPropsOnly : public ITraceFilter
{
public:
bool ShouldHitEntity(IClientEntity* pServerEntity, int contentsMask)
{
return false;
}
virtual TraceType_t GetTraceType() const
{
return TRACE_EVERYTHING;
}
};
class CTraceFilterSkipTwoEntities : public ITraceFilter {
public:
CTraceFilterSkipTwoEntities(void* pPassEnt1, void* pPassEnt2) {
passentity1 = pPassEnt1;
passentity2 = pPassEnt2;
}
virtual bool ShouldHitEntity(void* pEntityHandle, int contentsMask) {
return !(pEntityHandle == passentity1 || pEntityHandle == passentity2);
}
virtual TraceType_t GetTraceType() const {
return TRACE_EVERYTHING;
}
void* passentity1;
void* passentity2;
};
typedef bool(*ShouldHitFunc_t)(IHandleEntity* pHandleEntity, int contentsMask);
class CTraceFilterSimple : public CTraceFilter
{
public:
CTraceFilterSimple(const IHandleEntity* passedict, int collisionGroup,
ShouldHitFunc_t pExtraShouldHitFunc = NULL)
{
m_pPassEnt = passedict;
m_collisionGroup = collisionGroup;
m_pExtraShouldHitCheckFunction = pExtraShouldHitFunc;
}
virtual bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
{
return !(pEntityHandle == pSkip);
}
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:
bool IsDispSurface(void) { return ((dispFlags & DISPSURF_FLAG_SURFACE) != 0); }
bool IsDispSurfaceWalkable(void) { return ((dispFlags & DISPSURF_FLAG_WALKABLE) != 0); }
bool IsDispSurfaceBuildable(void) { return ((dispFlags & DISPSURF_FLAG_BUILDABLE) != 0); }
bool IsDispSurfaceProp1(void) { return ((dispFlags & DISPSURF_FLAG_SURFPROP1) != 0); }
bool IsDispSurfaceProp2(void) { return ((dispFlags & DISPSURF_FLAG_SURFPROP2) != 0); }
public:
// these members are aligned!!
Vector startpos; // start position
Vector endpos; // final position
cplane_t plane; // surface normal at impact
float fraction; // time completed, 1.0 = didn't hit anything
int contents; // contents on other side of surface hit
unsigned short dispFlags; // displacement flags for marking surfaces with data
bool allsolid; // if true, plane is not valid
bool startsolid; // if true, the initial point was in a solid area
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;
IClientEntity* m_pEnt;
int hitbox;
CGameTrace() { }
private:
CGameTrace(const CGameTrace& vOther);
};
inline bool CGameTrace::IsVisible() const
{
return fraction > 0.97f;
}
inline bool CGameTrace::DidHit() const
{
return fraction < 1.0f || allsolid || startsolid;
}
inline bool CGameTrace::DidHitWorld() const
{
return m_pEnt && (*(int*)((uintptr_t)m_pEnt + 0x64)) == 0;
}
inline bool CGameTrace::DidHitNonWorldEntity() const
{
return m_pEnt != NULL && !DidHitWorld();
}
typedef CGameTrace trace_t;
class VMatrix
{
public:
float* operator [] (const std::uint32_t index);
const float* operator [] (const std::uint32_t index) const;
public:
float m[4][4] = { };
};
typedef float w2smatrix4x4[4][4];