Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
//////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright (C) Microsoft Corporation.  All Rights Reserved.
4
//
5
//  File:       d3dx9math.inl
6
//  Content:    D3DX math inline functions
7
//
8
//////////////////////////////////////////////////////////////////////////////
9
 
10
#ifndef __D3DX9MATH_INL__
11
#define __D3DX9MATH_INL__
12
 
13
//===========================================================================
14
//
15
// Inline Class Methods
16
//
17
//===========================================================================
18
 
19
#ifdef __cplusplus
20
 
21
//--------------------------
22
// Float16
23
//--------------------------
24
 
25
D3DXINLINE
26
D3DXFLOAT16::D3DXFLOAT16( FLOAT f )
27
{
28
    D3DXFloat32To16Array(this, &f, 1);
29
}
30
 
31
D3DXINLINE
32
D3DXFLOAT16::D3DXFLOAT16( CONST D3DXFLOAT16& f )
33
{
34
    value = f.value;
35
}
36
 
37
// casting
38
D3DXINLINE
39
D3DXFLOAT16::operator FLOAT ()
40
{
41
    FLOAT f;
42
    D3DXFloat16To32Array(&f, this, 1);
43
    return f;
44
}
45
 
46
// binary operators
47
D3DXINLINE BOOL
48
D3DXFLOAT16::operator == ( CONST D3DXFLOAT16& f ) const
49
{
50
    return value == f.value;
51
}
52
 
53
D3DXINLINE BOOL
54
D3DXFLOAT16::operator != ( CONST D3DXFLOAT16& f ) const
55
{
56
    return value != f.value;
57
}
58
 
59
 
60
//--------------------------
61
// 2D Vector
62
//--------------------------
63
 
64
D3DXINLINE
65
D3DXVECTOR2::D3DXVECTOR2( CONST FLOAT *pf )
66
{
67
#ifdef D3DX_DEBUG
68
    if(!pf)
69
        return;
70
#endif
71
 
72
    x = pf[0];
73
    y = pf[1];
74
}
75
 
76
D3DXINLINE
77
D3DXVECTOR2::D3DXVECTOR2( CONST D3DXFLOAT16 *pf )
78
{
79
#ifdef D3DX_DEBUG
80
    if(!pf)
81
        return;
82
#endif
83
 
84
    D3DXFloat16To32Array(&x, pf, 2);    
85
}
86
 
87
D3DXINLINE
88
D3DXVECTOR2::D3DXVECTOR2( FLOAT fx, FLOAT fy )
89
{
90
    x = fx;
91
    y = fy;
92
}
93
 
94
 
95
// casting
96
D3DXINLINE
97
D3DXVECTOR2::operator FLOAT* ()
98
{
99
    return (FLOAT *) &x;
100
}
101
 
102
D3DXINLINE
103
D3DXVECTOR2::operator CONST FLOAT* () const
104
{
105
    return (CONST FLOAT *) &x;
106
}
107
 
108
 
109
// assignment operators
110
D3DXINLINE D3DXVECTOR2&
111
D3DXVECTOR2::operator += ( CONST D3DXVECTOR2& v )
112
{
113
    x += v.x;
114
    y += v.y;
115
    return *this;
116
}
117
 
118
D3DXINLINE D3DXVECTOR2&
119
D3DXVECTOR2::operator -= ( CONST D3DXVECTOR2& v )
120
{
121
    x -= v.x;
122
    y -= v.y;
123
    return *this;
124
}
125
 
126
D3DXINLINE D3DXVECTOR2&
127
D3DXVECTOR2::operator *= ( FLOAT f )
128
{
129
    x *= f;
130
    y *= f;
131
    return *this;
132
}
133
 
134
D3DXINLINE D3DXVECTOR2&
135
D3DXVECTOR2::operator /= ( FLOAT f )
136
{
137
    FLOAT fInv = 1.0f / f;
138
    x *= fInv;
139
    y *= fInv;
140
    return *this;
141
}
142
 
143
 
144
// unary operators
145
D3DXINLINE D3DXVECTOR2
146
D3DXVECTOR2::operator + () const
147
{
148
    return *this;
149
}
150
 
151
D3DXINLINE D3DXVECTOR2
152
D3DXVECTOR2::operator - () const
153
{
154
    return D3DXVECTOR2(-x, -y);
155
}
156
 
157
 
158
// binary operators
159
D3DXINLINE D3DXVECTOR2
160
D3DXVECTOR2::operator + ( CONST D3DXVECTOR2& v ) const
161
{
162
    return D3DXVECTOR2(x + v.x, y + v.y);
163
}
164
 
165
D3DXINLINE D3DXVECTOR2
166
D3DXVECTOR2::operator - ( CONST D3DXVECTOR2& v ) const
167
{
168
    return D3DXVECTOR2(x - v.x, y - v.y);
169
}
170
 
171
D3DXINLINE D3DXVECTOR2
172
D3DXVECTOR2::operator * ( FLOAT f ) const
173
{
174
    return D3DXVECTOR2(x * f, y * f);
175
}
176
 
177
D3DXINLINE D3DXVECTOR2
178
D3DXVECTOR2::operator / ( FLOAT f ) const
179
{
180
    FLOAT fInv = 1.0f / f;
181
    return D3DXVECTOR2(x * fInv, y * fInv);
182
}
183
 
184
D3DXINLINE D3DXVECTOR2
185
operator * ( FLOAT f, CONST D3DXVECTOR2& v )
186
{
187
    return D3DXVECTOR2(f * v.x, f * v.y);
188
}
189
 
190
D3DXINLINE BOOL
191
D3DXVECTOR2::operator == ( CONST D3DXVECTOR2& v ) const
192
{
193
    return x == v.x && y == v.y;
194
}
195
 
196
D3DXINLINE BOOL
197
D3DXVECTOR2::operator != ( CONST D3DXVECTOR2& v ) const
198
{
199
    return x != v.x || y != v.y;
200
}
201
 
202
 
203
 
204
//--------------------------
205
// 2D Vector (16 bit)
206
//--------------------------
207
 
208
D3DXINLINE
209
D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST FLOAT *pf )
210
{
211
#ifdef D3DX_DEBUG
212
    if(!pf)
213
        return;
214
#endif
215
 
216
    D3DXFloat32To16Array(&x, pf, 2);
217
}
218
 
219
D3DXINLINE
220
D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 *pf )
221
{
222
#ifdef D3DX_DEBUG
223
    if(!pf)
224
        return;
225
#endif
226
 
227
    *((DWORD *) &x) = *((DWORD *) &pf[0]);
228
}
229
 
230
D3DXINLINE
231
D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy )
232
{
233
    x = fx;
234
    y = fy;
235
}
236
 
237
 
238
// casting
239
D3DXINLINE
240
D3DXVECTOR2_16F::operator D3DXFLOAT16* ()
241
{
242
    return (D3DXFLOAT16*) &x;
243
}
244
 
245
D3DXINLINE
246
D3DXVECTOR2_16F::operator CONST D3DXFLOAT16* () const
247
{
248
    return (CONST D3DXFLOAT16*) &x;
249
}
250
 
251
 
252
// binary operators
253
D3DXINLINE BOOL 
254
D3DXVECTOR2_16F::operator == ( CONST D3DXVECTOR2_16F &v ) const
255
{
256
    return *((DWORD *) &x) == *((DWORD *) &v.x);
257
}
258
 
259
D3DXINLINE BOOL 
260
D3DXVECTOR2_16F::operator != ( CONST D3DXVECTOR2_16F &v ) const
261
{
262
    return *((DWORD *) &x) != *((DWORD *) &v.x);
263
}
264
 
265
 
266
//--------------------------
267
// 3D Vector
268
//--------------------------
269
D3DXINLINE
270
D3DXVECTOR3::D3DXVECTOR3( CONST FLOAT *pf )
271
{
272
#ifdef D3DX_DEBUG
273
    if(!pf)
274
        return;
275
#endif
276
 
277
    x = pf[0];
278
    y = pf[1];
279
    z = pf[2];
280
}
281
 
282
D3DXINLINE
283
D3DXVECTOR3::D3DXVECTOR3( CONST D3DVECTOR& v )
284
{
285
    x = v.x;
286
    y = v.y;
287
    z = v.z;
288
}
289
 
290
D3DXINLINE
291
D3DXVECTOR3::D3DXVECTOR3( CONST D3DXFLOAT16 *pf )
292
{
293
#ifdef D3DX_DEBUG
294
    if(!pf)
295
        return;
296
#endif
297
 
298
    D3DXFloat16To32Array(&x, pf, 3);
299
}
300
 
301
D3DXINLINE
302
D3DXVECTOR3::D3DXVECTOR3( FLOAT fx, FLOAT fy, FLOAT fz )
303
{
304
    x = fx;
305
    y = fy;
306
    z = fz;
307
}
308
 
309
 
310
// casting
311
D3DXINLINE
312
D3DXVECTOR3::operator FLOAT* ()
313
{
314
    return (FLOAT *) &x;
315
}
316
 
