-
Notifications
You must be signed in to change notification settings - Fork 5
/
Angle.h
164 lines (129 loc) · 2.74 KB
/
Angle.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
#include "Interfaces.h"
#define M_PI 3.14159265358979323846f
#define M_RADPI 57.295779513082f
#define RAD2DEG(x) ((float)(x) * (float)(180.f / M_PI))
#define DEG2RAD(x) ((float)(x) / (float)(180.f / M_PI))
class Angle : public Vector
{
public:
Angle(float _x = 0.f, float _y = 0.f, float _z = 0.f)
{
Init(_x, _y, _z);
}
float& operator[](int i)
{
return ((float*)this)[i];
}
float operator[](int i) const
{
return ((float*)this)[i];
}
Angle operator+(const Angle& in)
{
return Angle(this->x + in.x, this->y + in.y, this->z + in.z);
}
Angle operator-(const Angle& in)
{
return Angle(this->x - in.x, this->y - in.y, this->z - in.z);
}
Angle operator*(const Angle& in)
{
return Angle(this->x * in.x, this->y * in.y, this->z * in.z);
}
Angle operator/(const Angle& in)
{
return Angle(this->x / in.x, this->y / in.y, this->z / in.z);
}
Angle operator-=(const Angle& in)
{
this->x -= in.x;
this->y -= in.y;
this->z -= in.z;
return *this;
}
Angle operator+=(const Angle& in)
{
this->x += in.x;
this->y += in.y;
this->z += in.z;
return *this;
}
Angle operator/=(const Angle& in)
{
this->x /= in.x;
this->y /= in.y;
this->z /= in.z;
return *this;
}
Angle operator*=(const Angle& in)
{
this->x *= in.x;
this->y *= in.y;
this->z *= in.z;
return *this;
}
void Clear()
{
this->x = this->y = this->z = .0f;
}
Angle Normalize()
{
if (this->x != this->x)
this->x = 0;
if (this->y != this->y)
this->y = 0;
if (this->z != this->z)
this->z = 0;
if (this->x > 89.f)
this->x = 89.f;
if (this->x < -89.f)
this->x = -89.f;
while (this->y > 180)
this->y -= 360;
while (this->y <= -180)
this->y += 360;
if (this->y > 180.f)
this->y = 180.f;
if (this->y < -180.f)
this->y = -180.f;
this->z = 0;
return *this;
}
float Difference(Angle angDestination)
{
bool bX180 = false;
bool bY180 = false;
float XDiff = _Normalize(this->x - angDestination.x);
float YDiff = _Normalize(this->y - angDestination.y);
bX180 = 180 > XDiff;
bY180 = 180 > YDiff;
if (!bX180)
XDiff -= 360;
if (!bY180)
YDiff -= 360;
if (0 > XDiff)
XDiff = (XDiff - XDiff) - XDiff;
if (0 > YDiff)
YDiff = (YDiff - YDiff) - YDiff;
float Diff = YDiff + XDiff;
return Diff;
}
/*
nigga that shit broken af
float Difference(Angle dest)
{
float _x = DEG2RAD(this->x);
float _y = DEG2RAD(this->y);
float __x = DEG2RAD(dest.x);
float __y = DEG2RAD(dest.y);
Vector a = Vector(sin(_x) * cos(_y), sin(_x) * sin(_y), cos(_x));
Vector b = Vector(sin(__x) * cos(__y), sin(__x) * sin(__y), cos(__x));
return RAD2DEG(acos(a.x * b.x + a.y * b.y + a.z * b.z));
}
*/
private:
float _Normalize(float angAngle)
{
return (float)(fmod(angAngle + 180, 360) - 180);
}
};