-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMathLib.h
116 lines (90 loc) · 1.91 KB
/
MathLib.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
#pragma once
#include <math.h>
// #define F_EPSILON (0.0002f)
class Frame;
class Vec2D
{
public:
inline Vec2D() {
}
inline Vec2D(float _x, float _y) {
x = _x;
y = _y;
}
inline Vec2D& operator+=(const Vec2D& quant) {
x += quant.x;
y += quant.y;
return *this;
}
ULONG pack_size();
ULONG Pack(BYTE** ppData, ULONG iSize);
BOOL UnPack(BYTE** ppData, ULONG iSize);
float x, y;
};
Vector cross_product(const Vector& v1, const Vector& v2);
// Imaginary class, either entirely inlined by Turbine or non-existant.
class Quaternion
{
public:
inline Quaternion() {
}
inline Quaternion(float _w, float _x, float _y, float _z) {
w = _w;
x = _x;
y = _y;
z = _z;
}
// Should probably be renamed. It's not the length of the quaternion!!
inline float magnitude() const {
return (float)sqrt((x * x) + (y * y) + (z * z) + (w * w));
}
inline ULONG pack_size() {
return(sizeof(float) * 4);
}
inline ULONG Pack(BYTE** ppData, ULONG iSize) {
// The client performs no size check, but we will.
ULONG PackSize = pack_size();
if (iSize >= PackSize) {
PACK(float, w);
PACK(float, x);
PACK(float, y);
PACK(float, z);
}
return PackSize;
}
inline BOOL UnPack(BYTE** ppData, ULONG iSize) {
if (iSize < pack_size())
return FALSE;
UNPACK(float, w);
UNPACK(float, x);
UNPACK(float, y);
UNPACK(float, z);
return TRUE;
}
BOOL IsValid() const;
void normalize();
float dot_product(const Quaternion& q) const;
float w, x, y, z;
};
class Ray
{
public:
Vector m_origin;
Vector m_direction;
};
class Plane
{
public:
// Constructors
Plane();
Plane(Vector& Vect1, Vector& Vect2);
// Pack Functions
ULONG pack_size();
BOOL UnPack(BYTE** ppData, ULONG iSize);
// Math Functions
float dot_product(const Vector& point);
int which_side(const Vector& point, float near_dist);
BOOL compute_time_of_intersection(const Ray& ray, float *time);
Vector m_normal;
float m_dist;
};