317
D3DXINLINE
318
D3DXVECTOR3::operator CONST FLOAT* () const
319
{
320
    return (CONST FLOAT *) &x;
321
}
322
 
323
 
324
// assignment operators
325
D3DXINLINE D3DXVECTOR3&
326
D3DXVECTOR3::operator += ( CONST D3DXVECTOR3& v )
327
{
328
    x += v.x;
329
    y += v.y;
330
    z += v.z;
331
    return *this;
332
}
333
 
334
D3DXINLINE D3DXVECTOR3&
335
D3DXVECTOR3::operator -= ( CONST D3DXVECTOR3& v )
336
{
337
    x -= v.x;
338
    y -= v.y;
339
    z -= v.z;
340
    return *this;
341
}
342
 
343
D3DXINLINE D3DXVECTOR3&
344
D3DXVECTOR3::operator *= ( FLOAT f )
345
{
346
    x *= f;
347
    y *= f;
348
    z *= f;
349
    return *this;
350
}
351
 
352
D3DXINLINE D3DXVECTOR3&
353
D3DXVECTOR3::operator /= ( FLOAT f )
354
{
355
    FLOAT fInv = 1.0f / f;
356
    x *= fInv;
357
    y *= fInv;
358
    z *= fInv;
359
    return *this;
360
}
361
 
362
 
363
// unary operators
364
D3DXINLINE D3DXVECTOR3
365
D3DXVECTOR3::operator + () const
366
{
367
    return *this;
368
}
369
 
370
D3DXINLINE D3DXVECTOR3
371
D3DXVECTOR3::operator - () const
372
{
373
    return D3DXVECTOR3(-x, -y, -z);
374
}
375
 
376
 
377
// binary operators
378
D3DXINLINE D3DXVECTOR3
379
D3DXVECTOR3::operator + ( CONST D3DXVECTOR3& v ) const
380
{
381
    return D3DXVECTOR3(x + v.x, y + v.y, z + v.z);
382
}
383
 
384
D3DXINLINE D3DXVECTOR3
385
D3DXVECTOR3::operator - ( CONST D3DXVECTOR3& v ) const
386
{
387
    return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
388
}
389
 
390
D3DXINLINE D3DXVECTOR3
391
D3DXVECTOR3::operator * ( FLOAT f ) const
392
{
393
    return D3DXVECTOR3(x * f, y * f, z * f);
394
}
395
 
396
D3DXINLINE D3DXVECTOR3
397
D3DXVECTOR3::operator / ( FLOAT f ) const
398
{
399
    FLOAT fInv = 1.0f / f;
400
    return D3DXVECTOR3(x * fInv, y * fInv, z * fInv);
401
}
402
 
403
 
404
D3DXINLINE D3DXVECTOR3
405
operator * ( FLOAT f, CONST struct D3DXVECTOR3& v )
406
{
407
    return D3DXVECTOR3(f * v.x, f * v.y, f * v.z);
408
}
409
 
410
 
411
D3DXINLINE BOOL
412
D3DXVECTOR3::operator == ( CONST D3DXVECTOR3& v ) const
413
{
414
    return x == v.x && y == v.y && z == v.z;
415
}
416
 
417
D3DXINLINE BOOL
418
D3DXVECTOR3::operator != ( CONST D3DXVECTOR3& v ) const
419
{
420
    return x != v.x || y != v.y || z != v.z;
421
}
422
 
423
 
424
 
425
//--------------------------
426
// 3D Vector (16 bit)
427
//--------------------------
428
 
429
D3DXINLINE
430
D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST FLOAT *pf )
431
{
432
#ifdef D3DX_DEBUG
433
    if(!pf)
434
        return;
435
#endif
436
 
437
    D3DXFloat32To16Array(&x, pf, 3);
438
}
439
 
440
D3DXINLINE
441
D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DVECTOR& v )
442
{
443
    D3DXFloat32To16Array(&x, &v.x, 1);
444
    D3DXFloat32To16Array(&y, &v.y, 1);
445
    D3DXFloat32To16Array(&z, &v.z, 1);
446
}
447
 
448
D3DXINLINE
449
D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 *pf )
450
{
451
#ifdef D3DX_DEBUG
452
    if(!pf)
453
        return;
454
#endif
455
 
456
    *((DWORD *) &x) = *((DWORD *) &pf[0]);
457
    *((WORD  *) &z) = *((WORD  *) &pf[2]);
458
}
459
 
460
D3DXINLINE
461
D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz )
462
{
463
    x = fx;
464
    y = fy;
465
    z = fz;
466
}
467
 
468
 
469
// casting
470
D3DXINLINE
471
D3DXVECTOR3_16F::operator D3DXFLOAT16* ()
472
{
473
    return (D3DXFLOAT16*) &x;
474
}
475
 
476
D3DXINLINE
477
D3DXVECTOR3_16F::operator CONST D3DXFLOAT16* () const
478
{
479
    return (CONST D3DXFLOAT16*) &x;
480
}
481
 
482
 
483
// binary operators
484
D3DXINLINE BOOL 
485
D3DXVECTOR3_16F::operator == ( CONST D3DXVECTOR3_16F &v ) const
486
{
487
    return *((DWORD *) &x) == *((DWORD *) &v.x) &&
488
           *((WORD  *) &z) == *((WORD  *) &v.z);
489
}
490
 
491
D3DXINLINE BOOL 
492
D3DXVECTOR3_16F::operator != ( CONST D3DXVECTOR3_16F &v ) const
493
{
494
    return *((DWORD *) &x) != *((DWORD *) &v.x) ||
495
           *((WORD  *) &z) != *((WORD  *) &v.z);
496
}
497
 
498
 
499
//--------------------------
500
// 4D Vector
501
//--------------------------
502
D3DXINLINE
503
D3DXVECTOR4::D3DXVECTOR4( CONST FLOAT *pf )
504
{
505
#ifdef D3DX_DEBUG
506
    if(!pf)
507
        return;
508
#endif
509
 
510
    x = pf[0];
511
    y = pf[1];
512
    z = pf[2];
513
    w = pf[3];
514
}
515
 
516
D3DXINLINE
517
D3DXVECTOR4::D3DXVECTOR4( CONST D3DXFLOAT16 *pf )
518
{
519
#ifdef D3DX_DEBUG
520
    if(!pf)
521
        return;
522
#endif
523
 
524
    D3DXFloat16To32Array(&x, pf, 4);
525
}
526
 
527
D3DXINLINE
528
D3DXVECTOR4::D3DXVECTOR4( CONST D3DVECTOR& v, FLOAT f )
529
{
530
    x = v.x;
531
    y = v.y;
532
    z = v.z;
533
    w = f;
534
}
535
 
536
D3DXINLINE
537
D3DXVECTOR4::D3DXVECTOR4( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
538
{
539
    x = fx;
540
    y = fy;
541
    z = fz;
542
    w = fw;
543
}
544
 
545
 
546
// casting
547
D3DXINLINE
548
D3DXVECTOR4::operator FLOAT* ()
549
{
550
    return (FLOAT *) &x;
551
}
552
 
553
D3DXINLINE
554
D3DXVECTOR4::operator CONST FLOAT* () const
555
{
556
    return (CONST FLOAT *) &x;
557
}
558
 
559
 
560
// assignment operators
561
D3DXINLINE D3DXVECTOR4&
562
D3DXVECTOR4::operator += ( CONST D3DXVECTOR4& v )
563
{
564
    x += v.x;
565
    y += v.y;
566
    z += v.z;
567
    w += v.w;
568
    return *this;
569
}
570
 
571
D3DXINLINE D3DXVECTOR4&
572
D3DXVECTOR4::operator -= ( CONST D3DXVECTOR4& v )
573
{
574
    x -= v.x;
575
    y -= v.y;
576
    z -= v.z;
577
    w -= v.w;
578
    return *this;
579
}
580
 
581
D3DXINLINE D3DXVECTOR4&
582
D3DXVECTOR4::operator *= ( FLOAT f )
583
{
584
    x *= f;
585
    y *= f;
586
    z *= f;
587
    w *= f;
588
    return *this;
589
}
590
 
591
D3DXINLINE D3DXVECTOR4&
592
D3DXVECTOR4::operator /= ( FLOAT f )
593
{
594
    FLOAT fInv = 1.0f / f;
595
    x *= fInv;
596
    y *= fInv;
597
    z *= fInv;
598
    w *= fInv;
599
    return *this;
600
}
601
 
602
 
603
// unary operators
604
D3DXINLINE D3DXVECTOR4
605
D3DXVECTOR4::operator + () const
606
{
607
    return *this;
608
}
609
 
610
D3DXINLINE D3DXVECTOR4
611
D3DXVECTOR4::operator - () const
612
{
613
    return D3DXVECTOR4(-x, -y, -z, -w);
614
}
615
 
616
 
617
// binary operators
618
D3DXINLINE D3DXVECTOR4
619
D3DXVECTOR4::operator + ( CONST D3DXVECTOR4& v ) const
620
{
621
    return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w);
622
}
623
 
