/[cvs]/api/include/d3dxmath.inl
ViewVC logotype

Contents of /api/include/d3dxmath.inl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:59 2001 UTC (23 years, 4 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
4 //
5 // File: d3dxmath.inl
6 // Content: D3DX math inline functions
7 //
8 //////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __D3DXMATH_INL__
11 #define __D3DXMATH_INL__
12
13
14 //===========================================================================
15 //
16 // Inline Class Methods
17 //
18 //===========================================================================
19
20 #ifdef __cplusplus
21
22 //--------------------------
23 // 2D Vector
24 //--------------------------
25
26 D3DXINLINE
27 D3DXVECTOR2::D3DXVECTOR2( const float *pf )
28 {
29 #ifdef D3DX_DEBUG
30 if(!pf)
31 return;
32 #endif
33
34 x = pf[0];
35 y = pf[1];
36 }
37
38 D3DXINLINE
39 D3DXVECTOR2::D3DXVECTOR2( float fx, float fy )
40 {
41 x = fx;
42 y = fy;
43 }
44
45 // casting
46 D3DXINLINE
47 D3DXVECTOR2::operator float* ()
48 {
49 return (float *) &x;
50 }
51
52 D3DXINLINE
53 D3DXVECTOR2::operator const float* () const
54 {
55 return (const float *) &x;
56 }
57
58 // assignment operators
59 D3DXINLINE D3DXVECTOR2&
60 D3DXVECTOR2::operator += ( const D3DXVECTOR2& v )
61 {
62 x += v.x;
63 y += v.y;
64 return *this;
65 }
66
67 D3DXINLINE D3DXVECTOR2&
68 D3DXVECTOR2::operator -= ( const D3DXVECTOR2& v )
69 {
70 x -= v.x;
71 y -= v.y;
72 return *this;
73 }
74
75 D3DXINLINE D3DXVECTOR2&
76 D3DXVECTOR2::operator *= ( float f )
77 {
78 x *= f;
79 y *= f;
80 return *this;
81 }
82
83 D3DXINLINE D3DXVECTOR2&
84 D3DXVECTOR2::operator /= ( float f )
85 {
86 float fInv = 1.0f / f;
87 x *= fInv;
88 y *= fInv;
89 return *this;
90 }
91
92 // unary operators
93 D3DXINLINE D3DXVECTOR2
94 D3DXVECTOR2::operator + () const
95 {
96 return *this;
97 }
98
99 D3DXINLINE D3DXVECTOR2
100 D3DXVECTOR2::operator - () const
101 {
102 return D3DXVECTOR2(-x, -y);
103 }
104
105 // binary operators
106 D3DXINLINE D3DXVECTOR2
107 D3DXVECTOR2::operator + ( const D3DXVECTOR2& v ) const
108 {
109 return D3DXVECTOR2(x + v.x, y + v.y);
110 }
111
112 D3DXINLINE D3DXVECTOR2
113 D3DXVECTOR2::operator - ( const D3DXVECTOR2& v ) const
114 {
115 return D3DXVECTOR2(x - v.x, y - v.y);
116 }
117
118 D3DXINLINE D3DXVECTOR2
119 D3DXVECTOR2::operator * ( float f ) const
120 {
121 return D3DXVECTOR2(x * f, y * f);
122 }
123
124 D3DXINLINE D3DXVECTOR2
125 D3DXVECTOR2::operator / ( float f ) const
126 {
127 float fInv = 1.0f / f;
128 return D3DXVECTOR2(x * fInv, y * fInv);
129 }
130
131
132 D3DXINLINE D3DXVECTOR2
133 operator * ( float f, const D3DXVECTOR2& v )
134 {
135 return D3DXVECTOR2(f * v.x, f * v.y);
136 }
137
138 D3DXINLINE BOOL
139 D3DXVECTOR2::operator == ( const D3DXVECTOR2& v ) const
140 {
141 return x == v.x && y == v.y;
142 }
143
144 D3DXINLINE BOOL
145 D3DXVECTOR2::operator != ( const D3DXVECTOR2& v ) const
146 {
147 return x != v.x || y != v.y;
148 }
149
150
151
152
153 //--------------------------
154 // 3D Vector
155 //--------------------------
156 D3DXINLINE
157 D3DXVECTOR3::D3DXVECTOR3( const float *pf )
158 {
159 #ifdef D3DX_DEBUG
160 if(!pf)
161 return;
162 #endif
163
164 x = pf[0];
165 y = pf[1];
166 z = pf[2];
167 }
168
169 D3DXINLINE
170 D3DXVECTOR3::D3DXVECTOR3( const D3DVECTOR& v )
171 {
172 x = v.x;
173 y = v.y;
174 z = v.z;
175 }
176
177 D3DXINLINE
178 D3DXVECTOR3::D3DXVECTOR3( float fx, float fy, float fz )
179 {
180 x = fx;
181 y = fy;
182 z = fz;
183 }
184
185
186 // casting
187 D3DXINLINE
188 D3DXVECTOR3::operator float* ()
189 {
190 return (float *) &x;
191 }
192
193 D3DXINLINE
194 D3DXVECTOR3::operator const float* () const
195 {
196 return (const float *) &x;
197 }
198
199
200 D3DXINLINE
201 D3DXVECTOR3::operator D3DVECTOR* ()
202 {
203 return (D3DVECTOR *) &x;
204 }
205
206 D3DXINLINE
207 D3DXVECTOR3::operator const D3DVECTOR* () const
208 {
209 return (const D3DVECTOR *) &x;
210 }
211
212
213 D3DXINLINE
214 D3DXVECTOR3::operator D3DVECTOR& ()
215 {
216 return *((D3DVECTOR *) &x);
217 }
218
219 D3DXINLINE
220 D3DXVECTOR3::operator const D3DVECTOR& () const
221 {
222 return *((const D3DVECTOR *) &x);
223 }
224
225
226 // assignment operators
227 D3DXINLINE D3DXVECTOR3&
228 D3DXVECTOR3::operator += ( const D3DXVECTOR3& v )
229 {
230 x += v.x;
231 y += v.y;
232 z += v.z;
233 return *this;
234 }
235
236 D3DXINLINE D3DXVECTOR3&
237 D3DXVECTOR3::operator -= ( const D3DXVECTOR3& v )
238 {
239 x -= v.x;
240 y -= v.y;
241 z -= v.z;
242 return *this;
243 }
244
245 D3DXINLINE D3DXVECTOR3&
246 D3DXVECTOR3::operator *= ( float f )
247 {
248 x *= f;
249 y *= f;
250 z *= f;
251 return *this;
252 }
253
254 D3DXINLINE D3DXVECTOR3&
255 D3DXVECTOR3::operator /= ( float f )
256 {
257 float fInv = 1.0f / f;
258 x *= fInv;
259 y *= fInv;
260 z *= fInv;
261 return *this;
262 }
263
264
265 // unary operators
266 D3DXINLINE D3DXVECTOR3
267 D3DXVECTOR3::operator + () const
268 {
269 return *this;
270 }
271
272 D3DXINLINE D3DXVECTOR3
273 D3DXVECTOR3::operator - () const
274 {
275 return D3DXVECTOR3(-x, -y, -z);
276 }
277
278
279 // binary operators
280 D3DXINLINE D3DXVECTOR3
281 D3DXVECTOR3::operator + ( const D3DXVECTOR3& v ) const
282 {
283 return D3DXVECTOR3(x + v.x, y + v.y, z + v.z);
284 }
285
286 D3DXINLINE D3DXVECTOR3
287 D3DXVECTOR3::operator - ( const D3DXVECTOR3& v ) const
288 {
289 return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
290 }
291
292 D3DXINLINE D3DXVECTOR3
293 D3DXVECTOR3::operator * ( float f ) const
294 {
295 return D3DXVECTOR3(x * f, y * f, z * f);
296 }
297
298 D3DXINLINE D3DXVECTOR3
299 D3DXVECTOR3::operator / ( float f ) const
300 {
301 float fInv = 1.0f / f;
302 return D3DXVECTOR3(x * fInv, y * fInv, z * fInv);
303 }
304
305
306 D3DXINLINE D3DXVECTOR3
307 operator * ( float f, const struct D3DXVECTOR3& v )
308 {
309 return D3DXVECTOR3(f * v.x, f * v.y, f * v.z);
310 }
311
312
313 D3DXINLINE BOOL
314 D3DXVECTOR3::operator == ( const D3DXVECTOR3& v ) const
315 {
316 return x == v.x && y == v.y && z == v.z;
317 }
318
319 D3DXINLINE BOOL
320 D3DXVECTOR3::operator != ( const D3DXVECTOR3& v ) const
321 {
322 return x != v.x || y != v.y || z != v.z;
323 }
324
325
326
327 //--------------------------
328 // 4D Vector
329 //--------------------------
330 D3DXINLINE
331 D3DXVECTOR4::D3DXVECTOR4( const float *pf )
332 {
333 #ifdef D3DX_DEBUG
334 if(!pf)
335 return;
336 #endif
337
338 x = pf[0];
339 y = pf[1];
340 z = pf[2];
341 w = pf[3];
342 }
343
344 D3DXINLINE
345 D3DXVECTOR4::D3DXVECTOR4( float fx, float fy, float fz, float fw )
346 {
347 x = fx;
348 y = fy;
349 z = fz;
350 w = fw;
351 }
352
353
354 // casting
355 D3DXINLINE
356 D3DXVECTOR4::operator float* ()
357 {
358 return (float *) &x;
359 }
360
361 D3DXINLINE
362 D3DXVECTOR4::operator const float* () const
363 {
364 return (const float *) &x;
365 }
366
367
368 // assignment operators
369 D3DXINLINE D3DXVECTOR4&
370 D3DXVECTOR4::operator += ( const D3DXVECTOR4& v )
371 {
372 x += v.x;
373 y += v.y;
374 z += v.z;
375 w += v.w;
376 return *this;
377 }
378
379 D3DXINLINE D3DXVECTOR4&
380 D3DXVECTOR4::operator -= ( const D3DXVECTOR4& v )
381 {
382 x -= v.x;
383 y -= v.y;
384 z -= v.z;
385 w -= v.w;
386 return *this;
387 }
388
389 D3DXINLINE D3DXVECTOR4&
390 D3DXVECTOR4::operator *= ( float f )
391 {
392 x *= f;
393 y *= f;
394 z *= f;
395 w *= f;
396 return *this;
397 }
398
399 D3DXINLINE D3DXVECTOR4&
400 D3DXVECTOR4::operator /= ( float f )
401 {
402 float fInv = 1.0f / f;
403 x *= fInv;
404 y *= fInv;
405 z *= fInv;
406 w *= fInv;
407 return *this;
408 }
409
410
411 // unary operators
412 D3DXINLINE D3DXVECTOR4
413 D3DXVECTOR4::operator + () const
414 {
415 return *this;
416 }
417
418 D3DXINLINE D3DXVECTOR4
419 D3DXVECTOR4::operator - () const
420 {
421 return D3DXVECTOR4(-x, -y, -z, -w);
422 }
423
424
425 // binary operators
426 D3DXINLINE D3DXVECTOR4
427 D3DXVECTOR4::operator + ( const D3DXVECTOR4& v ) const
428 {
429 return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w);
430 }
431
432 D3DXINLINE D3DXVECTOR4
433 D3DXVECTOR4::operator - ( const D3DXVECTOR4& v ) const
434 {
435 return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w);
436 }
437
438 D3DXINLINE D3DXVECTOR4
439 D3DXVECTOR4::operator * ( float f ) const
440 {
441 return D3DXVECTOR4(x * f, y * f, z * f, w * f);
442 }
443
444 D3DXINLINE D3DXVECTOR4
445 D3DXVECTOR4::operator / ( float f ) const
446 {
447 float fInv = 1.0f / f;
448 return D3DXVECTOR4(x * fInv, y * fInv, z * fInv, w * fInv);
449 }
450
451
452 D3DXINLINE D3DXVECTOR4
453 operator * ( float f, const D3DXVECTOR4& v )
454 {
455 return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w);
456 }
457
458
459 D3DXINLINE BOOL
460 D3DXVECTOR4::operator == ( const D3DXVECTOR4& v ) const
461 {
462 return x == v.x && y == v.y && z == v.z && w == v.w;
463 }
464
465 D3DXINLINE BOOL
466 D3DXVECTOR4::operator != ( const D3DXVECTOR4& v ) const
467 {
468 return x != v.x || y != v.y || z != v.z || w != v.w;
469 }
470
471
472 //--------------------------
473 // Matrix
474 //--------------------------
475 D3DXINLINE
476 D3DXMATRIX::D3DXMATRIX( const float* pf )
477 {
478 #ifdef D3DX_DEBUG
479 if(!pf)
480 return;
481 #endif
482
483 memcpy(&m00, pf, sizeof(D3DXMATRIX));
484 }
485
486 D3DXINLINE
487 D3DXMATRIX::D3DXMATRIX( const D3DMATRIX& mat )
488 {
489 memcpy(&m00, &mat, sizeof(D3DXMATRIX));
490 }
491
492 D3DXINLINE
493 D3DXMATRIX::D3DXMATRIX( float f00, float f01, float f02, float f03,
494 float f10, float f11, float f12, float f13,
495 float f20, float f21, float f22, float f23,
496 float f30, float f31, float f32, float f33 )
497 {
498 m00 = f00; m01 = f01; m02 = f02; m03 = f03;
499 m10 = f10; m11 = f11; m12 = f12; m13 = f13;
500 m20 = f20; m21 = f21; m22 = f22; m23 = f23;
501 m30 = f30; m31 = f31; m32 = f32; m33 = f33;
502 }
503
504
505
506 // access grants
507 D3DXINLINE float&
508 D3DXMATRIX::operator () ( UINT iRow, UINT iCol )
509 {
510 return m[iRow][iCol];
511 }
512
513 D3DXINLINE float
514 D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) const
515 {
516 return m[iRow][iCol];
517 }
518
519
520 // casting operators
521 D3DXINLINE
522 D3DXMATRIX::operator float* ()
523 {
524 return (float *) &m00;
525 }
526
527 D3DXINLINE
528 D3DXMATRIX::operator const float* () const
529 {
530 return (const float *) &m00;
531 }
532
533
534 D3DXINLINE
535 D3DXMATRIX::operator D3DMATRIX* ()
536 {
537 return (D3DMATRIX *) &m00;
538 }
539
540 D3DXINLINE
541 D3DXMATRIX::operator const D3DMATRIX* () const
542 {
543 return (const D3DMATRIX *) &m00;
544 }
545
546
547 D3DXINLINE
548 D3DXMATRIX::operator D3DMATRIX& ()
549 {
550 return *((D3DMATRIX *) &m00);
551 }
552
553 D3DXINLINE
554 D3DXMATRIX::operator const D3DMATRIX& () const
555 {
556 return *((const D3DMATRIX *) &m00);
557 }
558
559
560 // assignment operators
561 D3DXINLINE D3DXMATRIX&
562 D3DXMATRIX::operator *= ( const D3DXMATRIX& mat )
563 {
564 D3DXMatrixMultiply(this, this, &mat);
565 return *this;
566 }
567
568 D3DXINLINE D3DXMATRIX&
569 D3DXMATRIX::operator += ( const D3DXMATRIX& mat )
570 {
571 m00 += mat.m00; m01 += mat.m01; m02 += mat.m02; m03 += mat.m03;
572 m10 += mat.m10; m11 += mat.m11; m12 += mat.m12; m13 += mat.m13;
573 m20 += mat.m20; m21 += mat.m21; m22 += mat.m22; m23 += mat.m23;
574 m30 += mat.m30; m31 += mat.m31; m32 += mat.m32; m33 += mat.m33;
575 return *this;
576 }
577
578 D3DXINLINE D3DXMATRIX&
579 D3DXMATRIX::operator -= ( const D3DXMATRIX& mat )
580 {
581 m00 -= mat.m00; m01 -= mat.m01; m02 -= mat.m02; m03 -= mat.m03;
582 m10 -= mat.m10; m11 -= mat.m11; m12 -= mat.m12; m13 -= mat.m13;
583 m20 -= mat.m20; m21 -= mat.m21; m22 -= mat.m22; m23 -= mat.m23;
584 m30 -= mat.m30; m31 -= mat.m31; m32 -= mat.m32; m33 -= mat.m33;
585 return *this;
586 }
587
588 D3DXINLINE D3DXMATRIX&
589 D3DXMATRIX::operator *= ( float f )
590 {
591 m00 *= f; m01 *= f; m02 *= f; m03 *= f;
592 m10 *= f; m11 *= f; m12 *= f; m13 *= f;
593 m20 *= f; m21 *= f; m22 *= f; m23 *= f;
594 m30 *= f; m31 *= f; m32 *= f; m33 *= f;
595 return *this;
596 }
597
598 D3DXINLINE D3DXMATRIX&
599 D3DXMATRIX::operator /= ( float f )
600 {
601 float fInv = 1.0f / f;
602 m00 *= fInv; m01 *= fInv; m02 *= fInv; m03 *= fInv;
603 m10 *= fInv; m11 *= fInv; m12 *= fInv; m13 *= fInv;
604 m20 *= fInv; m21 *= fInv; m22 *= fInv; m23 *= fInv;
605 m30 *= fInv; m31 *= fInv; m32 *= fInv; m33 *= fInv;
606 return *this;
607 }
608
609
610 // unary operators
611 D3DXINLINE D3DXMATRIX
612 D3DXMATRIX::operator + () const
613 {
614 return *this;
615 }
616
617 D3DXINLINE D3DXMATRIX
618 D3DXMATRIX::operator - () const
619 {
620 return D3DXMATRIX(-m00, -m01, -m02, -m03,
621 -m10, -m11, -m12, -m13,
622 -m20, -m21, -m22, -m23,
623 -m30, -m31, -m32, -m33);
624 }
625
626
627 // binary operators
628 D3DXINLINE D3DXMATRIX
629 D3DXMATRIX::operator * ( const D3DXMATRIX& mat ) const
630 {
631 D3DXMATRIX matT;
632 D3DXMatrixMultiply(&matT, this, &mat);
633 return matT;
634 }
635
636 D3DXINLINE D3DXMATRIX
637 D3DXMATRIX::operator + ( const D3DXMATRIX& mat ) const
638 {
639 return D3DXMATRIX(m00 + mat.m00, m01 + mat.m01, m02 + mat.m02, m03 + mat.m03,
640 m10 + mat.m10, m11 + mat.m11, m12 + mat.m12, m13 + mat.m13,
641 m20 + mat.m20, m21 + mat.m21, m22 + mat.m22, m23 + mat.m23,
642 m30 + mat.m30, m31 + mat.m31, m32 + mat.m32, m33 + mat.m33);
643 }
644
645 D3DXINLINE D3DXMATRIX
646 D3DXMATRIX::operator - ( const D3DXMATRIX& mat ) const
647 {
648 return D3DXMATRIX(m00 - mat.m00, m01 - mat.m01, m02 - mat.m02, m03 - mat.m03,
649 m10 - mat.m10, m11 - mat.m11, m12 - mat.m12, m13 - mat.m13,
650 m20 - mat.m20, m21 - mat.m21, m22 - mat.m22, m23 - mat.m23,
651 m30 - mat.m30, m31 - mat.m31, m32 - mat.m32, m33 - mat.m33);
652 }
653
654 D3DXINLINE D3DXMATRIX
655 D3DXMATRIX::operator * ( float f ) const
656 {
657 return D3DXMATRIX(m00 * f, m01 * f, m02 * f, m03 * f,
658 m10 * f, m11 * f, m12 * f, m13 * f,
659 m20 * f, m21 * f, m22 * f, m23 * f,
660 m30 * f, m31 * f, m32 * f, m33 * f);
661 }
662
663 D3DXINLINE D3DXMATRIX
664 D3DXMATRIX::operator / ( float f ) const
665 {
666 float fInv = 1.0f / f;
667 return D3DXMATRIX(m00 * fInv, m01 * fInv, m02 * fInv, m03 * fInv,
668 m10 * fInv, m11 * fInv, m12 * fInv, m13 * fInv,
669 m20 * fInv, m21 * fInv, m22 * fInv, m23 * fInv,
670 m30 * fInv, m31 * fInv, m32 * fInv, m33 * fInv);
671 }
672
673
674 D3DXINLINE D3DXMATRIX
675 operator * ( float f, const D3DXMATRIX& mat )
676 {
677 return D3DXMATRIX(f * mat.m00, f * mat.m01, f * mat.m02, f * mat.m03,
678 f * mat.m10, f * mat.m11, f * mat.m12, f * mat.m13,
679 f * mat.m20, f * mat.m21, f * mat.m22, f * mat.m23,
680 f * mat.m30, f * mat.m31, f * mat.m32, f * mat.m33);
681 }
682
683
684 D3DXINLINE BOOL
685 D3DXMATRIX::operator == ( const D3DXMATRIX& mat ) const
686 {
687 return 0 == memcmp(this, &mat, sizeof(D3DXMATRIX));
688 }
689
690 D3DXINLINE BOOL
691 D3DXMATRIX::operator != ( const D3DXMATRIX& mat ) const
692 {
693 return 0 != memcmp(this, &mat, sizeof(D3DXMATRIX));
694 }
695
696
697
698 //--------------------------
699 // Quaternion
700 //--------------------------
701
702 D3DXINLINE
703 D3DXQUATERNION::D3DXQUATERNION( const float* pf )
704 {
705 #ifdef D3DX_DEBUG
706 if(!pf)
707 return;
708 #endif
709
710 x = pf[0];
711 y = pf[1];
712 z = pf[2];
713 w = pf[3];
714 }
715
716 D3DXINLINE
717 D3DXQUATERNION::D3DXQUATERNION( float fx, float fy, float fz, float fw )
718 {
719 x = fx;
720 y = fy;
721 z = fz;
722 w = fw;
723 }
724
725
726 // casting
727 D3DXINLINE
728 D3DXQUATERNION::operator float* ()
729 {
730 return (float *) &x;
731 }
732
733 D3DXINLINE
734 D3DXQUATERNION::operator const float* () const
735 {
736 return (const float *) &x;
737 }
738
739
740 // assignment operators
741 D3DXINLINE D3DXQUATERNION&
742 D3DXQUATERNION::operator += ( const D3DXQUATERNION& q )
743 {
744 x += q.x;
745 y += q.y;
746 z += q.z;
747 w += q.w;
748 return *this;
749 }
750
751 D3DXINLINE D3DXQUATERNION&
752 D3DXQUATERNION::operator -= ( const D3DXQUATERNION& q )
753 {
754 x -= q.x;
755 y -= q.y;
756 z -= q.z;
757 w -= q.w;
758 return *this;
759 }
760
761 D3DXINLINE D3DXQUATERNION&
762 D3DXQUATERNION::operator *= ( const D3DXQUATERNION& q )
763 {
764 D3DXQuaternionMultiply(this, this, &q);
765 return *this;
766 }
767
768 D3DXINLINE D3DXQUATERNION&
769 D3DXQUATERNION::operator *= ( float f )
770 {
771 x *= f;
772 y *= f;
773 z *= f;
774 w *= f;
775 return *this;
776 }
777
778 D3DXINLINE D3DXQUATERNION&
779 D3DXQUATERNION::operator /= ( float f )
780 {
781 float fInv = 1.0f / f;
782 x *= fInv;
783 y *= fInv;
784 z *= fInv;
785 w *= fInv;
786 return *this;
787 }
788
789
790 // unary operators
791 D3DXINLINE D3DXQUATERNION
792 D3DXQUATERNION::operator + () const
793 {
794 return *this;
795 }
796
797 D3DXINLINE D3DXQUATERNION
798 D3DXQUATERNION::operator - () const
799 {
800 return D3DXQUATERNION(-x, -y, -z, -w);
801 }
802
803
804 // binary operators
805 D3DXINLINE D3DXQUATERNION
806 D3DXQUATERNION::operator + ( const D3DXQUATERNION& q ) const
807 {
808 return D3DXQUATERNION(x + q.x, y + q.y, z + q.z, w + q.w);
809 }
810
811 D3DXINLINE D3DXQUATERNION
812 D3DXQUATERNION::operator - ( const D3DXQUATERNION& q ) const
813 {
814 return D3DXQUATERNION(x - q.x, y - q.y, z - q.z, w - q.w);
815 }
816
817 D3DXINLINE D3DXQUATERNION
818 D3DXQUATERNION::operator * ( const D3DXQUATERNION& q ) const
819 {
820 D3DXQUATERNION qT;
821 D3DXQuaternionMultiply(&qT, this, &q);
822 return qT;
823 }
824
825 D3DXINLINE D3DXQUATERNION
826 D3DXQUATERNION::operator * ( float f ) const
827 {
828 return D3DXQUATERNION(x * f, y * f, z * f, w * f);
829 }
830
831 D3DXINLINE D3DXQUATERNION
832 D3DXQUATERNION::operator / ( float f ) const
833 {
834 float fInv = 1.0f / f;
835 return D3DXQUATERNION(x * fInv, y * fInv, z * fInv, w * fInv);
836 }
837
838
839 D3DXINLINE D3DXQUATERNION
840 operator * (float f, const D3DXQUATERNION& q )
841 {
842 return D3DXQUATERNION(f * q.x, f * q.y, f * q.z, f * q.w);
843 }
844
845
846 D3DXINLINE BOOL
847 D3DXQUATERNION::operator == ( const D3DXQUATERNION& q ) const
848 {
849 return x == q.x && y == q.y && z == q.z && w == q.w;
850 }
851
852 D3DXINLINE BOOL
853 D3DXQUATERNION::operator != ( const D3DXQUATERNION& q ) const
854 {
855 return x != q.x || y != q.y || z != q.z || w != q.w;
856 }
857
858
859
860 //--------------------------
861 // Plane
862 //--------------------------
863
864 D3DXINLINE
865 D3DXPLANE::D3DXPLANE( const float* pf )
866 {
867 #ifdef D3DX_DEBUG
868 if(!pf)
869 return;
870 #endif
871
872 a = pf[0];
873 b = pf[1];
874 c = pf[2];
875 d = pf[3];
876 }
877
878 D3DXINLINE
879 D3DXPLANE::D3DXPLANE( float fa, float fb, float fc, float fd )
880 {
881 a = fa;
882 b = fb;
883 c = fc;
884 d = fd;
885 }
886
887
888 // casting
889 D3DXINLINE
890 D3DXPLANE::operator float* ()
891 {
892 return (float *) &a;
893 }
894
895 D3DXINLINE
896 D3DXPLANE::operator const float* () const
897 {
898 return (const float *) &a;
899 }
900
901
902 // unary operators
903 D3DXINLINE D3DXPLANE
904 D3DXPLANE::operator + () const
905 {
906 return *this;
907 }
908
909 D3DXINLINE D3DXPLANE
910 D3DXPLANE::operator - () const
911 {
912 return D3DXPLANE(-a, -b, -c, -d);
913 }
914
915
916 // binary operators
917 D3DXINLINE BOOL
918 D3DXPLANE::operator == ( const D3DXPLANE& p ) const
919 {
920 return a == p.a && b == p.b && c == p.c && d == p.d;
921 }
922
923 D3DXINLINE BOOL
924 D3DXPLANE::operator != ( const D3DXPLANE& p ) const
925 {
926 return a != p.a || b != p.b || c != p.c || d != p.d;
927 }
928
929
930
931
932 //--------------------------
933 // Color
934 //--------------------------
935
936 D3DXINLINE
937 D3DXCOLOR::D3DXCOLOR( DWORD dw )
938 {
939 const float f = 1.0f / 255.0f;
940 r = f * (float) (unsigned char) (dw >> 16);
941 g = f * (float) (unsigned char) (dw >> 8);
942 b = f * (float) (unsigned char) (dw >> 0);
943 a = f * (float) (unsigned char) (dw >> 24);
944 }
945
946 D3DXINLINE
947 D3DXCOLOR::D3DXCOLOR( const float* pf )
948 {
949 #ifdef D3DX_DEBUG
950 if(!pf)
951 return;
952 #endif
953
954 r = pf[0];
955 g = pf[1];
956 b = pf[2];
957 a = pf[3];
958 }
959
960 D3DXINLINE
961 D3DXCOLOR::D3DXCOLOR( const D3DCOLORVALUE& c )
962 {
963 r = c.r;
964 g = c.g;
965 b = c.b;
966 a = c.a;
967 }
968
969 D3DXINLINE
970 D3DXCOLOR::D3DXCOLOR( float fr, float fg, float fb, float fa )
971 {
972 r = fr;
973 g = fg;
974 b = fb;
975 a = fa;
976 }
977
978
979 // casting
980 D3DXINLINE
981 D3DXCOLOR::operator DWORD () const
982 {
983 DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
984 DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
985 DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
986 DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
987
988 return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
989 }
990
991
992 D3DXINLINE
993 D3DXCOLOR::operator float * ()
994 {
995 return (float *) &r;
996 }
997
998 D3DXINLINE
999 D3DXCOLOR::operator const float * () const
1000 {
1001 return (const float *) &r;
1002 }
1003
1004
1005 D3DXINLINE
1006 D3DXCOLOR::operator D3DCOLORVALUE * ()
1007 {
1008 return (D3DCOLORVALUE *) &r;
1009 }
1010
1011 D3DXINLINE
1012 D3DXCOLOR::operator const D3DCOLORVALUE * () const
1013 {
1014 return (const D3DCOLORVALUE *) &r;
1015 }
1016
1017
1018 D3DXINLINE
1019 D3DXCOLOR::operator D3DCOLORVALUE& ()
1020 {
1021 return *((D3DCOLORVALUE *) &r);
1022 }
1023
1024 D3DXINLINE
1025 D3DXCOLOR::operator const D3DCOLORVALUE& () const
1026 {
1027 return *((const D3DCOLORVALUE *) &r);
1028 }
1029
1030
1031 // assignment operators
1032 D3DXINLINE D3DXCOLOR&
1033 D3DXCOLOR::operator += ( const D3DXCOLOR& c )
1034 {
1035 r += c.r;
1036 g += c.g;
1037 b += c.b;
1038 a += c.a;
1039 return *this;
1040 }
1041
1042 D3DXINLINE D3DXCOLOR&
1043 D3DXCOLOR::operator -= ( const D3DXCOLOR& c )
1044 {
1045 r -= c.r;
1046 g -= c.g;
1047 b -= c.b;
1048 a -= c.a;
1049 return *this;
1050 }
1051
1052 D3DXINLINE D3DXCOLOR&
1053 D3DXCOLOR::operator *= ( float f )
1054 {
1055 r *= f;
1056 g *= f;
1057 b *= f;
1058 a *= f;
1059 return *this;
1060 }
1061
1062 D3DXINLINE D3DXCOLOR&
1063 D3DXCOLOR::operator /= ( float f )
1064 {
1065 float fInv = 1.0f / f;
1066 r *= fInv;
1067 g *= fInv;
1068 b *= fInv;
1069 a *= fInv;
1070 return *this;
1071 }
1072
1073
1074 // unary operators
1075 D3DXINLINE D3DXCOLOR
1076 D3DXCOLOR::operator + () const
1077 {
1078 return *this;
1079 }
1080
1081 D3DXINLINE D3DXCOLOR
1082 D3DXCOLOR::operator - () const
1083 {
1084 return D3DXCOLOR(-r, -g, -b, -a);
1085 }
1086
1087
1088 // binary operators
1089 D3DXINLINE D3DXCOLOR
1090 D3DXCOLOR::operator + ( const D3DXCOLOR& c ) const
1091 {
1092 return D3DXCOLOR(r + c.r, g + c.g, b + c.b, a + c.a);
1093 }
1094
1095 D3DXINLINE D3DXCOLOR
1096 D3DXCOLOR::operator - ( const D3DXCOLOR& c ) const
1097 {
1098 return D3DXCOLOR(r - c.r, g - c.g, b - c.b, a - c.a);
1099 }
1100
1101 D3DXINLINE D3DXCOLOR
1102 D3DXCOLOR::operator * ( float f ) const
1103 {
1104 return D3DXCOLOR(r * f, g * f, b * f, a * f);
1105 }
1106
1107 D3DXINLINE D3DXCOLOR
1108 D3DXCOLOR::operator / ( float f ) const
1109 {
1110 float fInv = 1.0f / f;
1111 return D3DXCOLOR(r * fInv, g * fInv, b * fInv, a * fInv);
1112 }
1113
1114
1115 D3DXINLINE D3DXCOLOR
1116 operator * (float f, const D3DXCOLOR& c )
1117 {
1118 return D3DXCOLOR(f * c.r, f * c.g, f * c.b, f * c.a);
1119 }
1120
1121
1122 D3DXINLINE BOOL
1123 D3DXCOLOR::operator == ( const D3DXCOLOR& c ) const
1124 {
1125 return r == c.r && g == c.g && b == c.b && a == c.a;
1126 }
1127
1128 D3DXINLINE BOOL
1129 D3DXCOLOR::operator != ( const D3DXCOLOR& c ) const
1130 {
1131 return r != c.r || g != c.g || b != c.b || a != c.a;
1132 }
1133
1134
1135 #endif //__cplusplus
1136
1137
1138
1139 //===========================================================================
1140 //
1141 // Inline functions
1142 //
1143 //===========================================================================
1144
1145
1146 //--------------------------
1147 // 2D Vector
1148 //--------------------------
1149
1150 D3DXINLINE float D3DXVec2Length
1151 ( const D3DXVECTOR2 *pV )
1152 {
1153 #ifdef D3DX_DEBUG
1154 if(!pV)
1155 return 0.0f;
1156 #endif
1157
1158 #ifdef __cplusplus
1159 return sqrtf(pV->x * pV->x + pV->y * pV->y);
1160 #else
1161 return (float) sqrt(pV->x * pV->x + pV->y * pV->y);
1162 #endif
1163 }
1164
1165 D3DXINLINE float D3DXVec2LengthSq
1166 ( const D3DXVECTOR2 *pV )
1167 {
1168 #ifdef D3DX_DEBUG
1169 if(!pV)
1170 return 0.0f;
1171 #endif
1172
1173 return pV->x * pV->x + pV->y * pV->y;
1174 }
1175
1176 D3DXINLINE float D3DXVec2Dot
1177 ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1178 {
1179 #ifdef D3DX_DEBUG
1180 if(!pV1 || !pV2)
1181 return 0.0f;
1182 #endif
1183
1184 return pV1->x * pV2->x + pV1->y * pV2->y;
1185 }
1186
1187 D3DXINLINE float D3DXVec2CCW
1188 ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1189 {
1190 #ifdef D3DX_DEBUG
1191 if(!pV1 || !pV2)
1192 return 0.0f;
1193 #endif
1194
1195 return pV1->x * pV2->y - pV1->y * pV2->x;
1196 }
1197
1198 D3DXINLINE D3DXVECTOR2* D3DXVec2Add
1199 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1200 {
1201 #ifdef D3DX_DEBUG
1202 if(!pOut || !pV1 || !pV2)
1203 return NULL;
1204 #endif
1205
1206 pOut->x = pV1->x + pV2->x;
1207 pOut->y = pV1->y + pV2->y;
1208 return pOut;
1209 }
1210
1211 D3DXINLINE D3DXVECTOR2* D3DXVec2Subtract
1212 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1213 {
1214 #ifdef D3DX_DEBUG
1215 if(!pOut || !pV1 || !pV2)
1216 return NULL;
1217 #endif
1218
1219 pOut->x = pV1->x - pV2->x;
1220 pOut->y = pV1->y - pV2->y;
1221 return pOut;
1222 }
1223
1224 D3DXINLINE D3DXVECTOR2* D3DXVec2Minimize
1225 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1226 {
1227 #ifdef D3DX_DEBUG
1228 if(!pOut || !pV1 || !pV2)
1229 return NULL;
1230 #endif
1231
1232 pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1233 pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1234 return pOut;
1235 }
1236
1237 D3DXINLINE D3DXVECTOR2* D3DXVec2Maximize
1238 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
1239 {
1240 #ifdef D3DX_DEBUG
1241 if(!pOut || !pV1 || !pV2)
1242 return NULL;
1243 #endif
1244
1245 pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1246 pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1247 return pOut;
1248 }
1249
1250 D3DXINLINE D3DXVECTOR2* D3DXVec2Scale
1251 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, float s )
1252 {
1253 #ifdef D3DX_DEBUG
1254 if(!pOut || !pV)
1255 return NULL;
1256 #endif
1257
1258 pOut->x = pV->x * s;
1259 pOut->y = pV->y * s;
1260 return pOut;
1261 }
1262
1263 D3DXINLINE D3DXVECTOR2* D3DXVec2Lerp
1264 ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
1265 float s )
1266 {
1267 #ifdef D3DX_DEBUG
1268 if(!pOut || !pV1 || !pV2)
1269 return NULL;
1270 #endif
1271
1272 pOut->x = pV1->x + s * (pV2->x - pV1->x);
1273 pOut->y = pV1->y + s * (pV2->y - pV1->y);
1274 return pOut;
1275 }
1276
1277
1278 //--------------------------
1279 // 3D Vector
1280 //--------------------------
1281
1282 D3DXINLINE float D3DXVec3Length
1283 ( const D3DXVECTOR3 *pV )
1284 {
1285 #ifdef D3DX_DEBUG
1286 if(!pV)
1287 return 0.0f;
1288 #endif
1289
1290 #ifdef __cplusplus
1291 return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
1292 #else
1293 return (float) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
1294 #endif
1295 }
1296
1297 D3DXINLINE float D3DXVec3LengthSq
1298 ( const D3DXVECTOR3 *pV )
1299 {
1300 #ifdef D3DX_DEBUG
1301 if(!pV)
1302 return 0.0f;
1303 #endif
1304
1305 return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z;
1306 }
1307
1308 D3DXINLINE float D3DXVec3Dot
1309 ( const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1310 {
1311 #ifdef D3DX_DEBUG
1312 if(!pV1 || !pV2)
1313 return 0.0f;
1314 #endif
1315
1316 return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
1317 }
1318
1319 D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
1320 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1321 {
1322 D3DXVECTOR3 v;
1323
1324 #ifdef D3DX_DEBUG
1325 if(!pOut || !pV1 || !pV2)
1326 return NULL;
1327 #endif
1328
1329 v.x = pV1->y * pV2->z - pV1->z * pV2->y;
1330 v.y = pV1->z * pV2->x - pV1->x * pV2->z;
1331 v.z = pV1->x * pV2->y - pV1->y * pV2->x;
1332
1333 *pOut = v;
1334 return pOut;
1335 }
1336
1337 D3DXINLINE D3DXVECTOR3* D3DXVec3Add
1338 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1339 {
1340 #ifdef D3DX_DEBUG
1341 if(!pOut || !pV1 || !pV2)
1342 return NULL;
1343 #endif
1344
1345 pOut->x = pV1->x + pV2->x;
1346 pOut->y = pV1->y + pV2->y;
1347 pOut->z = pV1->z + pV2->z;
1348 return pOut;
1349 }
1350
1351 D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract
1352 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1353 {
1354 #ifdef D3DX_DEBUG
1355 if(!pOut || !pV1 || !pV2)
1356 return NULL;
1357 #endif
1358
1359 pOut->x = pV1->x - pV2->x;
1360 pOut->y = pV1->y - pV2->y;
1361 pOut->z = pV1->z - pV2->z;
1362 return pOut;
1363 }
1364
1365 D3DXINLINE D3DXVECTOR3* D3DXVec3Minimize
1366 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1367 {
1368 #ifdef D3DX_DEBUG
1369 if(!pOut || !pV1 || !pV2)
1370 return NULL;
1371 #endif
1372
1373 pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1374 pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1375 pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
1376 return pOut;
1377 }
1378
1379 D3DXINLINE D3DXVECTOR3* D3DXVec3Maximize
1380 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
1381 {
1382 #ifdef D3DX_DEBUG
1383 if(!pOut || !pV1 || !pV2)
1384 return NULL;
1385 #endif
1386
1387 pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1388 pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1389 pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
1390 return pOut;
1391 }
1392
1393 D3DXINLINE D3DXVECTOR3* D3DXVec3Scale
1394 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, float s)
1395 {
1396 #ifdef D3DX_DEBUG
1397 if(!pOut || !pV)
1398 return NULL;
1399 #endif
1400
1401 pOut->x = pV->x * s;
1402 pOut->y = pV->y * s;
1403 pOut->z = pV->z * s;
1404 return pOut;
1405 }
1406
1407 D3DXINLINE D3DXVECTOR3* D3DXVec3Lerp
1408 ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
1409 float s )
1410 {
1411 #ifdef D3DX_DEBUG
1412 if(!pOut || !pV1 || !pV2)
1413 return NULL;
1414 #endif
1415
1416 pOut->x = pV1->x + s * (pV2->x - pV1->x);
1417 pOut->y = pV1->y + s * (pV2->y - pV1->y);
1418 pOut->z = pV1->z + s * (pV2->z - pV1->z);
1419 return pOut;
1420 }
1421
1422
1423 //--------------------------
1424 // 4D Vector
1425 //--------------------------
1426
1427 D3DXINLINE float D3DXVec4Length
1428 ( const D3DXVECTOR4 *pV )
1429 {
1430 #ifdef D3DX_DEBUG
1431 if(!pV)
1432 return 0.0f;
1433 #endif
1434
1435 #ifdef __cplusplus
1436 return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
1437 #else
1438 return (float) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
1439 #endif
1440 }
1441
1442 D3DXINLINE float D3DXVec4LengthSq
1443 ( const D3DXVECTOR4 *pV )
1444 {
1445 #ifdef D3DX_DEBUG
1446 if(!pV)
1447 return 0.0f;
1448 #endif
1449
1450 return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w;
1451 }
1452
1453 D3DXINLINE float D3DXVec4Dot
1454 ( const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2 )
1455 {
1456 #ifdef D3DX_DEBUG
1457 if(!pV1 || !pV2)
1458 return 0.0f;
1459 #endif
1460
1461 return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w;
1462 }
1463
1464 D3DXINLINE D3DXVECTOR4* D3DXVec4Add
1465 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
1466 {
1467 #ifdef D3DX_DEBUG
1468 if(!pOut || !pV1 || !pV2)
1469 return NULL;
1470 #endif
1471
1472 pOut->x = pV1->x + pV2->x;
1473 pOut->y = pV1->y + pV2->y;
1474 pOut->z = pV1->z + pV2->z;
1475 pOut->w = pV1->w + pV2->w;
1476 return pOut;
1477 }
1478
1479 D3DXINLINE D3DXVECTOR4* D3DXVec4Subtract
1480 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
1481 {
1482 #ifdef D3DX_DEBUG
1483 if(!pOut || !pV1 || !pV2)
1484 return NULL;
1485 #endif
1486
1487 pOut->x = pV1->x - pV2->x;
1488 pOut->y = pV1->y - pV2->y;
1489 pOut->z = pV1->z - pV2->z;
1490 pOut->w = pV1->w - pV2->w;
1491 return pOut;
1492 }
1493
1494 D3DXINLINE D3DXVECTOR4* D3DXVec4Minimize
1495 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
1496 {
1497 #ifdef D3DX_DEBUG
1498 if(!pOut || !pV1 || !pV2)
1499 return NULL;
1500 #endif
1501
1502 pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1503 pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1504 pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
1505 pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w;
1506 return pOut;
1507 }
1508
1509 D3DXINLINE D3DXVECTOR4* D3DXVec4Maximize
1510 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
1511 {
1512 #ifdef D3DX_DEBUG
1513 if(!pOut || !pV1 || !pV2)
1514 return NULL;
1515 #endif
1516
1517 pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1518 pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1519 pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
1520 pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w;
1521 return pOut;
1522 }
1523
1524 D3DXINLINE D3DXVECTOR4* D3DXVec4Scale
1525 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, float s)
1526 {
1527 #ifdef D3DX_DEBUG
1528 if(!pOut || !pV)
1529 return NULL;
1530 #endif
1531
1532 pOut->x = pV->x * s;
1533 pOut->y = pV->y * s;
1534 pOut->z = pV->z * s;
1535 pOut->w = pV->w * s;
1536 return pOut;
1537 }
1538
1539 D3DXINLINE D3DXVECTOR4* D3DXVec4Lerp
1540 ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
1541 float s )
1542 {
1543 #ifdef D3DX_DEBUG
1544 if(!pOut || !pV1 || !pV2)
1545 return NULL;
1546 #endif
1547
1548 pOut->x = pV1->x + s * (pV2->x - pV1->x);
1549 pOut->y = pV1->y + s * (pV2->y - pV1->y);
1550 pOut->z = pV1->z + s * (pV2->z - pV1->z);
1551 pOut->w = pV1->w + s * (pV2->w - pV1->w);
1552 return pOut;
1553 }
1554
1555
1556 //--------------------------
1557 // 4D Matrix
1558 //--------------------------
1559
1560 D3DXINLINE D3DXMATRIX* D3DXMatrixIdentity
1561 ( D3DXMATRIX *pOut )
1562 {
1563 #ifdef D3DX_DEBUG
1564 if(!pOut)
1565 return NULL;
1566 #endif
1567
1568 pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] =
1569 pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] =
1570 pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
1571 pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
1572
1573 pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f;
1574 return pOut;
1575 }
1576
1577
1578 D3DXINLINE BOOL D3DXMatrixIsIdentity
1579 ( const D3DXMATRIX *pM )
1580 {
1581 #ifdef D3DX_DEBUG
1582 if(!pM)
1583 return FALSE;
1584 #endif
1585
1586 return pM->m[0][0] == 1.0f && pM->m[0][1] == 0.0f && pM->m[0][2] == 0.0f && pM->m[0][3] == 0.0f &&
1587 pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f &&
1588 pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f &&
1589 pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f;
1590 }
1591
1592
1593 //--------------------------
1594 // Quaternion
1595 //--------------------------
1596
1597 D3DXINLINE float D3DXQuaternionLength
1598 ( const D3DXQUATERNION *pQ )
1599 {
1600 #ifdef D3DX_DEBUG
1601 if(!pQ)
1602 return 0.0f;
1603 #endif
1604
1605 #ifdef __cplusplus
1606 return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
1607 #else
1608 return (float) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
1609 #endif
1610 }
1611
1612 D3DXINLINE float D3DXQuaternionLengthSq
1613 ( const D3DXQUATERNION *pQ )
1614 {
1615 #ifdef D3DX_DEBUG
1616 if(!pQ)
1617 return 0.0f;
1618 #endif
1619
1620 return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w;
1621 }
1622
1623 D3DXINLINE float D3DXQuaternionDot
1624 ( const D3DXQUATERNION *pQ1, const D3DXQUATERNION *pQ2 )
1625 {
1626 #ifdef D3DX_DEBUG
1627 if(!pQ1 || !pQ2)
1628 return 0.0f;
1629 #endif
1630
1631 return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w;
1632 }
1633
1634
1635 D3DXINLINE D3DXQUATERNION* D3DXQuaternionIdentity
1636 ( D3DXQUATERNION *pOut )
1637 {
1638 #ifdef D3DX_DEBUG
1639 if(!pOut)
1640 return NULL;
1641 #endif
1642
1643 pOut->x = pOut->y = pOut->z = 0.0f;
1644 pOut->w = 1.0f;
1645 return pOut;
1646 }
1647
1648 D3DXINLINE BOOL D3DXQuaternionIsIdentity
1649 ( const D3DXQUATERNION *pQ )
1650 {
1651 #ifdef D3DX_DEBUG
1652 if(!pQ)
1653 return FALSE;
1654 #endif
1655
1656 return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f;
1657 }
1658
1659
1660 D3DXINLINE D3DXQUATERNION* D3DXQuaternionConjugate
1661 ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ )
1662 {
1663 #ifdef D3DX_DEBUG
1664 if(!pOut || !pQ)
1665 return NULL;
1666 #endif
1667
1668 pOut->x = -pQ->x;
1669 pOut->y = -pQ->y;
1670 pOut->z = -pQ->z;
1671 pOut->w = pQ->w;
1672 return pOut;
1673 }
1674
1675
1676 //--------------------------
1677 // Plane
1678 //--------------------------
1679
1680 D3DXINLINE float D3DXPlaneDot
1681 ( const D3DXPLANE *pP, const D3DXVECTOR4 *pV)
1682 {
1683 #ifdef D3DX_DEBUG
1684 if(!pP || !pV)
1685 return 0.0f;
1686 #endif
1687
1688 return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w;
1689 }
1690
1691 D3DXINLINE float D3DXPlaneDotCoord
1692 ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV)
1693 {
1694 #ifdef D3DX_DEBUG
1695 if(!pP || !pV)
1696 return 0.0f;
1697 #endif
1698
1699 return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
1700 }
1701
1702 D3DXINLINE float D3DXPlaneDotNormal
1703 ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV)
1704 {
1705 #ifdef D3DX_DEBUG
1706 if(!pP || !pV)
1707 return 0.0f;
1708 #endif
1709
1710 return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z;
1711 }
1712
1713
1714 //--------------------------
1715 // Color
1716 //--------------------------
1717
1718 D3DXINLINE D3DXCOLOR* D3DXColorNegative
1719 (D3DXCOLOR *pOut, const D3DXCOLOR *pC)
1720 {
1721 #ifdef D3DX_DEBUG
1722 if(!pOut || !pC)
1723 return NULL;
1724 #endif
1725
1726 pOut->r = 1.0f - pC->r;
1727 pOut->g = 1.0f - pC->g;
1728 pOut->b = 1.0f - pC->b;
1729 pOut->a = pC->a;
1730 return pOut;
1731 }
1732
1733 D3DXINLINE D3DXCOLOR* D3DXColorAdd
1734 (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
1735 {
1736 #ifdef D3DX_DEBUG
1737 if(!pOut || !pC1 || !pC2)
1738 return NULL;
1739 #endif
1740
1741 pOut->r = pC1->r + pC2->r;
1742 pOut->g = pC1->g + pC2->g;
1743 pOut->b = pC1->b + pC2->b;
1744 pOut->a = pC1->a + pC2->a;
1745 return pOut;
1746 }
1747
1748 D3DXINLINE D3DXCOLOR* D3DXColorSubtract
1749 (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
1750 {
1751 #ifdef D3DX_DEBUG
1752 if(!pOut || !pC1 || !pC2)
1753 return NULL;
1754 #endif
1755
1756 pOut->r = pC1->r - pC2->r;
1757 pOut->g = pC1->g - pC2->g;
1758 pOut->b = pC1->b - pC2->b;
1759 pOut->a = pC1->a - pC2->a;
1760 return pOut;
1761 }
1762
1763 D3DXINLINE D3DXCOLOR* D3DXColorScale
1764 (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s)
1765 {
1766 #ifdef D3DX_DEBUG
1767 if(!pOut || !pC)
1768 return NULL;
1769 #endif
1770
1771 pOut->r = pC->r * s;
1772 pOut->g = pC->g * s;
1773 pOut->b = pC->b * s;
1774 pOut->a = pC->a * s;
1775 return pOut;
1776 }
1777
1778 D3DXINLINE D3DXCOLOR* D3DXColorModulate
1779 (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
1780 {
1781 #ifdef D3DX_DEBUG
1782 if(!pOut || !pC1 || !pC2)
1783 return NULL;
1784 #endif
1785
1786 pOut->r = pC1->r * pC2->r;
1787 pOut->g = pC1->g * pC2->g;
1788 pOut->b = pC1->b * pC2->b;
1789 pOut->a = pC1->a * pC2->a;
1790 return pOut;
1791 }
1792
1793 D3DXINLINE D3DXCOLOR* D3DXColorLerp
1794 (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2, float s)
1795 {
1796 #ifdef D3DX_DEBUG
1797 if(!pOut || !pC1 || !pC2)
1798 return NULL;
1799 #endif
1800
1801 pOut->r = pC1->r + s * (pC2->r - pC1->r);
1802 pOut->g = pC1->g + s * (pC2->g - pC1->g);
1803 pOut->b = pC1->b + s * (pC2->b - pC1->b);
1804 pOut->a = pC1->a + s * (pC2->a - pC1->a);
1805 return pOut;
1806 }
1807
1808
1809 #endif // __D3DXMATH_INL__

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26