forked from faggotman69/Prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.h
More file actions
616 lines (496 loc) · 11.4 KB
/
Vector.h
File metadata and controls
616 lines (496 loc) · 11.4 KB
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#ifndef _VECTORZ_H
#define _VECTORZ_H
#define CHECK_VALID( _v ) 0
#define Assert( _exp ) ((void)0)
#include <Windows.h>
#include <math.h>
// from the leaked sdk
#define FORCEINLINE __forceinline
typedef float vec_t;
inline vec_t BitsToFloat(unsigned long i)
{
return *reinterpret_cast<vec_t*>(&i);
}
#define M_PI 3.14159265358979323846
#define FLOAT32_NAN_BITS (unsigned long)0x7FC00000
#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS )
#define FLT_EPSILON 1.192092896e-07F // smallest such that 1.0+FLT_EPSILON != 1.0
#define VEC_T_NAN FLOAT32_NAN
#include <xmmintrin.h>
inline float FastSqrt(float x)
{
auto root = _mm_sqrt_ss(_mm_load_ss(&x));
return *(reinterpret_cast<float *>(&root));
}
class Vector
{
public:
vec_t x, y, z;
Vector(void);
Vector(vec_t X, vec_t Y, vec_t Z);
explicit Vector(vec_t XYZ);
void Init(vec_t ix = 0.0f, vec_t iy = 0.0f, vec_t iz = 0.0f);
bool IsValid() const;
void Invalidate();
vec_t operator[](int i) const;
vec_t& operator[](int i);
vec_t* Base();
vec_t const* Base() const;
inline void Zero();
bool operator==(const Vector& v) const;
bool operator!=(const Vector& v) const;
FORCEINLINE Vector& operator+=(const Vector& v);
FORCEINLINE Vector& operator-=(const Vector& v);
FORCEINLINE Vector& operator*=(const Vector& v);
FORCEINLINE Vector& operator*=(float s);
FORCEINLINE Vector& operator/=(const Vector& v);
FORCEINLINE Vector& operator/=(float s);
FORCEINLINE Vector& operator+=(float fl);
FORCEINLINE Vector& operator-=(float fl);
void Negate();
inline vec_t Length() const;
FORCEINLINE vec_t LengthSqr(void) const
{
return (x * x + y * y + z * z);
}
bool IsZero(float tolerance = 0.01f) const
{
return (x > -tolerance && x < tolerance &&
y > -tolerance && y < tolerance &&
z > -tolerance && z < tolerance);
}
vec_t NormalizeInPlace();
Vector Normalized() const
{
Vector norm = *this;
float radius = FastSqrt(norm.x * norm.x + norm.y * norm.y + norm.z * norm.z);
// FLT_EPSILON is added to the radius to eliminate the possibility of divide by zero.
float iradius = 1.f / (radius + FLT_EPSILON);
norm.x *= iradius;
norm.y *= iradius;
norm.z *= iradius;
return norm;
}
bool IsLengthGreaterThan(float val) const;
bool IsLengthLessThan(float val) const;
FORCEINLINE bool WithinAABox(Vector const &boxmin, Vector const &boxmax);
vec_t DistTo(const Vector& vOther) const;
FORCEINLINE vec_t DistToSqr(const Vector& vOther) const
{
Vector delta;
delta.x = x - vOther.x;
delta.y = y - vOther.y;
delta.z = z - vOther.z;
return delta.LengthSqr();
}
void CopyToArray(float* rgfl) const;
void MulAdd(const Vector& a, const Vector& b, float scalar);
vec_t Dot(const Vector& vOther) const;
Vector& operator=(const Vector& vOther);
vec_t Length2D(void) const;
vec_t Length2DSqr(void) const;
Vector operator-(void) const;
Vector operator+(const Vector& v) const;
Vector operator-(const Vector& v) const;
Vector operator*(const Vector& v) const;
Vector operator/(const Vector& v) const;
Vector operator*(float fl) const;
Vector operator/(float fl) const;
Vector Cross(const Vector& vOther) const;
Vector Min(const Vector& vOther) const;
Vector Max(const Vector& vOther) const;
Vector Direction()
{
return Vector(cos(y * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin(y * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin(-x * M_PI / 180.0f)).Normalized();
}
Vector Forward()
{
return Direction();
}
Vector Up()
{
return Vector(cos(y * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin(y * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin(-(x - 90.0f) * M_PI / 180.0f)).Normalized();
}
Vector Right()
{
return Vector(cos((y + 90.f) * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin((y + 90.f) * M_PI / 180.0f) * cos(x * M_PI / 180.0f), sin(-x * M_PI / 180.0f)).Normalized();
}
};
FORCEINLINE Vector ReplicateToVector(float x)
{
return Vector(x, x, x);
}
inline Vector::Vector(void)
{
}
inline Vector::Vector(vec_t X, vec_t Y, vec_t Z)
{
x = X; y = Y; z = Z;
}
inline Vector::Vector(vec_t XYZ)
{
x = y = z = XYZ;
}
inline void Vector::Init(vec_t ix, vec_t iy, vec_t iz)
{
x = ix; y = iy; z = iz;
}
inline void Vector::Zero()
{
x = y = z = 0.0f;
}
inline void VectorClear(Vector& a)
{
a.x = a.y = a.z = 0.0f;
}
inline Vector& Vector::operator=(const Vector& vOther)
{
x = vOther.x; y = vOther.y; z = vOther.z;
return *this;
}
inline vec_t& Vector::operator[](int i)
{
return ((vec_t*)this)[i];
}
inline vec_t Vector::operator[](int i) const
{
return ((vec_t*)this)[i];
}
inline vec_t* Vector::Base()
{
return (vec_t*)this;
}
inline vec_t const* Vector::Base() const
{
return (vec_t const*)this;
}
inline bool Vector::IsValid() const
{
return (x == x && y == y && z == z);
}
inline void Vector::Invalidate()
{
x = y = z = VEC_T_NAN;
}
inline bool Vector::operator==(const Vector& src) const
{
return (src.x == x) && (src.y == y) && (src.z == z);
}
inline bool Vector::operator!=(const Vector& src) const
{
return (src.x != x) || (src.y != y) || (src.z != z);
}
FORCEINLINE void VectorCopy(const Vector& src, Vector& dst)
{
dst.x = src.x;
dst.y = src.y;
dst.z = src.z;
}
inline void Vector::CopyToArray(float* rgfl) const
{
rgfl[0] = x; rgfl[1] = y; rgfl[2] = z;
}
inline void Vector::Negate()
{
x = -x; y = -y; z = -z;
}
FORCEINLINE Vector& Vector::operator+=(const Vector& v)
{
x += v.x; y += v.y; z += v.z;
return *this;
}
FORCEINLINE Vector& Vector::operator-=(const Vector& v)
{
x -= v.x; y -= v.y; z -= v.z;
return *this;
}
FORCEINLINE Vector& Vector::operator*=(float fl)
{
x *= fl;
y *= fl;
z *= fl;
return *this;
}
FORCEINLINE Vector& Vector::operator*=(const Vector& v)
{
x *= v.x;
y *= v.y;
z *= v.z;
return *this;
}
FORCEINLINE Vector& Vector::operator+=(float fl)
{
x += fl;
y += fl;
z += fl;
return *this;
}
FORCEINLINE Vector& Vector::operator-=(float fl)
{
x -= fl;
y -= fl;
z -= fl;
return *this;
}
FORCEINLINE Vector& Vector::operator/=(float fl)
{
float oofl = 1.0f / fl;
x *= oofl;
y *= oofl;
z *= oofl;
return *this;
}
FORCEINLINE Vector& Vector::operator/=(const Vector& v)
{
x /= v.x;
y /= v.y;
z /= v.z;
return *this;
}
FORCEINLINE void VectorAdd(const Vector& a, const Vector& b, Vector& c)
{
c.x = a.x + b.x;
c.y = a.y + b.y;
c.z = a.z + b.z;
}
FORCEINLINE void VectorSubtract(const Vector& a, const Vector& b, Vector& c)
{
c.x = a.x - b.x;
c.y = a.y - b.y;
c.z = a.z - b.z;
}
FORCEINLINE void VectorMultiply(const Vector& a, vec_t b, Vector& c)
{
c.x = a.x * b;
c.y = a.y * b;
c.z = a.z * b;
}
FORCEINLINE void VectorMultiply(const Vector& a, const Vector& b, Vector& c)
{
c.x = a.x * b.x;
c.y = a.y * b.y;
c.z = a.z * b.z;
}
inline void VectorScale(const Vector& in, vec_t scale, Vector& result)
{
VectorMultiply(in, scale, result);
}
FORCEINLINE void VectorDivide(const Vector& a, vec_t b, Vector& c)
{
vec_t oob = 1.0f / b;
c.x = a.x * oob;
c.y = a.y * oob;
c.z = a.z * oob;
}
FORCEINLINE void VectorDivide(const Vector& a, const Vector& b, Vector& c)
{
c.x = a.x / b.x;
c.y = a.y / b.y;
c.z = a.z / b.z;
}
inline void Vector::MulAdd(const Vector& a, const Vector& b, float scalar)
{
x = a.x + b.x * scalar;
y = a.y + b.y * scalar;
z = a.z + b.z * scalar;
}
inline void VectorLerp(const Vector& src1, const Vector& src2, vec_t t, Vector& dest)
{
dest.x = src1.x + (src2.x - src1.x) * t;
dest.y = src1.y + (src2.y - src1.y) * t;
dest.z = src1.z + (src2.z - src1.z) * t;
}
FORCEINLINE vec_t DotProduct(const Vector& a, const Vector& b)
{
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
inline vec_t Vector::Dot(const Vector& vOther) const
{
return DotProduct(*this, vOther);
}
inline void CrossProduct(const Vector& a, const Vector& b, Vector& result)
{
result.x = a.y * b.z - a.z * b.y;
result.y = a.z * b.x - a.x * b.z;
result.z = a.x * b.y - a.y * b.x;
}
//inline vec_t DotProductAbs(const Vector& v0, const Vector& v1)
//{
// return abs(v0.x * v1.x) + abs(v0.y * v1.y) + abs(v0.z * v1.z);
//}
inline vec_t VectorLength(const Vector& v)
{
return (vec_t)sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
inline vec_t Vector::Length(void) const
{
return VectorLength(*this);
}
inline vec_t VectorNormalize(Vector& v)
{
vec_t l = v.Length();
if (l != 0.0f)
{
v /= l;
}
else
{
v.x = v.y = 0.0f; v.z = 1.0f;
}
return l;
}
FORCEINLINE float VectorNormalizer(float * v)
{
return VectorNormalize(*(reinterpret_cast<Vector *>(v)));
}
inline vec_t Vector::NormalizeInPlace()
{
return VectorNormalize(*this);
}
bool Vector::WithinAABox(Vector const &boxmin, Vector const &boxmax)
{
return (
(x >= boxmin.x) && (x <= boxmax.x) &&
(y >= boxmin.y) && (y <= boxmax.y) &&
(z >= boxmin.z) && (z <= boxmax.z)
);
}
inline vec_t Vector::DistTo(const Vector& vOther) const
{
Vector delta;
VectorSubtract(*this, vOther, delta);
return delta.Length();
}
inline Vector Vector::Min(const Vector& vOther) const
{
return Vector(x < vOther.x ? x : vOther.x,
y < vOther.y ? y : vOther.y,
z < vOther.z ? z : vOther.z);
}
inline Vector Vector::Max(const Vector& vOther) const
{
return Vector(x > vOther.x ? x : vOther.x,
y > vOther.y ? y : vOther.y,
z > vOther.z ? z : vOther.z);
}
inline Vector Vector::operator-(void) const
{
return Vector(-x, -y, -z);
}
inline Vector Vector::operator+(const Vector& v) const
{
Vector res;
VectorAdd(*this, v, res);
return res;
}
inline Vector Vector::operator-(const Vector& v) const
{
Vector res;
VectorSubtract(*this, v, res);
return res;
}
inline Vector Vector::operator*(float fl) const
{
Vector res;
VectorMultiply(*this, fl, res);
return res;
}
inline Vector Vector::operator*(const Vector& v) const
{
Vector res;
VectorMultiply(*this, v, res);
return res;
}
inline Vector Vector::operator/(float fl) const
{
Vector res;
VectorDivide(*this, fl, res);
return res;
}
inline Vector Vector::operator/(const Vector& v) const
{
Vector res;
VectorDivide(*this, v, res);
return res;
}
inline Vector operator*(float fl, const Vector& v)
{
return v * fl;
}
inline Vector Vector::Cross(const Vector& vOther) const
{
Vector res;
CrossProduct(*this, vOther, res);
return res;
}
inline vec_t Vector::Length2D(void) const
{
return (vec_t)::sqrtf(x * x + y * y);
}
inline vec_t Vector::Length2DSqr(void) const
{
return (x * x + y * y);
}
inline Vector CrossProduct(const Vector& a, const Vector& b)
{
return Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}
inline void VectorMin(const Vector& a, const Vector& b, Vector& result)
{
result.x = min(a.x, b.x);
result.y = min(a.y, b.y);
result.z = min(a.z, b.z);
}
inline void VectorMax(const Vector& a, const Vector& b, Vector& result)
{
result.x = max(a.x, b.x);
result.y = max(a.y, b.y);
result.z = max(a.z, b.z);
}
typedef Vector QAngle;
class VectorAligned : public Vector
{
public:
VectorAligned()
{
x = y = z = 0.0f;
}
VectorAligned(const Vector& v)
{
x = v.x; y = v.y; z = v.z;
}
float w;
};
struct CViewSetup
{
char _0x0000[16];
__int32 x;
__int32 x_old;
__int32 y;
__int32 y_old;
__int32 width;
__int32 width_old;
__int32 height;
__int32 height_old;
char _0x0030[128];
float fov;
float fovViewmodel;
Vector origin;
Vector angles;
float zNear;
float zFar;
float zNearViewmodel;
float zFarViewmodel;
float m_flAspectRatio;
float m_flNearBlurDepth;
float m_flNearFocusDepth;
float m_flFarFocusDepth;
float m_flFarBlurDepth;
float m_flNearBlurRadius;
float m_flFarBlurRadius;
float m_nDoFQuality;
__int32 m_nMotionBlurMode;
char _0x0104[68];
__int32 m_EdgeBlur;
};
#endif // VECTOR_H