-
Notifications
You must be signed in to change notification settings - Fork 6
/
cPoint3D.h
149 lines (119 loc) · 2.8 KB
/
cPoint3D.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
#pragma once
class cPoint3D {
public:
cPoint3D()
{
}
cPoint3D(float nx, float ny, float nz)
{
x = nx;
y = ny;
z = nz;
}
bool operator ==(cPoint3D p3dOther)
{
if (x != p3dOther.x) return false;
if (y != p3dOther.y) return false;
if (z != p3dOther.z) return false;
return true;
}
bool operator !=(cPoint3D p3dOther)
{
return !((x == p3dOther.x) && (y == p3dOther.y) && (z == p3dOther.z));
}
cPoint3D operator *(float fOther)
{
return cPoint3D(x * fOther, y * fOther, z * fOther);
}
cPoint3D operator /(float fOther)
{
return cPoint3D(x / fOther, y / fOther, z / fOther);
}
cPoint3D operator +(cPoint3D p3dOther)
{
return cPoint3D(x + p3dOther.x, y + p3dOther.y, z + p3dOther.z);
}
cPoint3D operator -(cPoint3D p3dOther)
{
return cPoint3D(x - p3dOther.x, y - p3dOther.y, z - p3dOther.z);
}
void operator *=(float fOther)
{
x *= fOther;
y *= fOther;
z *= fOther;
return; //true;
}
void operator /=(float fOther)
{
x /= fOther;
y /= fOther;
z /= fOther;
return; //true;
}
void operator +=(cPoint3D p3dOther)
{
x += p3dOther.x;
y += p3dOther.y;
z += p3dOther.z;
return; //true;
}
void operator -=(cPoint3D p3dOther)
{
x -= p3dOther.x;
y -= p3dOther.y;
z -= p3dOther.z;
return; //true;
}
void RotateAround(cPoint3D Center, cPoint3D Rotation)
{
float tpx, tpy, tpz;
x -= Center.x;
y -= Center.y;
z -= Center.z;
tpy = y * (float) cos(Rotation.x) - z * (float) sin(Rotation.x);
tpz = z * (float) cos(Rotation.x) + y * (float) sin(Rotation.x);
z = tpz * (float) cos(Rotation.y) - x * (float) sin(Rotation.y) + Center.z;
tpx = x * (float) cos(Rotation.y) + tpz * (float) sin(Rotation.y);
x = tpx * (float) cos(Rotation.z) - tpy * (float) sin(Rotation.z) + Center.x;
y = tpy * (float) cos(Rotation.z) + tpx * (float) sin(Rotation.z) + Center.y;
}
cPoint3D CrossProduct(cPoint3D p3dOther)
{
return cPoint3D(y*p3dOther.z - p3dOther.y*z, z*p3dOther.x - p3dOther.z*x, x*p3dOther.y - p3dOther.x*y);
}
float DotProduct(cPoint3D p3dOther)
{
return x*p3dOther.x + y*p3dOther.y + z*p3dOther.z;
}
void Normalize()
{
float fTemp = (float) Abs();
x /= fTemp;
y /= fTemp;
z /= fTemp;
}
void CalcFromLocation(stLocation *Loc)
{
z = Loc->zOffset / 240.0f;
DWORD dwBlockX = (Loc->landblock & 0xff000000) >> 24;
DWORD dwBlockY = (Loc->landblock & 0x00ff0000) >> 16;
if (dwBlockX < 3)
{
// dungeon, dwBlockX and dwBlockY remain constant - just use x and y
x = Loc->xOffset / 240.0f;
y = Loc->yOffset / 240.0f;
}
else
{
// outdoors
x = (float) ((((float (dwBlockX)+1.0f) * 8.0f + (Loc->xOffset / 24.0)) - 1027.5) / 10.0f);
y = (float) ((((float (dwBlockY)+1.0f) * 8.0f + (Loc->yOffset / 24.0)) - 1027.5) / 10.0f);
}
}
float Abs()
{
return (float) sqrt(x*x+y*y+z*z);
}
float x, y, z;
};