624
D3DXINLINE D3DXVECTOR4
625
D3DXVECTOR4::operator - ( CONST D3DXVECTOR4& v ) const
626
{
627
    return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w);
628
}
629
 
630
D3DXINLINE D3DXVECTOR4
631
D3DXVECTOR4::operator * ( FLOAT f ) const
632
{
633
    return D3DXVECTOR4(x * f, y * f, z * f, w * f);
634
}
635
 
636
D3DXINLINE D3DXVECTOR4
637
D3DXVECTOR4::operator / ( FLOAT f ) const
638
{
639
    FLOAT fInv = 1.0f / f;
640
    return D3DXVECTOR4(x * fInv, y * fInv, z * fInv, w * fInv);
641
}
642
 
643
D3DXINLINE D3DXVECTOR4
644
operator * ( FLOAT f, CONST D3DXVECTOR4& v )
645
{
646
    return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w);
647
}
648
 
649
 
650
D3DXINLINE BOOL
651
D3DXVECTOR4::operator == ( CONST D3DXVECTOR4& v ) const
652
{
653
    return x == v.x && y == v.y && z == v.z && w == v.w;
654
}
655
 
656
D3DXINLINE BOOL
657
D3DXVECTOR4::operator != ( CONST D3DXVECTOR4& v ) const
658
{
659
    return x != v.x || y != v.y || z != v.z || w != v.w;
660
}
661
 
662
 
663
 
664
//--------------------------
665
// 4D Vector (16 bit)
666
//--------------------------
667
 
668
D3DXINLINE
669
D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST FLOAT *pf )
670
{
671
#ifdef D3DX_DEBUG
672
    if(!pf)
673
        return;
674
#endif
675
 
676
    D3DXFloat32To16Array(&x, pf, 4);
677
}
678
 
679
D3DXINLINE
680
D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 *pf )
681
{
682
#ifdef D3DX_DEBUG
683
    if(!pf)
684
        return;
685
#endif
686
 
687
    *((DWORD *) &x) = *((DWORD *) &pf[0]);
688
    *((DWORD *) &z) = *((DWORD *) &pf[2]);
689
}
690
 
691
D3DXINLINE
692
D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& v, CONST D3DXFLOAT16& f )
693
{
694
    x = v.x;
695
    y = v.y;
696
    z = v.z;
697
    w = f;
698
}
699
 
700
D3DXINLINE
701
D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz, CONST D3DXFLOAT16 &fw )
702
{
703
    x = fx;
704
    y = fy;
705
    z = fz;
706
    w = fw;
707
}
708
 
709
 
710
// casting
711
D3DXINLINE
712
D3DXVECTOR4_16F::operator D3DXFLOAT16* ()
713
{
714
    return (D3DXFLOAT16*) &x;
715
}
716
 
717
D3DXINLINE
718
D3DXVECTOR4_16F::operator CONST D3DXFLOAT16* () const
719
{
720
    return (CONST D3DXFLOAT16*) &x;
721
}
722
 
723
 
724
// binary operators
725
D3DXINLINE BOOL 
726
D3DXVECTOR4_16F::operator == ( CONST D3DXVECTOR4_16F &v ) const
727
{
728
    return *((DWORD *) &x) == *((DWORD *) &v.x) &&
729
           *((DWORD *) &z) == *((DWORD *) &v.z);
730
}
731
 
732
D3DXINLINE BOOL 
733
D3DXVECTOR4_16F::operator != ( CONST D3DXVECTOR4_16F &v ) const
734
{
735
    return *((DWORD *) &x) != *((DWORD *) &v.x) ||
736
           *((DWORD *) &z) != *((DWORD *) &v.z);
737
}
738
 
739
 
740
//--------------------------
741
// Matrix
742
//--------------------------
743
D3DXINLINE
744
D3DXMATRIX::D3DXMATRIX( CONST FLOAT* pf )
745
{
746
#ifdef D3DX_DEBUG
747
    if(!pf)
748
        return;
749
#endif
750
 
751
    memcpy(&_11, pf, sizeof(D3DXMATRIX));
752
}
753
 
754
D3DXINLINE
755
D3DXMATRIX::D3DXMATRIX( CONST D3DMATRIX& mat )
756
{
757
    memcpy(&_11, &mat, sizeof(D3DXMATRIX));
758
}
759
 
760
D3DXINLINE
761
D3DXMATRIX::D3DXMATRIX( CONST D3DXFLOAT16* pf )
762
{
763
#ifdef D3DX_DEBUG
764
    if(!pf)
765
        return;
766
#endif
767
 
768
    D3DXFloat16To32Array(&_11, pf, 16);
769
}
770
 
771
D3DXINLINE
772
D3DXMATRIX::D3DXMATRIX( FLOAT f11, FLOAT f12, FLOAT f13, FLOAT f14,
773
                        FLOAT f21, FLOAT f22, FLOAT f23, FLOAT f24,
774
                        FLOAT f31, FLOAT f32, FLOAT f33, FLOAT f34,
775
                        FLOAT f41, FLOAT f42, FLOAT f43, FLOAT f44 )
776
{
777
    _11 = f11; _12 = f12; _13 = f13; _14 = f14;
778
    _21 = f21; _22 = f22; _23 = f23; _24 = f24;
779
    _31 = f31; _32 = f32; _33 = f33; _34 = f34;
780
    _41 = f41; _42 = f42; _43 = f43; _44 = f44;
781
}
782
 
783
 
784
 
785
// access grants
786
D3DXINLINE FLOAT&
787
D3DXMATRIX::operator () ( UINT iRow, UINT iCol )
788
{
789
    return m[iRow][iCol];
790
}
791
 
792
D3DXINLINE FLOAT
793
D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) const
794
{
795
    return m[iRow][iCol];
796
}
797
 
798
 
799
// casting operators
800
D3DXINLINE
801
D3DXMATRIX::operator FLOAT* ()
802
{
803
    return (FLOAT *) &_11;
804
}
805
 
806
D3DXINLINE
807
D3DXMATRIX::operator CONST FLOAT* () const
808
{
809
    return (CONST FLOAT *) &_11;
810
}
811
 
812
 
813
// assignment operators
814
D3DXINLINE D3DXMATRIX&
815
D3DXMATRIX::operator *= ( CONST D3DXMATRIX& mat )
816
{
817
    D3DXMatrixMultiply(this, this, &mat);
818
    return *this;
819
}
820
 
821
D3DXINLINE D3DXMATRIX&
822
D3DXMATRIX::operator += ( CONST D3DXMATRIX& mat )
823
{
824
    _11 += mat._11; _12 += mat._12; _13 += mat._13; _14 += mat._14;
825
    _21 += mat._21; _22 += mat._22; _23 += mat._23; _24 += mat._24;
826
    _31 += mat._31; _32 += mat._32; _33 += mat._33; _34 += mat._34;
827
    _41 += mat._41; _42 += mat._42; _43 += mat._43; _44 += mat._44;
828
    return *this;
829
}
830
 
831
D3DXINLINE D3DXMATRIX&
832
D3DXMATRIX::operator -= ( CONST D3DXMATRIX& mat )
833
{
834
    _11 -= mat._11; _12 -= mat._12; _13 -= mat._13; _14 -= mat._14;
835
    _21 -= mat._21; _22 -= mat._22; _23 -= mat._23; _24 -= mat._24;
836
    _31 -= mat._31; _32 -= mat._32; _33 -= mat._33; _34 -= mat._34;
837
    _41 -= mat._41; _42 -= mat._42; _43 -= mat._43; _44 -= mat._44;
838
    return *this;
839
}
840
 
841
D3DXINLINE D3DXMATRIX&
842
D3DXMATRIX::operator *= ( FLOAT f )
843
{
844
    _11 *= f; _12 *= f; _13 *= f; _14 *= f;
845
    _21 *= f; _22 *= f; _23 *= f; _24 *= f;
846
    _31 *= f; _32 *= f; _33 *= f; _34 *= f;
847
    _41 *= f; _42 *= f; _43 *= f; _44 *= f;
848
    return *this;
849
}
850
 
851
D3DXINLINE D3DXMATRIX&
852
D3DXMATRIX::operator /= ( FLOAT f )
853
{
854
    FLOAT fInv = 1.0f / f;
855
    _11 *= fInv; _12 *= fInv; _13 *= fInv; _14 *= fInv;
856
    _21 *= fInv; _22 *= fInv; _23 *= fInv; _24 *= fInv;
857
    _31 *= fInv; _32 *= fInv; _33 *= fInv; _34 *= fInv;
858
    _41 *= fInv; _42 *= fInv; _43 *= fInv; _44 *= fInv;
859
    return *this;
860
}
861
 
862
 
