1 | /*
|
---|
2 | * Copyright (C) 2007 David Adam
|
---|
3 | * Copyright (C) 2007 Tony Wasserka
|
---|
4 | *
|
---|
5 | * This library is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU Lesser General Public
|
---|
7 | * License as published by the Free Software Foundation; either
|
---|
8 | * version 2.1 of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This library is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | * Lesser General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU Lesser General Public
|
---|
16 | * License along with this library; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
18 | */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
22 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
23 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
24 | * a choice of LGPL license versions is made available with the language indicating
|
---|
25 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
26 | * of the LGPL is applied is otherwise unspecified.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef __D3DX9MATH_INL__
|
---|
30 | #define __D3DX9MATH_INL__
|
---|
31 |
|
---|
32 | /* constructors & operators */
|
---|
33 | #ifdef __cplusplus
|
---|
34 |
|
---|
35 | inline D3DXVECTOR2::D3DXVECTOR2()
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | inline D3DXVECTOR2::D3DXVECTOR2(CONST FLOAT *pf)
|
---|
40 | {
|
---|
41 | if(!pf) return;
|
---|
42 | x = pf[0];
|
---|
43 | y = pf[1];
|
---|
44 | }
|
---|
45 |
|
---|
46 | inline D3DXVECTOR2::D3DXVECTOR2(FLOAT fx, FLOAT fy)
|
---|
47 | {
|
---|
48 | x = fx;
|
---|
49 | y = fy;
|
---|
50 | }
|
---|
51 |
|
---|
52 | inline D3DXVECTOR2::operator FLOAT* ()
|
---|
53 | {
|
---|
54 | return (FLOAT*)&x;
|
---|
55 | }
|
---|
56 |
|
---|
57 | inline D3DXVECTOR2::operator CONST FLOAT* () const
|
---|
58 | {
|
---|
59 | return (CONST FLOAT*)&x;
|
---|
60 | }
|
---|
61 |
|
---|
62 | inline D3DXVECTOR2& D3DXVECTOR2::operator += (CONST D3DXVECTOR2& v)
|
---|
63 | {
|
---|
64 | x += v.x;
|
---|
65 | y += v.y;
|
---|
66 | return *this;
|
---|
67 | }
|
---|
68 |
|
---|
69 | inline D3DXVECTOR2& D3DXVECTOR2::operator -= (CONST D3DXVECTOR2& v)
|
---|
70 | {
|
---|
71 | x -= v.x;
|
---|
72 | y -= v.y;
|
---|
73 | return *this;
|
---|
74 | }
|
---|
75 |
|
---|
76 | inline D3DXVECTOR2& D3DXVECTOR2::operator *= (FLOAT f)
|
---|
77 | {
|
---|
78 | x *= f;
|
---|
79 | y *= f;
|
---|
80 | return *this;
|
---|
81 | }
|
---|
82 |
|
---|
83 | inline D3DXVECTOR2& D3DXVECTOR2::operator /= (FLOAT f)
|
---|
84 | {
|
---|
85 | x /= f;
|
---|
86 | y /= f;
|
---|
87 | return *this;
|
---|
88 | }
|
---|
89 |
|
---|
90 | inline D3DXVECTOR2 D3DXVECTOR2::operator + () const
|
---|
91 | {
|
---|
92 | return *this;
|
---|
93 | }
|
---|
94 |
|
---|
95 | inline D3DXVECTOR2 D3DXVECTOR2::operator - () const
|
---|
96 | {
|
---|
97 | return D3DXVECTOR2(-x, -y);
|
---|
98 | }
|
---|
99 |
|
---|
100 | inline D3DXVECTOR2 D3DXVECTOR2::operator + (CONST D3DXVECTOR2& v) const
|
---|
101 | {
|
---|
102 | return D3DXVECTOR2(x + v.x, y + v.y);
|
---|
103 | }
|
---|
104 |
|
---|
105 | inline D3DXVECTOR2 D3DXVECTOR2::operator - (CONST D3DXVECTOR2& v) const
|
---|
106 | {
|
---|
107 | return D3DXVECTOR2(x - v.x, y - v.y);
|
---|
108 | }
|
---|
109 |
|
---|
110 | inline D3DXVECTOR2 D3DXVECTOR2::operator * (FLOAT f) const
|
---|
111 | {
|
---|
112 | return D3DXVECTOR2(x * f, y * f);
|
---|
113 | }
|
---|
114 |
|
---|
115 | inline D3DXVECTOR2 D3DXVECTOR2::operator / (FLOAT f) const
|
---|
116 | {
|
---|
117 | return D3DXVECTOR2(x / f, y / f);
|
---|
118 | }
|
---|
119 |
|
---|
120 | inline D3DXVECTOR2 operator * (FLOAT f, CONST D3DXVECTOR2& v)
|
---|
121 | {
|
---|
122 | return D3DXVECTOR2(f * v.x, f * v.y);
|
---|
123 | }
|
---|
124 |
|
---|
125 | inline BOOL D3DXVECTOR2::operator == (CONST D3DXVECTOR2& v) const
|
---|
126 | {
|
---|
127 | return x == v.x && y == v.y;
|
---|
128 | }
|
---|
129 |
|
---|
130 | inline BOOL D3DXVECTOR2::operator != (CONST D3DXVECTOR2& v) const
|
---|
131 | {
|
---|
132 | return x != v.x || y != v.y;
|
---|
133 | }
|
---|
134 |
|
---|
135 | inline D3DXVECTOR3::D3DXVECTOR3()
|
---|
136 | {
|
---|
137 | }
|
---|
138 |
|
---|
139 | inline D3DXVECTOR3::D3DXVECTOR3(CONST FLOAT *pf)
|
---|
140 | {
|
---|
141 | if(!pf) return;
|
---|
142 | x = pf[0];
|
---|
143 | y = pf[1];
|
---|
144 | z = pf[2];
|
---|
145 | }
|
---|
146 |
|
---|
147 | inline D3DXVECTOR3::D3DXVECTOR3(CONST D3DVECTOR& v)
|
---|
148 | {
|
---|
149 | x = v.x;
|
---|
150 | y = v.y;
|
---|
151 | z = v.z;
|
---|
152 | }
|
---|
153 |
|
---|
154 | inline D3DXVECTOR3::D3DXVECTOR3(FLOAT fx, FLOAT fy, FLOAT fz)
|
---|
155 | {
|
---|
156 | x = fx;
|
---|
157 | y = fy;
|
---|
158 | z = fz;
|
---|
159 | }
|
---|
160 |
|
---|
161 | inline D3DXVECTOR3::operator FLOAT* ()
|
---|
162 | {
|
---|
163 | return (FLOAT*)&x;
|
---|
164 | }
|
---|
165 |
|
---|
166 | inline D3DXVECTOR3::operator CONST FLOAT* () const
|
---|
167 | {
|
---|
168 | return (CONST FLOAT*)&x;
|
---|
169 | }
|
---|
170 |
|
---|
171 | inline D3DXVECTOR3& D3DXVECTOR3::operator += (CONST D3DXVECTOR3& v)
|
---|
172 | {
|
---|
173 | x += v.x;
|
---|
174 | y += v.y;
|
---|
175 | z += v.z;
|
---|
176 | return *this;
|
---|
177 | }
|
---|
178 |
|
---|
179 | inline D3DXVECTOR3& D3DXVECTOR3::operator -= (CONST D3DXVECTOR3& v)
|
---|
180 | {
|
---|
181 | x -= v.x;
|
---|
182 | y -= v.y;
|
---|
183 | z -= v.z;
|
---|
184 | return *this;
|
---|
185 | }
|
---|
186 |
|
---|
187 | inline D3DXVECTOR3& D3DXVECTOR3::operator *= (FLOAT f)
|
---|
188 | {
|
---|
189 | x *= f;
|
---|
190 | y *= f;
|
---|
191 | z *= f;
|
---|
192 | return *this;
|
---|
193 | }
|
---|
194 |
|
---|
195 | inline D3DXVECTOR3& D3DXVECTOR3::operator /= (FLOAT f)
|
---|
196 | {
|
---|
197 | x /= f;
|
---|
198 | y /= f;
|
---|
199 | z /= f;
|
---|
200 | return *this;
|
---|
201 | }
|
---|
202 |
|
---|
203 | inline D3DXVECTOR3 D3DXVECTOR3::operator + () const
|
---|
204 | {
|
---|
205 | return *this;
|
---|
206 | }
|
---|
207 |
|
---|
208 | inline D3DXVECTOR3 D3DXVECTOR3::operator - () const
|
---|
209 | {
|
---|
210 | return D3DXVECTOR3(-x, -y, -z);
|
---|
211 | }
|
---|
212 |
|
---|
213 | inline D3DXVECTOR3 D3DXVECTOR3::operator + (CONST D3DXVECTOR3& v) const
|
---|
214 | {
|
---|
215 | return D3DXVECTOR3(x + v.x, y + v.y, z + v.z);
|
---|
216 | }
|
---|
217 |
|
---|
218 | inline D3DXVECTOR3 D3DXVECTOR3::operator - (CONST D3DXVECTOR3& v) const
|
---|
219 | {
|
---|
220 | return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
|
---|
221 | }
|
---|
222 |
|
---|
223 | inline D3DXVECTOR3 D3DXVECTOR3::operator * (FLOAT f) const
|
---|
224 | {
|
---|
225 | return D3DXVECTOR3(x * f, y * f, z * f);
|
---|
226 | }
|
---|
227 |
|
---|
228 | inline D3DXVECTOR3 D3DXVECTOR3::operator / (FLOAT f) const
|
---|
229 | {
|
---|
230 | return D3DXVECTOR3(x / f, y / f, z / f);
|
---|
231 | }
|
---|
232 |
|
---|
233 | inline D3DXVECTOR3 operator * (FLOAT f, CONST D3DXVECTOR3& v)
|
---|
234 | {
|
---|
235 | return D3DXVECTOR3(f * v.x, f * v.y, f * v.z);
|
---|
236 | }
|
---|
237 |
|
---|
238 | inline BOOL D3DXVECTOR3::operator == (CONST D3DXVECTOR3& v) const
|
---|
239 | {
|
---|
240 | return x == v.x && y == v.y && z == v.z;
|
---|
241 | }
|
---|
242 |
|
---|
243 | inline BOOL D3DXVECTOR3::operator != (CONST D3DXVECTOR3& v) const
|
---|
244 | {
|
---|
245 | return x != v.x || y != v.y || z != v.z;
|
---|
246 | }
|
---|
247 |
|
---|
248 | inline D3DXVECTOR4::D3DXVECTOR4()
|
---|
249 | {
|
---|
250 | }
|
---|
251 |
|
---|
252 | inline D3DXVECTOR4::D3DXVECTOR4(CONST FLOAT *pf)
|
---|
253 | {
|
---|
254 | if(!pf) return;
|
---|
255 | x = pf[0];
|
---|
256 | y = pf[1];
|
---|
257 | z = pf[2];
|
---|
258 | w = pf[3];
|
---|
259 | }
|
---|
260 |
|
---|
261 | inline D3DXVECTOR4::D3DXVECTOR4(FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw)
|
---|
262 | {
|
---|
263 | x = fx;
|
---|
264 | y = fy;
|
---|
265 | z = fz;
|
---|
266 | w = fw;
|
---|
267 | }
|
---|
268 |
|
---|
269 | inline D3DXVECTOR4::operator FLOAT* ()
|
---|
270 | {
|
---|
271 | return (FLOAT*)&x;
|
---|
272 | }
|
---|
273 |
|
---|
274 | inline D3DXVECTOR4::operator CONST FLOAT* () const
|
---|
275 | {
|
---|
276 | return (CONST FLOAT*)&x;
|
---|
277 | }
|
---|
278 |
|
---|
279 | inline D3DXVECTOR4& D3DXVECTOR4::operator += (CONST D3DXVECTOR4& v)
|
---|
280 | {
|
---|
281 | x += v.x;
|
---|
282 | y += v.y;
|
---|
283 | z += v.z;
|
---|
284 | w += v.w;
|
---|
285 | return *this;
|
---|
286 | }
|
---|
287 |
|
---|
288 | inline D3DXVECTOR4& D3DXVECTOR4::operator -= (CONST D3DXVECTOR4& v)
|
---|
289 | {
|
---|
290 | x -= v.x;
|
---|
291 | y -= v.y;
|
---|
292 | z -= v.z;
|
---|
293 | w -= v.w;
|
---|
294 | return *this;
|
---|
295 | }
|
---|
296 |
|
---|
297 | inline D3DXVECTOR4& D3DXVECTOR4::operator *= (FLOAT f)
|
---|
298 | {
|
---|
299 | x *= f;
|
---|
300 | y *= f;
|
---|
301 | z *= f;
|
---|
302 | w *= f;
|
---|
303 | return *this;
|
---|
304 | }
|
---|
305 |
|
---|
306 | inline D3DXVECTOR4& D3DXVECTOR4::operator /= (FLOAT f)
|
---|
307 | {
|
---|
308 | x /= f;
|
---|
309 | y /= f;
|
---|
310 | z /= f;
|
---|
311 | w /= f;
|
---|
312 | return *this;
|
---|
313 | }
|
---|
314 |
|
---|
315 | inline D3DXVECTOR4 D3DXVECTOR4::operator + () const
|
---|
316 | {
|
---|
317 | return *this;
|
---|
318 | }
|
---|
319 |
|
---|
320 | inline D3DXVECTOR4 D3DXVECTOR4::operator - () const
|
---|
321 | {
|
---|
322 | return D3DXVECTOR4(-x, -y, -z, -w);
|
---|
323 | }
|
---|
324 |
|
---|
325 | inline D3DXVECTOR4 D3DXVECTOR4::operator + (CONST D3DXVECTOR4& v) const
|
---|
326 | {
|
---|
327 | return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w);
|
---|
328 | }
|
---|
329 |
|
---|
330 | inline D3DXVECTOR4 D3DXVECTOR4::operator - (CONST D3DXVECTOR4& v) const
|
---|
331 | {
|
---|
332 | return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w);
|
---|
333 | }
|
---|
334 |
|
---|
335 | inline D3DXVECTOR4 D3DXVECTOR4::operator * (FLOAT f) const
|
---|
336 | {
|
---|
337 | return D3DXVECTOR4(x * f, y * f, z * f, w * f);
|
---|
338 | }
|
---|
339 |
|
---|
340 | inline D3DXVECTOR4 D3DXVECTOR4::operator / (FLOAT f) const
|
---|
341 | {
|
---|
342 | return D3DXVECTOR4(x / f, y / f, z / f, w / f);
|
---|
343 | }
|
---|
344 |
|
---|
345 | inline D3DXVECTOR4 operator * (FLOAT f, CONST D3DXVECTOR4& v)
|
---|
346 | {
|
---|
347 | return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w);
|
---|
348 | }
|
---|
349 |
|
---|
350 | inline BOOL D3DXVECTOR4::operator == (CONST D3DXVECTOR4& v) const
|
---|
351 | {
|
---|
352 | return x == v.x && y == v.y && z == v.z && w == v.w;
|
---|
353 | }
|
---|
354 |
|
---|
355 | inline BOOL D3DXVECTOR4::operator != (CONST D3DXVECTOR4& v) const
|
---|
356 | {
|
---|
357 | return x != v.x || y != v.y || z != v.z || w != v.w;
|
---|
358 | }
|
---|
359 |
|
---|
360 | inline D3DXMATRIX::D3DXMATRIX()
|
---|
361 | {
|
---|
362 | }
|
---|
363 |
|
---|
364 | inline D3DXMATRIX::D3DXMATRIX(CONST FLOAT *pf)
|
---|
365 | {
|
---|
366 | if(!pf) return;
|
---|
367 | memcpy(&_11, pf, sizeof(D3DXMATRIX));
|
---|
368 | }
|
---|
369 |
|
---|
370 | inline D3DXMATRIX::D3DXMATRIX(CONST D3DMATRIX& mat)
|
---|
371 | {
|
---|
372 | memcpy(&_11, &mat, sizeof(D3DXMATRIX));
|
---|
373 | }
|
---|
374 |
|
---|
375 | inline D3DXMATRIX::D3DXMATRIX(FLOAT f11, FLOAT f12, FLOAT f13, FLOAT f14,
|
---|
376 | FLOAT f21, FLOAT f22, FLOAT f23, FLOAT f24,
|
---|
377 | FLOAT f31, FLOAT f32, FLOAT f33, FLOAT f34,
|
---|
378 | FLOAT f41, FLOAT f42, FLOAT f43, FLOAT f44)
|
---|
379 | {
|
---|
380 | _11 = f11; _12 = f12; _13 = f13; _14 = f14;
|
---|
381 | _21 = f21; _22 = f22; _23 = f23; _24 = f24;
|
---|
382 | _31 = f31; _32 = f32; _33 = f33; _34 = f34;
|
---|
383 | _41 = f41; _42 = f42; _43 = f43; _44 = f44;
|
---|
384 | }
|
---|
385 |
|
---|
386 | inline FLOAT& D3DXMATRIX::operator () (UINT row, UINT col)
|
---|
387 | {
|
---|
388 | return m[row][col];
|
---|
389 | }
|
---|
390 |
|
---|
391 | inline FLOAT D3DXMATRIX::operator () (UINT row, UINT col) const
|
---|
392 | {
|
---|
393 | return m[row][col];
|
---|
394 | }
|
---|
395 |
|
---|
396 | inline D3DXMATRIX::operator FLOAT* ()
|
---|
397 | {
|
---|
398 | return (FLOAT*)&_11;
|
---|
399 | }
|
---|
400 |
|
---|
401 | inline D3DXMATRIX::operator CONST FLOAT* () const
|
---|
402 | {
|
---|
403 | return (CONST FLOAT*)&_11;
|
---|
404 | }
|
---|
405 |
|
---|
406 | inline D3DXMATRIX& D3DXMATRIX::operator *= (CONST D3DXMATRIX& mat)
|
---|
407 | {
|
---|
408 | D3DXMatrixMultiply(this, this, &mat);
|
---|
409 | return *this;
|
---|
410 | }
|
---|
411 |
|
---|
412 | inline D3DXMATRIX& D3DXMATRIX::operator += (CONST D3DXMATRIX& mat)
|
---|
413 | {
|
---|
414 | _11 += mat._11; _12 += mat._12; _13 += mat._13; _14 += mat._14;
|
---|
415 | _21 += mat._21; _22 += mat._22; _23 += mat._23; _24 += mat._24;
|
---|
416 | _31 += mat._31; _32 += mat._32; _33 += mat._33; _34 += mat._34;
|
---|
417 | _41 += mat._41; _42 += mat._42; _43 += mat._43; _44 += mat._44;
|
---|
418 | return *this;
|
---|
419 | }
|
---|
420 |
|
---|
421 | inline D3DXMATRIX& D3DXMATRIX::operator -= (CONST D3DXMATRIX& mat)
|
---|
422 | {
|
---|
423 | _11 -= mat._11; _12 -= mat._12; _13 -= mat._13; _14 -= mat._14;
|
---|
424 | _21 -= mat._21; _22 -= mat._22; _23 -= mat._23; _24 -= mat._24;
|
---|
425 | _31 -= mat._31; _32 -= mat._32; _33 -= mat._33; _34 -= mat._34;
|
---|
426 | _41 -= mat._41; _42 -= mat._42; _43 -= mat._43; _44 -= mat._44;
|
---|
427 | return *this;
|
---|
428 | }
|
---|
429 |
|
---|
430 | inline D3DXMATRIX& D3DXMATRIX::operator *= (FLOAT f)
|
---|
431 | {
|
---|
432 | _11 *= f; _12 *= f; _13 *= f; _14 *= f;
|
---|
433 | _21 *= f; _22 *= f; _23 *= f; _24 *= f;
|
---|
434 | _31 *= f; _32 *= f; _33 *= f; _34 *= f;
|
---|
435 | _41 *= f; _42 *= f; _43 *= f; _44 *= f;
|
---|
436 | return *this;
|
---|
437 | }
|
---|
438 |
|
---|
439 | inline D3DXMATRIX& D3DXMATRIX::operator /= (FLOAT f)
|
---|
440 | {
|
---|
441 | FLOAT inv = 1.0f / f;
|
---|
442 | _11 *= inv; _12 *= inv; _13 *= inv; _14 *= inv;
|
---|
443 | _21 *= inv; _22 *= inv; _23 *= inv; _24 *= inv;
|
---|
444 | _31 *= inv; _32 *= inv; _33 *= inv; _34 *= inv;
|
---|
445 | _41 *= inv; _42 *= inv; _43 *= inv; _44 *= inv;
|
---|
446 | return *this;
|
---|
447 | }
|
---|
448 |
|
---|
449 | inline D3DXMATRIX D3DXMATRIX::operator + () const
|
---|
450 | {
|
---|
451 | return *this;
|
---|
452 | }
|
---|
453 |
|
---|
454 | inline D3DXMATRIX D3DXMATRIX::operator - () const
|
---|
455 | {
|
---|
456 | return D3DXMATRIX(-_11, -_12, -_13, -_14,
|
---|
457 | -_21, -_22, -_23, -_24,
|
---|
458 | -_31, -_32, -_33, -_34,
|
---|
459 | -_41, -_42, -_43, -_44);
|
---|
460 | }
|
---|
461 |
|
---|
462 | inline D3DXMATRIX D3DXMATRIX::operator * (CONST D3DXMATRIX& mat) const
|
---|
463 | {
|
---|
464 | D3DXMATRIX buf;
|
---|
465 | D3DXMatrixMultiply(&buf, this, &mat);
|
---|
466 | return buf;
|
---|
467 | }
|
---|
468 |
|
---|
469 | inline D3DXMATRIX D3DXMATRIX::operator + (CONST D3DXMATRIX& mat) const
|
---|
470 | {
|
---|
471 | return D3DXMATRIX(_11 + mat._11, _12 + mat._12, _13 + mat._13, _14 + mat._14,
|
---|
472 | _21 + mat._21, _22 + mat._22, _23 + mat._23, _24 + mat._24,
|
---|
473 | _31 + mat._31, _32 + mat._32, _33 + mat._33, _34 + mat._34,
|
---|
474 | _41 + mat._41, _42 + mat._42, _43 + mat._43, _44 + mat._44);
|
---|
475 | }
|
---|
476 |
|
---|
477 | inline D3DXMATRIX D3DXMATRIX::operator - (CONST D3DXMATRIX& mat) const
|
---|
478 | {
|
---|
479 | return D3DXMATRIX(_11 - mat._11, _12 - mat._12, _13 - mat._13, _14 - mat._14,
|
---|
480 | _21 - mat._21, _22 - mat._22, _23 - mat._23, _24 - mat._24,
|
---|
481 | _31 - mat._31, _32 - mat._32, _33 - mat._33, _34 - mat._34,
|
---|
482 | _41 - mat._41, _42 - mat._42, _43 - mat._43, _44 - mat._44);
|
---|
483 | }
|
---|
484 |
|
---|
485 | inline D3DXMATRIX D3DXMATRIX::operator * (FLOAT f) const
|
---|
486 | {
|
---|
487 | return D3DXMATRIX(_11 * f, _12 * f, _13 * f, _14 * f,
|
---|
488 | _21 * f, _22 * f, _23 * f, _24 * f,
|
---|
489 | _31 * f, _32 * f, _33 * f, _34 * f,
|
---|
490 | _41 * f, _42 * f, _43 * f, _44 * f);
|
---|
491 | }
|
---|
492 |
|
---|
493 | inline D3DXMATRIX D3DXMATRIX::operator / (FLOAT f) const
|
---|
494 | {
|
---|
495 | FLOAT inv = 1.0f / f;
|
---|
496 | return D3DXMATRIX(_11 * inv, _12 * inv, _13 * inv, _14 * inv,
|
---|
497 | _21 * inv, _22 * inv, _23 * inv, _24 * inv,
|
---|
498 | _31 * inv, _32 * inv, _33 * inv, _34 * inv,
|
---|
499 | _41 * inv, _42 * inv, _43 * inv, _44 * inv);
|
---|
500 | }
|
---|
501 |
|
---|
502 | inline D3DXMATRIX operator * (FLOAT f, CONST D3DXMATRIX& mat)
|
---|
503 | {
|
---|
504 | return D3DXMATRIX(f * mat._11, f * mat._12, f * mat._13, f * mat._14,
|
---|
505 | f * mat._21, f * mat._22, f * mat._23, f * mat._24,
|
---|
506 | f * mat._31, f * mat._32, f * mat._33, f * mat._34,
|
---|
507 | f * mat._41, f * mat._42, f * mat._43, f * mat._44);
|
---|
508 | }
|
---|
509 |
|
---|
510 | inline BOOL D3DXMATRIX::operator == (CONST D3DXMATRIX& mat) const
|
---|
511 | {
|
---|
512 | return (memcmp(this, &mat, sizeof(D3DXMATRIX)) == 0);
|
---|
513 | }
|
---|
514 |
|
---|
515 | inline BOOL D3DXMATRIX::operator != (CONST D3DXMATRIX& mat) const
|
---|
516 | {
|
---|
517 | return (memcmp(this, &mat, sizeof(D3DXMATRIX)) != 0);
|
---|
518 | }
|
---|
519 |
|
---|
520 | inline D3DXQUATERNION::D3DXQUATERNION()
|
---|
521 | {
|
---|
522 | }
|
---|
523 |
|
---|
524 | inline D3DXQUATERNION::D3DXQUATERNION(CONST FLOAT *pf)
|
---|
525 | {
|
---|
526 | if(!pf) return;
|
---|
527 | x = pf[0];
|
---|
528 | y = pf[1];
|
---|
529 | z = pf[2];
|
---|
530 | w = pf[3];
|
---|
531 | }
|
---|
532 |
|
---|
533 | inline D3DXQUATERNION::D3DXQUATERNION(FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw)
|
---|
534 | {
|
---|
535 | x = fx;
|
---|
536 | y = fy;
|
---|
537 | z = fz;
|
---|
538 | w = fw;
|
---|
539 | }
|
---|
540 |
|
---|
541 | inline D3DXQUATERNION::operator FLOAT* ()
|
---|
542 | {
|
---|
543 | return (FLOAT*)&x;
|
---|
544 | }
|
---|
545 |
|
---|
546 | inline D3DXQUATERNION::operator CONST FLOAT* () const
|
---|
547 | {
|
---|
548 | return (CONST FLOAT*)&x;
|
---|
549 | }
|
---|
550 |
|
---|
551 | inline D3DXQUATERNION& D3DXQUATERNION::operator += (CONST D3DXQUATERNION& quat)
|
---|
552 | {
|
---|
553 | x += quat.x;
|
---|
554 | y += quat.y;
|
---|
555 | z += quat.z;
|
---|
556 | w += quat.w;
|
---|
557 | return *this;
|
---|
558 | }
|
---|
559 |
|
---|
560 | inline D3DXQUATERNION& D3DXQUATERNION::operator -= (CONST D3DXQUATERNION& quat)
|
---|
561 | {
|
---|
562 | x -= quat.x;
|
---|
563 | y -= quat.y;
|
---|
564 | z -= quat.z;
|
---|
565 | w -= quat.w;
|
---|
566 | return *this;
|
---|
567 | }
|
---|
568 |
|
---|
569 | /* TODO: uncomment this when D3DXQuaternionMultiply has been implemented
|
---|
570 | inline D3DXQUATERNION& D3DXQUATERNION::operator *= (CONST D3DXQUATERNION& quat)
|
---|
571 | {
|
---|
572 | D3DXQuaternionMultiply(this, this, &quat);
|
---|
573 | return *this;
|
---|
574 | }
|
---|
575 | */
|
---|
576 |
|
---|
577 | inline D3DXQUATERNION& D3DXQUATERNION::operator *= (FLOAT f)
|
---|
578 | {
|
---|
579 | x *= f;
|
---|
580 | y *= f;
|
---|
581 | z *= f;
|
---|
582 | w *= f;
|
---|
583 | return *this;
|
---|
584 | }
|
---|
585 |
|
---|
586 | inline D3DXQUATERNION& D3DXQUATERNION::operator /= (FLOAT f)
|
---|
587 | {
|
---|
588 | FLOAT inv = 1.0f / f;
|
---|
589 | x *= inv;
|
---|
590 | y *= inv;
|
---|
591 | z *= inv;
|
---|
592 | w *= inv;
|
---|
593 | return *this;
|
---|
594 | }
|
---|
595 |
|
---|
596 | inline D3DXQUATERNION D3DXQUATERNION::operator + () const
|
---|
597 | {
|
---|
598 | return *this;
|
---|
599 | }
|
---|
600 |
|
---|
601 | inline D3DXQUATERNION D3DXQUATERNION::operator - () const
|
---|
602 | {
|
---|
603 | return D3DXQUATERNION(-x, -y, -z, -w);
|
---|
604 | }
|
---|
605 |
|
---|
606 | inline D3DXQUATERNION D3DXQUATERNION::operator + (CONST D3DXQUATERNION& quat) const
|
---|
607 | {
|
---|
608 | return D3DXQUATERNION(x + quat.x, y + quat.y, z + quat.z, w + quat.w);
|
---|
609 | }
|
---|
610 |
|
---|
611 | inline D3DXQUATERNION D3DXQUATERNION::operator - (CONST D3DXQUATERNION& quat) const
|
---|
612 | {
|
---|
613 | return D3DXQUATERNION(x - quat.x, y - quat.y, z - quat.z, w - quat.w);
|
---|
614 | }
|
---|
615 |
|
---|
616 | /* TODO: uncomment this when D3DXQuaternionMultiply has been implemented
|
---|
617 | inline D3DXQUATERNION D3DXQUATERNION::operator * (CONST D3DXQUATERNION& quat) const
|
---|
618 | {
|
---|
619 | D3DXQUATERNION buf;
|
---|
620 | D3DXQuaternionMultiply(&buf, this, &quat);
|
---|
621 | return buf;
|
---|
622 | }
|
---|
623 | */
|
---|
624 |
|
---|
625 | inline D3DXQUATERNION D3DXQUATERNION::operator * (FLOAT f) const
|
---|
626 | {
|
---|
627 | return D3DXQUATERNION(x * f, y * f, z * f, w * f);
|
---|
628 | }
|
---|
629 |
|
---|
630 | inline D3DXQUATERNION D3DXQUATERNION::operator / (FLOAT f) const
|
---|
631 | {
|
---|
632 | FLOAT inv = 1.0f / f;
|
---|
633 | return D3DXQUATERNION(x * inv, y * inv, z * inv, w * inv);
|
---|
634 | }
|
---|
635 |
|
---|
636 | inline D3DXQUATERNION operator * (FLOAT f, CONST D3DXQUATERNION& quat)
|
---|
637 | {
|
---|
638 | return D3DXQUATERNION(f * quat.x, f * quat.y, f * quat.z, f * quat.w);
|
---|
639 | }
|
---|
640 |
|
---|
641 | inline BOOL D3DXQUATERNION::operator == (CONST D3DXQUATERNION& quat) const
|
---|
642 | {
|
---|
643 | return x == quat.x && y == quat.y && z == quat.z && w == quat.w;
|
---|
644 | }
|
---|
645 |
|
---|
646 | inline BOOL D3DXQUATERNION::operator != (CONST D3DXQUATERNION& quat) const
|
---|
647 | {
|
---|
648 | return x != quat.x || y != quat.y || z != quat.z || w != quat.w;
|
---|
649 | }
|
---|
650 |
|
---|
651 | inline D3DXPLANE::D3DXPLANE()
|
---|
652 | {
|
---|
653 | }
|
---|
654 |
|
---|
655 | inline D3DXPLANE::D3DXPLANE(CONST FLOAT *pf)
|
---|
656 | {
|
---|
657 | if(!pf) return;
|
---|
658 | a = pf[0];
|
---|
659 | b = pf[1];
|
---|
660 | c = pf[2];
|
---|
661 | d = pf[3];
|
---|
662 | }
|
---|
663 |
|
---|
664 | inline D3DXPLANE::D3DXPLANE(FLOAT fa, FLOAT fb, FLOAT fc, FLOAT fd)
|
---|
665 | {
|
---|
666 | a = fa;
|
---|
667 | b = fb;
|
---|
668 | c = fc;
|
---|
669 | d = fd;
|
---|
670 | }
|
---|
671 |
|
---|
672 | inline D3DXPLANE::operator FLOAT* ()
|
---|
673 | {
|
---|
674 | return (FLOAT*)&a;
|
---|
675 | }
|
---|
676 |
|
---|
677 | inline D3DXPLANE::operator CONST FLOAT* () const
|
---|
678 | {
|
---|
679 | return (CONST FLOAT*)&a;
|
---|
680 | }
|
---|
681 |
|
---|
682 | inline D3DXPLANE D3DXPLANE::operator + () const
|
---|
683 | {
|
---|
684 | return *this;
|
---|
685 | }
|
---|
686 |
|
---|
687 | inline D3DXPLANE D3DXPLANE::operator - () const
|
---|
688 | {
|
---|
689 | return D3DXPLANE(-a, -b, -c, -d);
|
---|
690 | }
|
---|
691 |
|
---|
692 | inline BOOL D3DXPLANE::operator == (CONST D3DXPLANE& pl) const
|
---|
693 | {
|
---|
694 | return a == pl.a && b == pl.b && c == pl.c && d == pl.d;
|
---|
695 | }
|
---|
696 |
|
---|
697 | inline BOOL D3DXPLANE::operator != (CONST D3DXPLANE& pl) const
|
---|
698 | {
|
---|
699 | return a != pl.a || b != pl.b || c != pl.c || d != pl.d;
|
---|
700 | }
|
---|
701 |
|
---|
702 | inline D3DXCOLOR::D3DXCOLOR()
|
---|
703 | {
|
---|
704 | }
|
---|
705 |
|
---|
706 | inline D3DXCOLOR::D3DXCOLOR(DWORD col)
|
---|
707 | {
|
---|
708 | CONST FLOAT f = 1.0f / 255.0f;
|
---|
709 | r = f * (FLOAT)(unsigned char)(col >> 16);
|
---|
710 | g = f * (FLOAT)(unsigned char)(col >> 8);
|
---|
711 | b = f * (FLOAT)(unsigned char)col;
|
---|
712 | a = f * (FLOAT)(unsigned char)(col >> 24);
|
---|
713 | }
|
---|
714 |
|
---|
715 | inline D3DXCOLOR::D3DXCOLOR(CONST FLOAT *pf)
|
---|
716 | {
|
---|
717 | if(!pf) return;
|
---|
718 | r = pf[0];
|
---|
719 | g = pf[1];
|
---|
720 | b = pf[2];
|
---|
721 | a = pf[3];
|
---|
722 | }
|
---|
723 |
|
---|
724 | inline D3DXCOLOR::D3DXCOLOR(CONST D3DCOLORVALUE& col)
|
---|
725 | {
|
---|
726 | r = col.r;
|
---|
727 | g = col.g;
|
---|
728 | b = col.b;
|
---|
729 | a = col.a;
|
---|
730 | }
|
---|
731 |
|
---|
732 | inline D3DXCOLOR::D3DXCOLOR(FLOAT fr, FLOAT fg, FLOAT fb, FLOAT fa)
|
---|
733 | {
|
---|
734 | r = fr;
|
---|
735 | g = fg;
|
---|
736 | b = fb;
|
---|
737 | a = fa;
|
---|
738 | }
|
---|
739 |
|
---|
740 | inline D3DXCOLOR::operator DWORD () const
|
---|
741 | {
|
---|
742 | DWORD _r = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD)(r * 255.0f + 0.5f);
|
---|
743 | DWORD _g = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD)(g * 255.0f + 0.5f);
|
---|
744 | DWORD _b = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD)(b * 255.0f + 0.5f);
|
---|
745 | DWORD _a = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD)(a * 255.0f + 0.5f);
|
---|
746 |
|
---|
747 | return (_a << 24) | (_r << 16) | (_g << 8) | _b;
|
---|
748 | }
|
---|
749 |
|
---|
750 | inline D3DXCOLOR::operator FLOAT * ()
|
---|
751 | {
|
---|
752 | return (FLOAT*)&r;
|
---|
753 | }
|
---|
754 |
|
---|
755 | inline D3DXCOLOR::operator CONST FLOAT * () const
|
---|
756 | {
|
---|
757 | return (CONST FLOAT*)&r;
|
---|
758 | }
|
---|
759 |
|
---|
760 | inline D3DXCOLOR::operator D3DCOLORVALUE * ()
|
---|
761 | {
|
---|
762 | return (D3DCOLORVALUE*)&r;
|
---|
763 | }
|
---|
764 |
|
---|
765 | inline D3DXCOLOR::operator CONST D3DCOLORVALUE * () const
|
---|
766 | {
|
---|
767 | return (CONST D3DCOLORVALUE*)&r;
|
---|
768 | }
|
---|
769 |
|
---|
770 | inline D3DXCOLOR::operator D3DCOLORVALUE& ()
|
---|
771 | {
|
---|
772 | return *((D3DCOLORVALUE*)&r);
|
---|
773 | }
|
---|
774 |
|
---|
775 | inline D3DXCOLOR::operator CONST D3DCOLORVALUE& () const
|
---|
776 | {
|
---|
777 | return *((CONST D3DCOLORVALUE*)&r);
|
---|
778 | }
|
---|
779 |
|
---|
780 | inline D3DXCOLOR& D3DXCOLOR::operator += (CONST D3DXCOLOR& col)
|
---|
781 | {
|
---|
782 | r += col.r;
|
---|
783 | g += col.g;
|
---|
784 | b += col.b;
|
---|
785 | a += col.a;
|
---|
786 | return *this;
|
---|
787 | }
|
---|
788 |
|
---|
789 | inline D3DXCOLOR& D3DXCOLOR::operator -= (CONST D3DXCOLOR& col)
|
---|
790 | {
|
---|
791 | r -= col.r;
|
---|
792 | g -= col.g;
|
---|
793 | b -= col.b;
|
---|
794 | a -= col.a;
|
---|
795 | return *this;
|
---|
796 | }
|
---|
797 |
|
---|
798 | inline D3DXCOLOR& D3DXCOLOR::operator *= (FLOAT f)
|
---|
799 | {
|
---|
800 | r *= f;
|
---|
801 | g *= f;
|
---|
802 | b *= f;
|
---|
803 | a *= f;
|
---|
804 | return *this;
|
---|
805 | }
|
---|
806 |
|
---|
807 | inline D3DXCOLOR& D3DXCOLOR::operator /= (FLOAT f)
|
---|
808 | {
|
---|
809 | FLOAT inv = 1.0f / f;
|
---|
810 | r *= inv;
|
---|
811 | g *= inv;
|
---|
812 | b *= inv;
|
---|
813 | a *= inv;
|
---|
814 | return *this;
|
---|
815 | }
|
---|
816 |
|
---|
817 | inline D3DXCOLOR D3DXCOLOR::operator + () const
|
---|
818 | {
|
---|
819 | return *this;
|
---|
820 | }
|
---|
821 |
|
---|
822 | inline D3DXCOLOR D3DXCOLOR::operator - () const
|
---|
823 | {
|
---|
824 | return D3DXCOLOR(-r, -g, -b, -a);
|
---|
825 | }
|
---|
826 |
|
---|
827 | inline D3DXCOLOR D3DXCOLOR::operator + (CONST D3DXCOLOR& col) const
|
---|
828 | {
|
---|
829 | return D3DXCOLOR(r + col.r, g + col.g, b + col.b, a + col.a);
|
---|
830 | }
|
---|
831 |
|
---|
832 | inline D3DXCOLOR D3DXCOLOR::operator - (CONST D3DXCOLOR& col) const
|
---|
833 | {
|
---|
834 | return D3DXCOLOR(r - col.r, g - col.g, b - col.b, a - col.a);
|
---|
835 | }
|
---|
836 |
|
---|
837 | inline D3DXCOLOR D3DXCOLOR::operator * (FLOAT f) const
|
---|
838 | {
|
---|
839 | return D3DXCOLOR(r * f, g * f, b * f, a * f);
|
---|
840 | }
|
---|
841 |
|
---|
842 | inline D3DXCOLOR D3DXCOLOR::operator / (FLOAT f) const
|
---|
843 | {
|
---|
844 | FLOAT inv = 1.0f / f;
|
---|
845 | return D3DXCOLOR(r * inv, g * inv, b * inv, a * inv);
|
---|
846 | }
|
---|
847 |
|
---|
848 | inline D3DXCOLOR operator * (FLOAT f, CONST D3DXCOLOR& col)
|
---|
849 | {
|
---|
850 | return D3DXCOLOR(f * col.r, f * col.g, f * col.b, f * col.a);
|
---|
851 | }
|
---|
852 |
|
---|
853 | inline BOOL D3DXCOLOR::operator == (CONST D3DXCOLOR& col) const
|
---|
854 | {
|
---|
855 | return r == col.r && g == col.g && b == col.b && a == col.a;
|
---|
856 | }
|
---|
857 |
|
---|
858 | inline BOOL D3DXCOLOR::operator != (CONST D3DXCOLOR& col) const
|
---|
859 | {
|
---|
860 | return r != col.r || g != col.g || b != col.b || a != col.a;
|
---|
861 | }
|
---|
862 |
|
---|
863 | #endif /* __cplusplus */
|
---|
864 |
|
---|
865 | /*_______________D3DXCOLOR_____________________*/
|
---|
866 |
|
---|
867 | static inline D3DXCOLOR* D3DXColorAdd(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
---|
868 | {
|
---|
869 | if ( !pout || !pc1 || !pc2 ) return NULL;
|
---|
870 | pout->r = (pc1->r) + (pc2->r);
|
---|
871 | pout->g = (pc1->g) + (pc2->g);
|
---|
872 | pout->b = (pc1->b) + (pc2->b);
|
---|
873 | pout->a = (pc1->a) + (pc2->a);
|
---|
874 | return pout;
|
---|
875 | }
|
---|
876 |
|
---|
877 | static inline D3DXCOLOR* D3DXColorLerp(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2, FLOAT s)
|
---|
878 | {
|
---|
879 | if ( !pout || !pc1 || !pc2 ) return NULL;
|
---|
880 | pout->r = (1-s) * (pc1->r) + s *(pc2->r);
|
---|
881 | pout->g = (1-s) * (pc1->g) + s *(pc2->g);
|
---|
882 | pout->b = (1-s) * (pc1->b) + s *(pc2->b);
|
---|
883 | pout->a = (1-s) * (pc1->a) + s *(pc2->a);
|
---|
884 | return pout;
|
---|
885 | }
|
---|
886 |
|
---|
887 | static inline D3DXCOLOR* D3DXColorModulate(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
---|
888 | {
|
---|
889 | if ( !pout || !pc1 || !pc2 ) return NULL;
|
---|
890 | pout->r = (pc1->r) * (pc2->r);
|
---|
891 | pout->g = (pc1->g) * (pc2->g);
|
---|
892 | pout->b = (pc1->b) * (pc2->b);
|
---|
893 | pout->a = (pc1->a) * (pc2->a);
|
---|
894 | return pout;
|
---|
895 | }
|
---|
896 |
|
---|
897 | static inline D3DXCOLOR* D3DXColorNegative(D3DXCOLOR *pout, CONST D3DXCOLOR *pc)
|
---|
898 | {
|
---|
899 | if ( !pout || !pc ) return NULL;
|
---|
900 | pout->r = 1.0f - pc->r;
|
---|
901 | pout->g = 1.0f - pc->g;
|
---|
902 | pout->b = 1.0f - pc->b;
|
---|
903 | pout->a = pc->a;
|
---|
904 | return pout;
|
---|
905 | }
|
---|
906 |
|
---|
907 | static inline D3DXCOLOR* D3DXColorScale(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s)
|
---|
908 | {
|
---|
909 | if ( !pout || !pc ) return NULL;
|
---|
910 | pout->r = s* (pc->r);
|
---|
911 | pout->g = s* (pc->g);
|
---|
912 | pout->b = s* (pc->b);
|
---|
913 | pout->a = s* (pc->a);
|
---|
914 | return pout;
|
---|
915 | }
|
---|
916 |
|
---|
917 | static inline D3DXCOLOR* D3DXColorSubtract(D3DXCOLOR *pout, CONST D3DXCOLOR *pc1, CONST D3DXCOLOR *pc2)
|
---|
918 | {
|
---|
919 | if ( !pout || !pc1 || !pc2 ) return NULL;
|
---|
920 | pout->r = (pc1->r) - (pc2->r);
|
---|
921 | pout->g = (pc1->g) - (pc2->g);
|
---|
922 | pout->b = (pc1->b) - (pc2->b);
|
---|
923 | pout->a = (pc1->a) - (pc2->a);
|
---|
924 | return pout;
|
---|
925 | }
|
---|
926 |
|
---|
927 | /*_______________D3DXVECTOR2________________________*/
|
---|
928 |
|
---|
929 | static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
930 | {
|
---|
931 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
932 | pout->x = pv1->x + pv2->x;
|
---|
933 | pout->y = pv1->y + pv2->y;
|
---|
934 | return pout;
|
---|
935 | }
|
---|
936 |
|
---|
937 | static inline FLOAT D3DXVec2CCW(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
938 | {
|
---|
939 | if ( !pv1 || !pv2) return 0.0f;
|
---|
940 | return ( (pv1->x) * (pv2->y) - (pv1->y) * (pv2->x) );
|
---|
941 | }
|
---|
942 |
|
---|
943 | static inline FLOAT D3DXVec2Dot(CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
944 | {
|
---|
945 | if ( !pv1 || !pv2) return 0.0f;
|
---|
946 | return ( (pv1->x * pv2->x + pv1->y * pv2->y) );
|
---|
947 | }
|
---|
948 |
|
---|
949 | static inline FLOAT D3DXVec2Length(CONST D3DXVECTOR2 *pv)
|
---|
950 | {
|
---|
951 | if (!pv) return 0.0f;
|
---|
952 | return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
|
---|
953 | }
|
---|
954 |
|
---|
955 | static inline FLOAT D3DXVec2LengthSq(CONST D3DXVECTOR2 *pv)
|
---|
956 | {
|
---|
957 | if (!pv) return 0.0f;
|
---|
958 | return( (pv->x) * (pv->x) + (pv->y) * (pv->y) );
|
---|
959 | }
|
---|
960 |
|
---|
961 | static inline D3DXVECTOR2* D3DXVec2Lerp(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, FLOAT s)
|
---|
962 | {
|
---|
963 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
964 | pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
---|
965 | pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
---|
966 | return pout;
|
---|
967 | }
|
---|
968 |
|
---|
969 | static inline D3DXVECTOR2* D3DXVec2Maximize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
970 | {
|
---|
971 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
972 | pout->x = max(pv1->x , pv2->x);
|
---|
973 | pout->y = max(pv1->y , pv2->y);
|
---|
974 | return pout;
|
---|
975 | }
|
---|
976 |
|
---|
977 | static inline D3DXVECTOR2* D3DXVec2Minimize(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
978 | {
|
---|
979 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
980 | pout->x = min(pv1->x , pv2->x);
|
---|
981 | pout->y = min(pv1->y , pv2->y);
|
---|
982 | return pout;
|
---|
983 | }
|
---|
984 |
|
---|
985 | static inline D3DXVECTOR2* D3DXVec2Scale(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv, FLOAT s)
|
---|
986 | {
|
---|
987 | if ( !pout || !pv) return NULL;
|
---|
988 | pout->x = s * (pv->x);
|
---|
989 | pout->y = s * (pv->y);
|
---|
990 | return pout;
|
---|
991 | }
|
---|
992 |
|
---|
993 | static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
|
---|
994 | {
|
---|
995 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
996 | pout->x = pv1->x - pv2->x;
|
---|
997 | pout->y = pv1->y - pv2->y;
|
---|
998 | return pout;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | /*__________________D3DXVECTOR3_______________________*/
|
---|
1002 |
|
---|
1003 | static inline D3DXVECTOR3* D3DXVec3Add(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1004 | {
|
---|
1005 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1006 | pout->x = pv1->x + pv2->x;
|
---|
1007 | pout->y = pv1->y + pv2->y;
|
---|
1008 | pout->z = pv1->z + pv2->z;
|
---|
1009 | return pout;
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | static inline D3DXVECTOR3* D3DXVec3Cross(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1013 | {
|
---|
1014 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1015 | pout->x = (pv1->y) * (pv2->z) - (pv1->z) * (pv2->y);
|
---|
1016 | pout->y = (pv1->z) * (pv2->x) - (pv1->x) * (pv2->z);
|
---|
1017 | pout->z = (pv1->x) * (pv2->y) - (pv1->y) * (pv2->x);
|
---|
1018 | return pout;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | static inline FLOAT D3DXVec3Dot(CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1022 | {
|
---|
1023 | if ( !pv1 || !pv2 ) return 0.0f;
|
---|
1024 | return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z);
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv)
|
---|
1028 | {
|
---|
1029 | if (!pv) return 0.0f;
|
---|
1030 | return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) );
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 *pv)
|
---|
1034 | {
|
---|
1035 | if (!pv) return 0.0f;
|
---|
1036 | return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z);
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | static inline D3DXVECTOR3* D3DXVec3Lerp(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2, FLOAT s)
|
---|
1040 | {
|
---|
1041 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1042 | pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
---|
1043 | pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
---|
1044 | pout->z = (1-s) * (pv1->z) + s * (pv2->z);
|
---|
1045 | return pout;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | static inline D3DXVECTOR3* D3DXVec3Maximize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1049 | {
|
---|
1050 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1051 | pout->x = max(pv1->x , pv2->x);
|
---|
1052 | pout->y = max(pv1->y , pv2->y);
|
---|
1053 | pout->z = max(pv1->z , pv2->z);
|
---|
1054 | return pout;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | static inline D3DXVECTOR3* D3DXVec3Minimize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1058 | {
|
---|
1059 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1060 | pout->x = min(pv1->x , pv2->x);
|
---|
1061 | pout->y = min(pv1->y , pv2->y);
|
---|
1062 | pout->z = min(pv1->z , pv2->z);
|
---|
1063 | return pout;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | static inline D3DXVECTOR3* D3DXVec3Scale(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv, FLOAT s)
|
---|
1067 | {
|
---|
1068 | if ( !pout || !pv) return NULL;
|
---|
1069 | pout->x = s * (pv->x);
|
---|
1070 | pout->y = s * (pv->y);
|
---|
1071 | pout->z = s * (pv->z);
|
---|
1072 | return pout;
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | static inline D3DXVECTOR3* D3DXVec3Subtract(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
|
---|
1076 | {
|
---|
1077 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1078 | pout->x = pv1->x - pv2->x;
|
---|
1079 | pout->y = pv1->y - pv2->y;
|
---|
1080 | pout->z = pv1->z - pv2->z;
|
---|
1081 | return pout;
|
---|
1082 | }
|
---|
1083 | /*__________________D3DXVECTOR4_______________________*/
|
---|
1084 |
|
---|
1085 | static inline D3DXVECTOR4* D3DXVec4Add(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
---|
1086 | {
|
---|
1087 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1088 | pout->x = pv1->x + pv2->x;
|
---|
1089 | pout->y = pv1->y + pv2->y;
|
---|
1090 | pout->z = pv1->z + pv2->z;
|
---|
1091 | pout->w = pv1->w + pv2->w;
|
---|
1092 | return pout;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | static inline FLOAT D3DXVec4Dot(CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
---|
1096 | {
|
---|
1097 | if (!pv1 || !pv2 ) return 0.0f;
|
---|
1098 | return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z) + (pv1->w) * (pv2->w);
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
|
---|
1102 | {
|
---|
1103 | if (!pv) return 0.0f;
|
---|
1104 | return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w) );
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | static inline FLOAT D3DXVec4LengthSq(CONST D3DXVECTOR4 *pv)
|
---|
1108 | {
|
---|
1109 | if (!pv) return 0.0f;
|
---|
1110 | return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w);
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | static inline D3DXVECTOR4* D3DXVec4Lerp(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2, FLOAT s)
|
---|
1114 | {
|
---|
1115 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1116 | pout->x = (1-s) * (pv1->x) + s * (pv2->x);
|
---|
1117 | pout->y = (1-s) * (pv1->y) + s * (pv2->y);
|
---|
1118 | pout->z = (1-s) * (pv1->z) + s * (pv2->z);
|
---|
1119 | pout->w = (1-s) * (pv1->w) + s * (pv2->w);
|
---|
1120 | return pout;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 |
|
---|
1124 | static inline D3DXVECTOR4* D3DXVec4Maximize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
---|
1125 | {
|
---|
1126 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1127 | pout->x = max(pv1->x , pv2->x);
|
---|
1128 | pout->y = max(pv1->y , pv2->y);
|
---|
1129 | pout->z = max(pv1->z , pv2->z);
|
---|
1130 | pout->w = max(pv1->w , pv2->w);
|
---|
1131 | return pout;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | static inline D3DXVECTOR4* D3DXVec4Minimize(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
---|
1135 | {
|
---|
1136 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1137 | pout->x = min(pv1->x , pv2->x);
|
---|
1138 | pout->y = min(pv1->y , pv2->y);
|
---|
1139 | pout->z = min(pv1->z , pv2->z);
|
---|
1140 | pout->w = min(pv1->w , pv2->w);
|
---|
1141 | return pout;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | static inline D3DXVECTOR4* D3DXVec4Scale(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv, FLOAT s)
|
---|
1145 | {
|
---|
1146 | if ( !pout || !pv) return NULL;
|
---|
1147 | pout->x = s * (pv->x);
|
---|
1148 | pout->y = s * (pv->y);
|
---|
1149 | pout->z = s * (pv->z);
|
---|
1150 | pout->w = s * (pv->w);
|
---|
1151 | return pout;
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | static inline D3DXVECTOR4* D3DXVec4Subtract(D3DXVECTOR4 *pout, CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
|
---|
1155 | {
|
---|
1156 | if ( !pout || !pv1 || !pv2) return NULL;
|
---|
1157 | pout->x = pv1->x - pv2->x;
|
---|
1158 | pout->y = pv1->y - pv2->y;
|
---|
1159 | pout->z = pv1->z - pv2->z;
|
---|
1160 | pout->w = pv1->w - pv2->w;
|
---|
1161 | return pout;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | /*__________________D3DXMatrix____________________*/
|
---|
1165 | #ifdef NONAMELESSUNION
|
---|
1166 | # define D3DX_U(x) (x).u
|
---|
1167 | #else
|
---|
1168 | # define D3DX_U(x) (x)
|
---|
1169 | #endif
|
---|
1170 |
|
---|
1171 | static inline D3DXMATRIX* D3DXMatrixIdentity(D3DXMATRIX *pout)
|
---|
1172 | {
|
---|
1173 | if ( !pout ) return NULL;
|
---|
1174 | D3DX_U(*pout).m[0][1] = 0.0f;
|
---|
1175 | D3DX_U(*pout).m[0][2] = 0.0f;
|
---|
1176 | D3DX_U(*pout).m[0][3] = 0.0f;
|
---|
1177 | D3DX_U(*pout).m[1][0] = 0.0f;
|
---|
1178 | D3DX_U(*pout).m[1][2] = 0.0f;
|
---|
1179 | D3DX_U(*pout).m[1][3] = 0.0f;
|
---|
1180 | D3DX_U(*pout).m[2][0] = 0.0f;
|
---|
1181 | D3DX_U(*pout).m[2][1] = 0.0f;
|
---|
1182 | D3DX_U(*pout).m[2][3] = 0.0f;
|
---|
1183 | D3DX_U(*pout).m[3][0] = 0.0f;
|
---|
1184 | D3DX_U(*pout).m[3][1] = 0.0f;
|
---|
1185 | D3DX_U(*pout).m[3][2] = 0.0f;
|
---|
1186 | D3DX_U(*pout).m[0][0] = 1.0f;
|
---|
1187 | D3DX_U(*pout).m[1][1] = 1.0f;
|
---|
1188 | D3DX_U(*pout).m[2][2] = 1.0f;
|
---|
1189 | D3DX_U(*pout).m[3][3] = 1.0f;
|
---|
1190 | return pout;
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | static inline BOOL D3DXMatrixIsIdentity(D3DXMATRIX *pm)
|
---|
1194 | {
|
---|
1195 | int i,j;
|
---|
1196 | D3DXMATRIX testmatrix;
|
---|
1197 |
|
---|
1198 | if ( !pm ) return FALSE;
|
---|
1199 | D3DXMatrixIdentity(&testmatrix);
|
---|
1200 | for (i=0; i<4; i++)
|
---|
1201 | {
|
---|
1202 | for (j=0; j<4; j++)
|
---|
1203 | {
|
---|
1204 | if ( D3DX_U(*pm).m[i][j] != D3DX_U(testmatrix).m[i][j] ) return FALSE;
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | return TRUE;
|
---|
1208 | }
|
---|
1209 | #undef D3DX_U
|
---|
1210 |
|
---|
1211 | /*__________________D3DXPLANE____________________*/
|
---|
1212 |
|
---|
1213 | static inline FLOAT D3DXPlaneDot(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
---|
1214 | {
|
---|
1215 | if ( !pp || !pv ) return 0.0f;
|
---|
1216 | return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) + (pp->d) * (pv->w) );
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | static inline FLOAT D3DXPlaneDotCoord(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
---|
1220 | {
|
---|
1221 | if ( !pp || !pv ) return 0.0f;
|
---|
1222 | return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) + (pp->d) );
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | static inline FLOAT D3DXPlaneDotNormal(CONST D3DXPLANE *pp, CONST D3DXVECTOR4 *pv)
|
---|
1226 | {
|
---|
1227 | if ( !pp || !pv ) return 0.0f;
|
---|
1228 | return ( (pp->a) * (pv->x) + (pp->b) * (pv->y) + (pp->c) * (pv->z) );
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | /*__________________D3DXQUATERNION____________________*/
|
---|
1232 |
|
---|
1233 | static inline D3DXQUATERNION* D3DXQuaternionConjugate(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
|
---|
1234 | {
|
---|
1235 | if ( !pout || !pq) return NULL;
|
---|
1236 | pout->x = -pq->x;
|
---|
1237 | pout->y = -pq->y;
|
---|
1238 | pout->z = -pq->z;
|
---|
1239 | pout->w = pq->w;
|
---|
1240 | return pout;
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | static inline FLOAT D3DXQuaternionDot(CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2)
|
---|
1244 | {
|
---|
1245 | if ( !pq1 || !pq2 ) return 0.0f;
|
---|
1246 | return (pq1->x) * (pq2->x) + (pq1->y) * (pq2->y) + (pq1->z) * (pq2->z) + (pq1->w) * (pq2->w);
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | static inline D3DXQUATERNION* D3DXQuaternionIdentity(D3DXQUATERNION *pout)
|
---|
1250 | {
|
---|
1251 | if ( !pout) return NULL;
|
---|
1252 | pout->x = 0.0f;
|
---|
1253 | pout->y = 0.0f;
|
---|
1254 | pout->z = 0.0f;
|
---|
1255 | pout->w = 1.0f;
|
---|
1256 | return pout;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | static inline BOOL D3DXQuaternionIsIdentity(D3DXQUATERNION *pq)
|
---|
1260 | {
|
---|
1261 | if ( !pq) return FALSE;
|
---|
1262 | return ( (pq->x == 0.0f) && (pq->y == 0.0f) && (pq->z == 0.0f) && (pq->w == 1.0f) );
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | static inline FLOAT D3DXQuaternionLength(CONST D3DXQUATERNION *pq)
|
---|
1266 | {
|
---|
1267 | if (!pq) return 0.0f;
|
---|
1268 | return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w) );
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | static inline FLOAT D3DXQuaternionLengthSq(CONST D3DXQUATERNION *pq)
|
---|
1272 | {
|
---|
1273 | if (!pq) return 0.0f;
|
---|
1274 | return (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w);
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | #endif
|
---|