[CMAKE]: Use some CMAKE magic to have widl defined as a "host tool", and make the...
[reactos.git] / include / dxsdk / d3dvec.inl
1
2 #include <math.h>
3
4
5 inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
6 {
7 x = y = z = f;
8 }
9
10 inline
11 _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
12 {
13 x = _x;
14 y = _y;
15 z = _z;
16 }
17
18 inline _D3DVECTOR::_D3DVECTOR(const D3DVALUE f[3])
19 {
20 x = f[0];
21 y = f[1];
22 z = f[2];
23 }
24
25 inline const D3DVALUE& _D3DVECTOR::operator[](int i) const
26 {
27 return (&x)[i];
28 }
29
30 inline D3DVALUE& _D3DVECTOR::operator[](int i)
31 {
32 return (&x)[i];
33 }
34
35 inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
36 {
37 x += v.x;
38 y += v.y;
39 z += v.z;
40 return *this;
41 }
42
43 inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
44 {
45 x -= v.x;
46 y -= v.y;
47 z -= v.z;
48 return *this;
49 }
50
51 inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
52 {
53 x *= v.x;
54 y *= v.y;
55 z *= v.z;
56 return *this;
57 }
58
59 inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
60 {
61 x /= v.x;
62 y /= v.y;
63 z /= v.z;
64 return *this;
65 }
66
67 inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
68 {
69 x *= s;
70 y *= s;
71 z *= s;
72 return *this;
73 }
74
75 inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
76 {
77 x /= s;
78 y /= s;
79 z /= s;
80 return *this;
81 }
82
83 inline _D3DVECTOR operator + (const _D3DVECTOR& v)
84 {
85 return v;
86 }
87
88 inline _D3DVECTOR operator - (const _D3DVECTOR& v)
89 {
90 return _D3DVECTOR(-v.x, -v.y, -v.z);
91 }
92
93 inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
94 {
95 return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
96 }
97
98 inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
99 {
100 return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
101 }
102
103 inline _D3DVECTOR operator * (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
104 {
105 return _D3DVECTOR(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
106 }
107
108 inline _D3DVECTOR operator / (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
109 {
110 return _D3DVECTOR(v1.x/v2.x, v1.y/v2.y, v1.z/v2.z);
111 }
112
113 inline int operator < (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
114 {
115 return v1[0] < v2[0] && v1[1] < v2[1] && v1[2] < v2[2];
116 }
117
118 inline int operator <= (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
119 {
120 return v1[0] <= v2[0] && v1[1] <= v2[1] && v1[2] <= v2[2];
121 }
122
123 inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
124 {
125 return _D3DVECTOR(s*v.x, s*v.y, s*v.z);
126 }
127
128 inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
129 {
130 return _D3DVECTOR(s*v.x, s*v.y, s*v.z);
131 }
132
133 inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
134 {
135 return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
136 }
137
138 inline int operator == (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
139 {
140 return v1.x==v2.x && v1.y==v2.y && v1.z == v2.z;
141 }
142
143 inline D3DVALUE Magnitude (const _D3DVECTOR& v)
144 {
145 return (D3DVALUE) sqrt(SquareMagnitude(v));
146 }
147
148 inline D3DVALUE SquareMagnitude (const _D3DVECTOR& v)
149 {
150 return v.x*v.x + v.y*v.y + v.z*v.z;
151 }
152
153 inline _D3DVECTOR Normalize (const _D3DVECTOR& v)
154 {
155 return v / Magnitude(v);
156 }
157
158 inline D3DVALUE Min (const _D3DVECTOR& v)
159 {
160 D3DVALUE ret = v.x;
161 if (v.y < ret)
162 ret = v.y;
163
164 if (v.z < ret)
165 ret = v.z;
166
167 return ret;
168 }
169
170 inline D3DVALUE Max (const _D3DVECTOR& v)
171 {
172 D3DVALUE ret = v.x;
173 if (ret < v.y)
174 ret = v.y;
175
176 if (ret < v.z)
177 ret = v.z;
178
179 return ret;
180 }
181
182 inline _D3DVECTOR Minimize (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
183 {
184 return _D3DVECTOR( v1[0] < v2[0] ? v1[0] : v2[0],
185 v1[1] < v2[1] ? v1[1] : v2[1],
186 v1[2] < v2[2] ? v1[2] : v2[2]);
187 }
188
189 inline _D3DVECTOR Maximize (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
190 {
191 return _D3DVECTOR( v1[0] > v2[0] ? v1[0] : v2[0],
192 v1[1] > v2[1] ? v1[1] : v2[1],
193 v1[2] > v2[2] ? v1[2] : v2[2]);
194 }
195
196 inline D3DVALUE DotProduct (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
197 {
198 return v1.x*v2.x + v1.y * v2.y + v1.z*v2.z;
199 }
200
201 inline _D3DVECTOR CrossProduct (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
202 {
203 _D3DVECTOR result;
204 result[0] = v1[1] * v2[2] - v1[2] * v2[1];
205 result[1] = v1[2] * v2[0] - v1[0] * v2[2];
206 result[2] = v1[0] * v2[1] - v1[1] * v2[0];
207
208 return result;
209 }
210
211 inline _D3DMATRIX operator* (const _D3DMATRIX& a, const _D3DMATRIX& b)
212 {
213 _D3DMATRIX ret;
214 for (int i=0; i<4; i++)
215 {
216 for (int j=0; j<4; j++)
217 {
218 ret(i, j) = 0.0f;
219 for (int k=0; k<4; k++)
220 {
221 ret(i, j) += a(i, k) * b(k, j);
222 }
223 }
224 }
225 return ret;
226 }
227