863
// unary operators
864
D3DXINLINE D3DXMATRIX
865
D3DXMATRIX::operator + () const
866
{
867
    return *this;
868
}
869
 
870
D3DXINLINE D3DXMATRIX
871
D3DXMATRIX::operator - () const
872
{
873
    return D3DXMATRIX(-_11, -_12, -_13, -_14,
874
                      -_21, -_22, -_23, -_24,
875
                      -_31, -_32, -_33, -_34,
876
                      -_41, -_42, -_43, -_44);
877
}
878
 
879
 
880
// binary operators
881
D3DXINLINE D3DXMATRIX
882
D3DXMATRIX::operator * ( CONST D3DXMATRIX& mat ) const
883
{
884
    D3DXMATRIX matT;
885
    D3DXMatrixMultiply(&matT, this, &mat);
886
    return matT;
887
}
888
 
889
D3DXINLINE D3DXMATRIX
890
D3DXMATRIX::operator + ( CONST D3DXMATRIX& mat ) const
891
{
892
    return D3DXMATRIX(_11 + mat._11, _12 + mat._12, _13 + mat._13, _14 + mat._14,
893
                      _21 + mat._21, _22 + mat._22, _23 + mat._23, _24 + mat._24,
894
                      _31 + mat._31, _32 + mat._32, _33 + mat._33, _34 + mat._34,
895
                      _41 + mat._41, _42 + mat._42, _43 + mat._43, _44 + mat._44);
896
}
897
 
898
D3DXINLINE D3DXMATRIX
899
D3DXMATRIX::operator - ( CONST D3DXMATRIX& mat ) const
900
{
901
    return D3DXMATRIX(_11 - mat._11, _12 - mat._12, _13 - mat._13, _14 - mat._14,
902
                      _21 - mat._21, _22 - mat._22, _23 - mat._23, _24 - mat._24,
903
                      _31 - mat._31, _32 - mat._32, _33 - mat._33, _34 - mat._34,
904
                      _41 - mat._41, _42 - mat._42, _43 - mat._43, _44 - mat._44);
905
}
906
 
907
D3DXINLINE D3DXMATRIX
908
D3DXMATRIX::operator * ( FLOAT f ) const
909
{
910
    return D3DXMATRIX(_11 * f, _12 * f, _13 * f, _14 * f,
911
                      _21 * f, _22 * f, _23 * f, _24 * f,
912
                      _31 * f, _32 * f, _33 * f, _34 * f,
913
                      _41 * f, _42 * f, _43 * f, _44 * f);
914
}
915
 
916
D3DXINLINE D3DXMATRIX
917
D3DXMATRIX::operator / ( FLOAT f ) const
918
{
919
    FLOAT fInv = 1.0f / f;
920
    return D3DXMATRIX(_11 * fInv, _12 * fInv, _13 * fInv, _14 * fInv,
921
                      _21 * fInv, _22 * fInv, _23 * fInv, _24 * fInv,
922
                      _31 * fInv, _32 * fInv, _33 * fInv, _34 * fInv,
923
                      _41 * fInv, _42 * fInv, _43 * fInv, _44 * fInv);
924
}
925
 
926
 
927
D3DXINLINE D3DXMATRIX
928
operator * ( FLOAT f, CONST D3DXMATRIX& mat )
929
{
930
    return D3DXMATRIX(f * mat._11, f * mat._12, f * mat._13, f * mat._14,
931
                      f * mat._21, f * mat._22, f * mat._23, f * mat._24,
932
                      f * mat._31, f * mat._32, f * mat._33, f * mat._34,
933
                      f * mat._41, f * mat._42, f * mat._43, f * mat._44);
934
}
935
 
936
 
937
D3DXINLINE BOOL
938
D3DXMATRIX::operator == ( CONST D3DXMATRIX& mat ) const
939
{
940
    return 0 == memcmp(this, &mat, sizeof(D3DXMATRIX));
941
}
942
 
943
D3DXINLINE BOOL
944
D3DXMATRIX::operator != ( CONST D3DXMATRIX& mat ) const
945
{
946
    return 0 != memcmp(this, &mat, sizeof(D3DXMATRIX));
947
}
948
 
949
 
950
 
951
//--------------------------
952
// Aligned Matrices
953
//--------------------------
954
 
955
D3DXINLINE
956
_D3DXMATRIXA16::_D3DXMATRIXA16( CONST FLOAT* f ) : 
957
    D3DXMATRIX( f ) 
958
{
959
}
960
 
961
D3DXINLINE
962
_D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DMATRIX& m ) : 
963
    D3DXMATRIX( m ) 
964
{
965
}
966
 
967
D3DXINLINE
968
_D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DXFLOAT16* f ) : 
969
    D3DXMATRIX( f ) 
970
{
971
}
972
 
973
D3DXINLINE
974
_D3DXMATRIXA16::_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
975
                                FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
976
                                FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
977
                                FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ) :
978
    D3DXMATRIX(_11, _12, _13, _14,
979
               _21, _22, _23, _24,
980
               _31, _32, _33, _34,
981
               _41, _42, _43, _44) 
982
{
983
}
984
 
985
#ifndef SIZE_MAX
986
#define SIZE_MAX ((SIZE_T)-1)
987
#endif
988
 
989
D3DXINLINE void* 
990
_D3DXMATRIXA16::operator new( size_t s )
991
{
992
    if (s > (SIZE_MAX-16))
993
	return NULL;
994
    LPBYTE p = ::new BYTE[s + 16];
995
    if (p)
996
    {
997
        BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
998
        p += offset;
999
        p[-1] = offset;
1000
    }
1001
    return p;
1002
}
1003
 
1004
D3DXINLINE void* 
1005
_D3DXMATRIXA16::operator new[]( size_t s )
1006
{
1007
    if (s > (SIZE_MAX-16))
1008
	return NULL;
1009
    LPBYTE p = ::new BYTE[s + 16];
1010
    if (p)
1011
    {
1012
        BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
1013
        p += offset;
1014
        p[-1] = offset;
1015
    }
1016
    return p;
1017
}
1018
 
1019
D3DXINLINE void 
1020
_D3DXMATRIXA16::operator delete(void* p)
1021
{
1022
    if(p)
1023
    {
1024
        BYTE* pb = static_cast<BYTE*>(p);
1025
        pb -= pb[-1];
1026
        ::delete [] pb;
1027
    }
1028
}
1029
 
1030
D3DXINLINE void 
1031
_D3DXMATRIXA16::operator delete[](void* p)
1032
{
1033
    if(p)
1034
    {
1035
        BYTE* pb = static_cast<BYTE*>(p);
1036
        pb -= pb[-1];
1037
        ::delete [] pb;
1038
    }
1039
}
1040
 
1041
D3DXINLINE _D3DXMATRIXA16& 
1042
_D3DXMATRIXA16::operator=(CONST D3DXMATRIX& rhs)
1043
{
1044
    memcpy(&_11, &rhs, sizeof(D3DXMATRIX));
1045
    return *this;
1046
}
1047
 
1048
 
1049
//--------------------------
1050
// Quaternion
1051
//--------------------------
1052
 
1053
D3DXINLINE
1054
D3DXQUATERNION::D3DXQUATERNION( CONST FLOAT* pf )
1055
{
1056
#ifdef D3DX_DEBUG
1057
    if(!pf)
1058
        return;
1059
#endif
1060
 
1061
    x = pf[0];
1062
    y = pf[1];
1063
    z = pf[2];
1064
    w = pf[3];
1065
}
1066
 
1067
D3DXINLINE
1068
D3DXQUATERNION::D3DXQUATERNION( CONST D3DXFLOAT16* pf )
1069
{
1070
#ifdef D3DX_DEBUG
1071
    if(!pf)
1072
        return;
1073
#endif
1074
 
1075
    D3DXFloat16To32Array(&x, pf, 4);
1076
}
1077
 
1078
D3DXINLINE
1079
D3DXQUATERNION::D3DXQUATERNION( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
1080
{
1081
    x = fx;
1082
    y = fy;
1083
    z = fz;
1084
    w = fw;
1085
}
1086
 
1087
 
1088
// casting
1089
D3DXINLINE
1090
D3DXQUATERNION::operator FLOAT* ()
1091
{
1092
    return (FLOAT *) &x;
1093
}
1094
 
1095
D3DXINLINE
1096
D3DXQUATERNION::operator CONST FLOAT* () const
1097
{
1098
    return (CONST FLOAT *) &x;
1099
}
1100
 
1101
 
1102
// assignment operators
1103
D3DXINLINE D3DXQUATERNION&
1104
D3DXQUATERNION::operator += ( CONST D3DXQUATERNION& q )
1105
{
1106
    x += q.x;
1107
    y += q.y;
1108
    z += q.z;
1109
    w += q.w;
1110
    return *this;
1111
}
1112
 
1113
D3DXINLINE D3DXQUATERNION&
1114
D3DXQUATERNION::operator -= ( CONST D3DXQUATERNION& q )
1115
{
1116
    x -= q.x;
1117
    y -= q.y;
1118
    z -= q.z;
1119
    w -= q.w;
1120
    return *this;
1121
}
1122
 
1123
D3DXINLINE D3DXQUATERNION&
1124
D3DXQUATERNION::operator *= ( CONST D3DXQUATERNION& q )
1125
{
1126
    D3DXQuaternionMultiply(this, this, &q);
1127
    return *this;
1128
}
1129
 
1130
D3DXINLINE D3DXQUATERNION&
1131
D3DXQUATERNION::operator *= ( FLOAT f )
1132
{
1133
    x *= f;
1134
    y *= f;
1135
    z *= f;
1136
    w *= f;
1137
    return *this;
1138
}
1139
 
1140
D3DXINLINE D3DXQUATERNION&
1141
D3DXQUATERNION::operator /= ( FLOAT f )
1142
{
1143
    FLOAT fInv = 1.0f / f;
1144
    x *= fInv;
1145
    y *= fInv;
1146
    z *= fInv;
1147
    w *= fInv;
1148
    return *this;
1149
}
1150
 
1151
 
1152
// unary operators
1153
D3DXINLINE D3DXQUATERNION
1154
D3DXQUATERNION::operator + () const
1155
{
1156
    return *this;
1157
}
1158
 
1159
D3DXINLINE D3DXQUATERNION
1160
D3DXQUATERNION::operator - () const
1161
{
1162
    return D3DXQUATERNION(-x, -y, -z, -w);
1163
}
1164
 
1165
 
1166
// binary operators
1167
D3DXINLINE D3DXQUATERNION
1168
D3DXQUATERNION::operator + ( CONST D3DXQUATERNION& q ) const
1169
{
1170
    return D3DXQUATERNION(x + q.x, y + q.y, z + q.z, w + q.w);
1171
}
1172
 
1173
D3DXINLINE D3DXQUATERNION
1174
D3DXQUATERNION::operator - ( CONST D3DXQUATERNION& q ) const
1175
{
1176
    return D3DXQUATERNION(x - q.x, y - q.y, z - q.z, w - q.w);
1177
}
1178
 
1179
D3DXINLINE D3DXQUATERNION
1180
D3DXQUATERNION::operator * ( CONST D3DXQUATERNION& q ) const
1181
{
1182
    D3DXQUATERNION qT;
1183
    D3DXQuaternionMultiply(&qT, this, &q);
1184
    return qT;
1185
}
1186
 
1187
D3DXINLINE D3DXQUATERNION
1188
D3DXQUATERNION::operator * ( FLOAT f ) const
1189
{
1190
    return D3DXQUATERNION(x * f, y * f, z * f, w * f);
1191
}
1192
 
1193
D3DXINLINE D3DXQUATERNION
1194
D3DXQUATERNION::operator / ( FLOAT f ) const
1195
{
1196
    FLOAT fInv = 1.0f / f;
1197
    return D3DXQUATERNION(x * fInv, y * fInv, z * fInv, w * fInv);
1198
}
1199
 
1200
 
1201
D3DXINLINE D3DXQUATERNION
1202
operator * (FLOAT f, CONST D3DXQUATERNION& q )
1203
{
1204
    return D3DXQUATERNION(f * q.x, f * q.y, f * q.z, f * q.w);
1205
}
1206
 
1207
 
1208
D3DXINLINE BOOL
1209
D3DXQUATERNION::operator == ( CONST D3DXQUATERNION& q ) const
1210
{
1211
    return x == q.x && y == q.y && z == q.z && w == q.w;
1212
}
1213
 
1214
D3DXINLINE BOOL
1215
D3DXQUATERNION::operator != ( CONST D3DXQUATERNION& q ) const
1216
{
1217
    return x != q.x || y != q.y || z != q.z || w != q.w;
1218
}
1219
 
1220
 
1221
 
1222
//--------------------------
1223
// Plane
1224
//--------------------------
1225
 
1226
D3DXINLINE
1227
D3DXPLANE::D3DXPLANE( CONST FLOAT* pf )
1228
{
1229
#ifdef D3DX_DEBUG
1230
    if(!pf)
1231
        return;
1232
#endif
1233
 
1234
    a = pf[0];
1235
    b = pf[1];
1236
    c = pf[2];
1237
    d = pf[3];
1238
}
1239
 
1240
D3DXINLINE
1241
D3DXPLANE::D3DXPLANE( CONST D3DXFLOAT16* pf )
1242
{
1243
#ifdef D3DX_DEBUG
1244
    if(!pf)
1245
        return;
1246
#endif
1247
 
1248
    D3DXFloat16To32Array(&a, pf, 4);
1249
}
1250
 
1251
D3DXINLINE
1252
D3DXPLANE::D3DXPLANE( FLOAT fa, FLOAT fb, FLOAT fc, FLOAT fd )
1253
{
1254
    a = fa;
1255
    b = fb;
1256
    c = fc;
1257
    d = fd;
1258
}
1259
 
1260
 
1261
// casting
1262
D3DXINLINE
1263
D3DXPLANE::operator FLOAT* ()
1264
{
1265
    return (FLOAT *) &a;
1266
}
1267
 
1268
D3DXINLINE
1269
D3DXPLANE::operator CONST FLOAT* () const
1270
{
1271
    return (CONST FLOAT *) &a;
1272
}
1273
 
1274
 
1275
// assignment operators
1276
D3DXINLINE D3DXPLANE&
1277
D3DXPLANE::operator *= ( FLOAT f )
1278
{
1279
    a *= f;
1280
    b *= f;
1281
    c *= f;
1282
    d *= f;
1283
    return *this;
1284
}
1285
 
1286
D3DXINLINE D3DXPLANE&
1287
D3DXPLANE::operator /= ( FLOAT f )
1288
{
1289
    FLOAT fInv = 1.0f / f;
1290
    a *= fInv;
1291
    b *= fInv;
1292
    c *= fInv;
1293
    d *= fInv;
1294
    return *this;
1295
}
1296
 
1297
 
1298
// unary operators
1299
D3DXINLINE D3DXPLANE
1300
D3DXPLANE::operator + () const
1301
{
1302
    return *this;
1303
}
1304
 
1305
D3DXINLINE D3DXPLANE
1306
D3DXPLANE::operator - () const
1307
{
1308
    return D3DXPLANE(-a, -b, -c, -d);
1309
}
1310
 
1311
 
1312
// binary operators
1313
D3DXINLINE D3DXPLANE
1314
D3DXPLANE::operator * ( FLOAT f ) const
1315
{
1316
    return D3DXPLANE(a * f, b * f, c * f, d * f);
1317
}
1318
 
1319
D3DXINLINE D3DXPLANE
1320
D3DXPLANE::operator / ( FLOAT f ) const
1321
{
1322
    FLOAT fInv = 1.0f / f;
1323
    return D3DXPLANE(a * fInv, b * fInv, c * fInv, d * fInv);
1324
}
1325
 
1326
D3DXINLINE D3DXPLANE
1327
operator * (FLOAT f, CONST D3DXPLANE& p )
1328
{
1329
    return D3DXPLANE(f * p.a, f * p.b, f * p.c, f * p.d);
1330
}
1331
 
1332
D3DXINLINE BOOL
1333
D3DXPLANE::operator == ( CONST D3DXPLANE& p ) const
1334
{
1335
    return a == p.a && b == p.b && c == p.c && d == p.d;
1336
}
1337
 
1338
D3DXINLINE BOOL
1339
D3DXPLANE::operator != ( CONST D3DXPLANE& p ) const
1340
{
1341
    return a != p.a || b != p.b || c != p.c || d != p.d;
1342
}
1343
 
1344
 
1345
 
1346
 
1347
//--------------------------
1348
// Color
1349
//--------------------------
1350
 
1351
D3DXINLINE
1352
D3DXCOLOR::D3DXCOLOR( DWORD dw )
1353
{
1354
    CONST FLOAT f = 1.0f / 255.0f;
1355
    r = f * (FLOAT) (unsigned char) (dw >> 16);
1356
    g = f * (FLOAT) (unsigned char) (dw >>  8);
1357
    b = f * (FLOAT) (unsigned char) (dw >>  0);
1358
    a = f * (FLOAT) (unsigned char) (dw >> 24);
1359
}
1360
 
1361
D3DXINLINE
1362
D3DXCOLOR::D3DXCOLOR( CONST FLOAT* pf )
1363
{
1364
#ifdef D3DX_DEBUG
1365
    if(!pf)
1366
        return;
1367
#endif
1368
 
1369
    r = pf[0];
1370
    g = pf[1];
1371
    b = pf[2];
1372
    a = pf[3];
1373
}
1374
 
1375
D3DXINLINE
1376
D3DXCOLOR::D3DXCOLOR( CONST D3DXFLOAT16* pf )
1377
{
1378
#ifdef D3DX_DEBUG
1379
    if(!pf)
1380
        return;
1381
#endif
1382
 
1383
    D3DXFloat16To32Array(&r, pf, 4);
1384
}
1385
 
1386
D3DXINLINE
1387
D3DXCOLOR::D3DXCOLOR( CONST D3DCOLORVALUE& c )
1388
{
1389
    r = c.r;
1390
    g = c.g;
1391
    b = c.b;
1392
    a = c.a;
1393
}
1394
 
1395
D3DXINLINE
1396
D3DXCOLOR::D3DXCOLOR( FLOAT fr, FLOAT fg, FLOAT fb, FLOAT fa )
1397
{
1398
    r = fr;
1399
    g = fg;
1400
    b = fb;
1401
    a = fa;
1402
}
1403
 
1404
 
1405
// casting
1406
D3DXINLINE
1407
D3DXCOLOR::operator DWORD () const
1408
{
1409
    DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
1410
    DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
1411
    DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
1412
    DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
1413
 
1414
    return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
1415
}
1416
 
1417
 
1418
D3DXINLINE
1419
D3DXCOLOR::operator FLOAT * ()
1420
{
1421
    return (FLOAT *) &r;
1422
}
1423
 
1424
D3DXINLINE
1425
D3DXCOLOR::operator CONST FLOAT * () const
1426
{
1427
    return (CONST FLOAT *) &r;
1428
}
1429
 
1430
 
1431
D3DXINLINE
1432
D3DXCOLOR::operator D3DCOLORVALUE * ()
1433
{
1434
    return (D3DCOLORVALUE *) &r;
1435
}
1436
 
1437
D3DXINLINE
1438
D3DXCOLOR::operator CONST D3DCOLORVALUE * () const
1439
{
1440
    return (CONST D3DCOLORVALUE *) &r;
1441
}
1442
 
1443
 
1444
D3DXINLINE
1445
D3DXCOLOR::operator D3DCOLORVALUE& ()
1446
{
1447
    return *((D3DCOLORVALUE *) &r);
1448
}
1449
 
1450
D3DXINLINE
1451
D3DXCOLOR::operator CONST D3DCOLORVALUE& () const
1452
{
1453
    return *((CONST D3DCOLORVALUE *) &r);
1454
}
1455
 
1456
 
1457
// assignment operators
1458
D3DXINLINE D3DXCOLOR&
1459
D3DXCOLOR::operator += ( CONST D3DXCOLOR& c )
1460
{
1461
    r += c.r;
1462
    g += c.g;
1463
    b += c.b;
1464
    a += c.a;
1465
    return *this;
1466
}
1467
 
1468
D3DXINLINE D3DXCOLOR&
1469
D3DXCOLOR::operator -= ( CONST D3DXCOLOR& c )
1470
{
1471
    r -= c.r;
1472
    g -= c.g;
1473
    b -= c.b;
1474
    a -= c.a;
1475
    return *this;
1476
}
1477
 
1478
D3DXINLINE D3DXCOLOR&
1479
D3DXCOLOR::operator *= ( FLOAT f )
1480
{
1481
    r *= f;
1482
    g *= f;
1483
    b *= f;
1484
    a *= f;
1485
    return *this;
1486
}
1487
 
1488
D3DXINLINE D3DXCOLOR&
1489
D3DXCOLOR::operator /= ( FLOAT f )
1490
{
1491
    FLOAT fInv = 1.0f / f;
1492
    r *= fInv;
1493
    g *= fInv;
1494
    b *= fInv;
1495
    a *= fInv;
1496
    return *this;
1497
}
1498
 
1499
 
1500
// unary operators
1501
D3DXINLINE D3DXCOLOR
1502
D3DXCOLOR::operator + () const
1503
{
1504
    return *this;
1505
}
1506
 
1507
D3DXINLINE D3DXCOLOR
1508
D3DXCOLOR::operator - () const
1509
{
1510
    return D3DXCOLOR(-r, -g, -b, -a);
1511
}
1512
 
1513
 
1514
// binary operators
1515
D3DXINLINE D3DXCOLOR
1516
D3DXCOLOR::operator + ( CONST D3DXCOLOR& c ) const
1517
{
1518
    return D3DXCOLOR(r + c.r, g + c.g, b + c.b, a + c.a);
1519
}
1520
 
1521
D3DXINLINE D3DXCOLOR
1522
D3DXCOLOR::operator - ( CONST D3DXCOLOR& c ) const
1523
{
1524
    return D3DXCOLOR(r - c.r, g - c.g, b - c.b, a - c.a);
1525
}
1526
 
1527
D3DXINLINE D3DXCOLOR
1528
D3DXCOLOR::operator * ( FLOAT f ) const
1529
{
1530
    return D3DXCOLOR(r * f, g * f, b * f, a * f);
1531
}
1532
 
1533
D3DXINLINE D3DXCOLOR
1534
D3DXCOLOR::operator / ( FLOAT f ) const
1535
{
1536
    FLOAT fInv = 1.0f / f;
1537
    return D3DXCOLOR(r * fInv, g * fInv, b * fInv, a * fInv);
1538
}
1539
 
1540
 
1541
D3DXINLINE D3DXCOLOR
1542
operator * (FLOAT f, CONST D3DXCOLOR& c )
1543
{
1544
    return D3DXCOLOR(f * c.r, f * c.g, f * c.b, f * c.a);
1545
}
1546
 
1547
 
1548
D3DXINLINE BOOL
1549
D3DXCOLOR::operator == ( CONST D3DXCOLOR& c ) const
1550
{
1551
    return r == c.r && g == c.g && b == c.b && a == c.a;
1552
}
1553
 
1554
D3DXINLINE BOOL
1555
D3DXCOLOR::operator != ( CONST D3DXCOLOR& c ) const
1556
{
1557
    return r != c.r || g != c.g || b != c.b || a != c.a;
1558
}
1559
 
1560
 
1561
#endif //__cplusplus
1562
 
1563
 
1564
 
1565
//===========================================================================
1566
//
1567
// Inline functions
1568
//
1569
//===========================================================================
1570
 
1571
 
1572
//--------------------------
1573
// 2D Vector
1574
//--------------------------
1575
 
1576
D3DXINLINE FLOAT D3DXVec2Length
1577
    ( CONST D3DXVECTOR2 *pV )
1578
{
1579
#ifdef D3DX_DEBUG
1580
    if(!pV)
1581
        return 0.0f;
1582
#endif
1583
 
1584
#ifdef __cplusplus
1585
    return sqrtf(pV->x * pV->x + pV->y * pV->y);
1586
#else
1587
    return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y);
1588
#endif
1589
}
1590
 
1591
D3DXINLINE FLOAT D3DXVec2LengthSq
1592
    ( CONST D3DXVECTOR2 *pV )
1593
{
1594
#ifdef D3DX_DEBUG
1595
    if(!pV)
1596
        return 0.0f;
1597
#endif
1598
 
1599
    return pV->x * pV->x + pV->y * pV->y;
1600
}
1601
 
1602
D3DXINLINE FLOAT D3DXVec2Dot
1603
    ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1604
{
1605
#ifdef D3DX_DEBUG
1606
    if(!pV1 || !pV2)
1607
        return 0.0f;
1608
#endif
1609
 
1610
    return pV1->x * pV2->x + pV1->y * pV2->y;
1611
}
1612
 
1613
D3DXINLINE FLOAT D3DXVec2CCW
1614
    ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1615
{
1616
#ifdef D3DX_DEBUG
1617
    if(!pV1 || !pV2)
1618
        return 0.0f;
1619
#endif
1620
 
1621
    return pV1->x * pV2->y - pV1->y * pV2->x;
1622
}
1623
 
1624
D3DXINLINE D3DXVECTOR2* D3DXVec2Add
1625
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1626
{
1627
#ifdef D3DX_DEBUG
1628
    if(!pOut || !pV1 || !pV2)
1629
        return NULL;
1630
#endif
1631
 
1632
    pOut->x = pV1->x + pV2->x;
1633
    pOut->y = pV1->y + pV2->y;
1634
    return pOut;
1635
}
1636
 
1637
D3DXINLINE D3DXVECTOR2* D3DXVec2Subtract
1638
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1639
{
1640
#ifdef D3DX_DEBUG
1641
    if(!pOut || !pV1 || !pV2)
1642
        return NULL;
1643
#endif
1644
 
1645
    pOut->x = pV1->x - pV2->x;
1646
    pOut->y = pV1->y - pV2->y;
1647
    return pOut;
1648
}
1649
 
1650
D3DXINLINE D3DXVECTOR2* D3DXVec2Minimize
1651
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1652
{
1653
#ifdef D3DX_DEBUG
1654
    if(!pOut || !pV1 || !pV2)
1655
        return NULL;
1656
#endif
1657
 
1658
    pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1659
    pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1660
    return pOut;
1661
}
1662
 
1663
D3DXINLINE D3DXVECTOR2* D3DXVec2Maximize
1664
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
1665
{
1666
#ifdef D3DX_DEBUG
1667
    if(!pOut || !pV1 || !pV2)
1668
        return NULL;
1669
#endif
1670
 
1671
    pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1672
    pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1673
    return pOut;
1674
}
1675
 
1676
D3DXINLINE D3DXVECTOR2* D3DXVec2Scale
1677
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s )
1678
{
1679
#ifdef D3DX_DEBUG
1680
    if(!pOut || !pV)
1681
        return NULL;
1682
#endif
1683
 
1684
    pOut->x = pV->x * s;
1685
    pOut->y = pV->y * s;
1686
    return pOut;
1687
}
1688
 
1689
D3DXINLINE D3DXVECTOR2* D3DXVec2Lerp
1690
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
1691
      FLOAT s )
1692
{
1693
#ifdef D3DX_DEBUG
1694
    if(!pOut || !pV1 || !pV2)
1695
        return NULL;
1696
#endif
1697
 
1698
    pOut->x = pV1->x + s * (pV2->x - pV1->x);
1699
    pOut->y = pV1->y + s * (pV2->y - pV1->y);
1700
    return pOut;
1701
}
1702
 
1703
 
1704
//--------------------------
1705
// 3D Vector
1706
//--------------------------
1707
 
1708
D3DXINLINE FLOAT D3DXVec3Length
1709
    ( CONST D3DXVECTOR3 *pV )
1710
{
1711
#ifdef D3DX_DEBUG
1712
    if(!pV)
1713
        return 0.0f;
1714
#endif
1715
 
1716
#ifdef __cplusplus
1717
    return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
1718
#else
1719
    return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
1720
#endif
1721
}
1722
 
1723
D3DXINLINE FLOAT D3DXVec3LengthSq
1724
    ( CONST D3DXVECTOR3 *pV )
1725
{
1726
#ifdef D3DX_DEBUG
1727
    if(!pV)
1728
        return 0.0f;
1729
#endif
1730
 
1731
    return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z;
1732
}
1733
 
1734
D3DXINLINE FLOAT D3DXVec3Dot
1735
    ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1736
{
1737
#ifdef D3DX_DEBUG
1738
    if(!pV1 || !pV2)
1739
        return 0.0f;
1740
#endif
1741
 
1742
    return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
1743
}
1744
 
1745
D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
1746
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1747
{
1748
    D3DXVECTOR3 v;
1749
 
1750
#ifdef D3DX_DEBUG
1751
    if(!pOut || !pV1 || !pV2)
1752
        return NULL;
1753
#endif
1754
 
1755
    v.x = pV1->y * pV2->z - pV1->z * pV2->y;
1756
    v.y = pV1->z * pV2->x - pV1->x * pV2->z;
1757
    v.z = pV1->x * pV2->y - pV1->y * pV2->x;
1758
 
1759
    *pOut = v;
1760
    return pOut;
1761
}
1762
 
1763
D3DXINLINE D3DXVECTOR3* D3DXVec3Add
1764
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1765
{
1766
#ifdef D3DX_DEBUG
1767
    if(!pOut || !pV1 || !pV2)
1768
        return NULL;
1769
#endif
1770
 
1771
    pOut->x = pV1->x + pV2->x;
1772
    pOut->y = pV1->y + pV2->y;
1773
    pOut->z = pV1->z + pV2->z;
1774
    return pOut;
1775
}
1776
 
1777
D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract
1778
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1779
{
1780
#ifdef D3DX_DEBUG
1781
    if(!pOut || !pV1 || !pV2)
1782
        return NULL;
1783
#endif
1784
 
1785
    pOut->x = pV1->x - pV2->x;
1786
    pOut->y = pV1->y - pV2->y;
1787
    pOut->z = pV1->z - pV2->z;
1788
    return pOut;
1789
}
1790
 
1791
D3DXINLINE D3DXVECTOR3* D3DXVec3Minimize
1792
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1793
{
1794
#ifdef D3DX_DEBUG
1795
    if(!pOut || !pV1 || !pV2)
1796
        return NULL;
1797
#endif
1798
 
1799
    pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1800
    pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1801
    pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
1802
    return pOut;
1803
}
1804
 
1805
D3DXINLINE D3DXVECTOR3* D3DXVec3Maximize
1806
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
1807
{
1808
#ifdef D3DX_DEBUG
1809
    if(!pOut || !pV1 || !pV2)
1810
        return NULL;
1811
#endif
1812
 
1813
    pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1814
    pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1815
    pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
1816
    return pOut;
1817
}
1818
 
1819
D3DXINLINE D3DXVECTOR3* D3DXVec3Scale
1820
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s)
1821
{
1822
#ifdef D3DX_DEBUG
1823
    if(!pOut || !pV)
1824
        return NULL;
1825
#endif
1826
 
1827
    pOut->x = pV->x * s;
1828
    pOut->y = pV->y * s;
1829
    pOut->z = pV->z * s;
1830
    return pOut;
1831
}
1832
 
1833
D3DXINLINE D3DXVECTOR3* D3DXVec3Lerp
1834
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
1835
      FLOAT s )
1836
{
1837
#ifdef D3DX_DEBUG
1838
    if(!pOut || !pV1 || !pV2)
1839
        return NULL;
1840
#endif
1841
 
1842
    pOut->x = pV1->x + s * (pV2->x - pV1->x);
1843
    pOut->y = pV1->y + s * (pV2->y - pV1->y);
1844
    pOut->z = pV1->z + s * (pV2->z - pV1->z);
1845
    return pOut;
1846
}
1847
 
1848
 
1849
//--------------------------
1850
// 4D Vector
1851
//--------------------------
1852
 
1853
D3DXINLINE FLOAT D3DXVec4Length
1854
    ( CONST D3DXVECTOR4 *pV )
1855
{
1856
#ifdef D3DX_DEBUG
1857
    if(!pV)
1858
        return 0.0f;
1859
#endif
1860
 
1861
#ifdef __cplusplus
1862
    return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
1863
#else
1864
    return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
1865
#endif
1866
}
1867
 
1868
D3DXINLINE FLOAT D3DXVec4LengthSq
1869
    ( CONST D3DXVECTOR4 *pV )
1870
{
1871
#ifdef D3DX_DEBUG
1872
    if(!pV)
1873
        return 0.0f;
1874
#endif
1875
 
1876
    return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w;
1877
}
1878
 
1879
D3DXINLINE FLOAT D3DXVec4Dot
1880
    ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 )
1881
{
1882
#ifdef D3DX_DEBUG
1883
    if(!pV1 || !pV2)
1884
        return 0.0f;
1885
#endif
1886
 
1887
    return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w;
1888
}
1889
 
1890
D3DXINLINE D3DXVECTOR4* D3DXVec4Add
1891
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
1892
{
1893
#ifdef D3DX_DEBUG
1894
    if(!pOut || !pV1 || !pV2)
1895
        return NULL;
1896
#endif
1897
 
1898
    pOut->x = pV1->x + pV2->x;
1899
    pOut->y = pV1->y + pV2->y;
1900
    pOut->z = pV1->z + pV2->z;
1901
    pOut->w = pV1->w + pV2->w;
1902
    return pOut;
1903
}
1904
 
1905
D3DXINLINE D3DXVECTOR4* D3DXVec4Subtract
1906
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
1907
{
1908
#ifdef D3DX_DEBUG
1909
    if(!pOut || !pV1 || !pV2)
1910
        return NULL;
1911
#endif
1912
 
1913
    pOut->x = pV1->x - pV2->x;
1914
    pOut->y = pV1->y - pV2->y;
1915
    pOut->z = pV1->z - pV2->z;
1916
    pOut->w = pV1->w - pV2->w;
1917
    return pOut;
1918
}
1919
 
1920
D3DXINLINE D3DXVECTOR4* D3DXVec4Minimize
1921
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
1922
{
1923
#ifdef D3DX_DEBUG
1924
    if(!pOut || !pV1 || !pV2)
1925
        return NULL;
1926
#endif
1927
 
1928
    pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
1929
    pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
1930
    pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
1931
    pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w;
1932
    return pOut;
1933
}
1934
 
1935
D3DXINLINE D3DXVECTOR4* D3DXVec4Maximize
1936
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
1937
{
1938
#ifdef D3DX_DEBUG
1939
    if(!pOut || !pV1 || !pV2)
1940
        return NULL;
1941
#endif
1942
 
1943
    pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
1944
    pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
1945
    pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
1946
    pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w;
1947
    return pOut;
1948
}
1949
 
1950
D3DXINLINE D3DXVECTOR4* D3DXVec4Scale
1951
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s)
1952
{
1953
#ifdef D3DX_DEBUG
1954
    if(!pOut || !pV)
1955
        return NULL;
1956
#endif
1957
 
1958
    pOut->x = pV->x * s;
1959
    pOut->y = pV->y * s;
1960
    pOut->z = pV->z * s;
1961
    pOut->w = pV->w * s;
1962
    return pOut;
1963
}
1964
 
1965
D3DXINLINE D3DXVECTOR4* D3DXVec4Lerp
1966
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
1967
      FLOAT s )
1968
{
1969
#ifdef D3DX_DEBUG
1970
    if(!pOut || !pV1 || !pV2)
1971
        return NULL;
1972
#endif
1973
 
1974
    pOut->x = pV1->x + s * (pV2->x - pV1->x);
1975
    pOut->y = pV1->y + s * (pV2->y - pV1->y);
1976
    pOut->z = pV1->z + s * (pV2->z - pV1->z);
1977
    pOut->w = pV1->w + s * (pV2->w - pV1->w);
1978
    return pOut;
1979
}
1980
 
1981
 
1982
//--------------------------
1983
// 4D Matrix
1984
//--------------------------
1985
 
1986
D3DXINLINE D3DXMATRIX* D3DXMatrixIdentity
1987
    ( D3DXMATRIX *pOut )
1988
{
1989
#ifdef D3DX_DEBUG
1990
    if(!pOut)
1991
        return NULL;
1992
#endif
1993
 
1994
    pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] =
1995
    pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] =
1996
    pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
1997
    pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
1998
 
1999
    pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f;
2000
    return pOut;
2001
}
2002
 
2003
 
2004
D3DXINLINE BOOL D3DXMatrixIsIdentity
2005
    ( CONST D3DXMATRIX *pM )
2006
{
2007
#ifdef D3DX_DEBUG
2008
    if(!pM)
2009
        return FALSE;
2010
#endif
2011
 
2012
    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 &&
2013
           pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f &&
2014
           pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f &&
2015
           pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f;
2016
}
2017
 
2018
 
2019
//--------------------------
2020
// Quaternion
2021
//--------------------------
2022
 
2023
D3DXINLINE FLOAT D3DXQuaternionLength
2024
    ( CONST D3DXQUATERNION *pQ )
2025
{
2026
#ifdef D3DX_DEBUG
2027
    if(!pQ)
2028
        return 0.0f;
2029
#endif
2030
 
2031
#ifdef __cplusplus
2032
    return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
2033
#else
2034
    return (FLOAT) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
2035
#endif
2036
}
2037
 
2038
D3DXINLINE FLOAT D3DXQuaternionLengthSq
2039
    ( CONST D3DXQUATERNION *pQ )
2040
{
2041
#ifdef D3DX_DEBUG
2042
    if(!pQ)
2043
        return 0.0f;
2044
#endif
2045
 
2046
    return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w;
2047
}
2048
 
2049
D3DXINLINE FLOAT D3DXQuaternionDot
2050
    ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 )
2051
{
2052
#ifdef D3DX_DEBUG
2053
    if(!pQ1 || !pQ2)
2054
        return 0.0f;
2055
#endif
2056
 
2057
    return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w;
2058
}
2059
 
2060
 
2061
D3DXINLINE D3DXQUATERNION* D3DXQuaternionIdentity
2062
    ( D3DXQUATERNION *pOut )
2063
{
2064
#ifdef D3DX_DEBUG
2065
    if(!pOut)
2066
        return NULL;
2067
#endif
2068
 
2069
    pOut->x = pOut->y = pOut->z = 0.0f;
2070
    pOut->w = 1.0f;
2071
    return pOut;
2072
}
2073
 
2074
D3DXINLINE BOOL D3DXQuaternionIsIdentity
2075
    ( CONST D3DXQUATERNION *pQ )
2076
{
2077
#ifdef D3DX_DEBUG
2078
    if(!pQ)
2079
        return FALSE;
2080
#endif
2081
 
2082
    return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f;
2083
}
2084
 
2085
 
2086
D3DXINLINE D3DXQUATERNION* D3DXQuaternionConjugate
2087
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ )
2088
{
2089
#ifdef D3DX_DEBUG
2090
    if(!pOut || !pQ)
2091
        return NULL;
2092
#endif
2093
 
2094
    pOut->x = -pQ->x;
2095
    pOut->y = -pQ->y;
2096
    pOut->z = -pQ->z;
2097
    pOut->w =  pQ->w;
2098
    return pOut;
2099
}
2100
 
2101
 
2102
//--------------------------
2103
// Plane
2104
//--------------------------
2105
 
2106
D3DXINLINE FLOAT D3DXPlaneDot
2107
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV)
2108
{
2109
#ifdef D3DX_DEBUG
2110
    if(!pP || !pV)
2111
        return 0.0f;
2112
#endif
2113
 
2114
    return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w;
2115
}
2116
 
2117
D3DXINLINE FLOAT D3DXPlaneDotCoord
2118
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
2119
{
2120
#ifdef D3DX_DEBUG
2121
    if(!pP || !pV)
2122
        return 0.0f;
2123
#endif
2124
 
2125
    return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
2126
}
2127
 
2128
D3DXINLINE FLOAT D3DXPlaneDotNormal
2129
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
2130
{
2131
#ifdef D3DX_DEBUG
2132
    if(!pP || !pV)
2133
        return 0.0f;
2134
#endif
2135
 
2136
    return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z;
2137
}
2138
 
2139
D3DXINLINE D3DXPLANE* D3DXPlaneScale
2140
    (D3DXPLANE *pOut, CONST D3DXPLANE *pP, FLOAT s)
2141
{
2142
#ifdef D3DX_DEBUG
2143
    if(!pOut || !pP)
2144
        return NULL;
2145
#endif
2146
 
2147
    pOut->a = pP->a * s;
2148
    pOut->b = pP->b * s;
2149
    pOut->c = pP->c * s;
2150
    pOut->d = pP->d * s;
2151
    return pOut;
2152
}
2153
 
2154
 
2155
//--------------------------
2156
// Color
2157
//--------------------------
2158
 
2159
D3DXINLINE D3DXCOLOR* D3DXColorNegative
2160
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC)
2161
{
2162
#ifdef D3DX_DEBUG
2163
    if(!pOut || !pC)
2164
        return NULL;
2165
#endif
2166
 
2167
    pOut->r = 1.0f - pC->r;
2168
    pOut->g = 1.0f - pC->g;
2169
    pOut->b = 1.0f - pC->b;
2170
    pOut->a = pC->a;
2171
    return pOut;
2172
}
2173
 
2174
D3DXINLINE D3DXCOLOR* D3DXColorAdd
2175
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
2176
{
2177
#ifdef D3DX_DEBUG
2178
    if(!pOut || !pC1 || !pC2)
2179
        return NULL;
2180
#endif
2181
 
2182
    pOut->r = pC1->r + pC2->r;
2183
    pOut->g = pC1->g + pC2->g;
2184
    pOut->b = pC1->b + pC2->b;
2185
    pOut->a = pC1->a + pC2->a;
2186
    return pOut;
2187
}
2188
 
2189
D3DXINLINE D3DXCOLOR* D3DXColorSubtract
2190
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
2191
{
2192
#ifdef D3DX_DEBUG
2193
    if(!pOut || !pC1 || !pC2)
2194
        return NULL;
2195
#endif
2196
 
2197
    pOut->r = pC1->r - pC2->r;
2198
    pOut->g = pC1->g - pC2->g;
2199
    pOut->b = pC1->b - pC2->b;
2200
    pOut->a = pC1->a - pC2->a;
2201
    return pOut;
2202
}
2203
 
2204
D3DXINLINE D3DXCOLOR* D3DXColorScale
2205
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s)
2206
{
2207
#ifdef D3DX_DEBUG
2208
    if(!pOut || !pC)
2209
        return NULL;
2210
#endif
2211
 
2212
    pOut->r = pC->r * s;
2213
    pOut->g = pC->g * s;
2214
    pOut->b = pC->b * s;
2215
    pOut->a = pC->a * s;
2216
    return pOut;
2217
}
2218
 
2219
D3DXINLINE D3DXCOLOR* D3DXColorModulate
2220
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
2221
{
2222
#ifdef D3DX_DEBUG
2223
    if(!pOut || !pC1 || !pC2)
2224
        return NULL;
2225
#endif
2226
 
2227
    pOut->r = pC1->r * pC2->r;
2228
    pOut->g = pC1->g * pC2->g;
2229
    pOut->b = pC1->b * pC2->b;
2230
    pOut->a = pC1->a * pC2->a;
2231
    return pOut;
2232
}
2233
 
2234
D3DXINLINE D3DXCOLOR* D3DXColorLerp
2235
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s)
2236
{
2237
#ifdef D3DX_DEBUG
2238
    if(!pOut || !pC1 || !pC2)
2239
        return NULL;
2240
#endif
2241
 
2242
    pOut->r = pC1->r + s * (pC2->r - pC1->r);
2243
    pOut->g = pC1->g + s * (pC2->g - pC1->g);
2244
    pOut->b = pC1->b + s * (pC2->b - pC1->b);
2245
    pOut->a = pC1->a + s * (pC2->a - pC1->a);
2246
    return pOut;
2247
}
2248
 
2249
 
2250
#endif // __D3DX9MATH_INL__
2251