-
Notifications
You must be signed in to change notification settings - Fork 3
/
d3dx9math.h
1796 lines (1412 loc) · 56.5 KB
/
d3dx9math.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
// File: d3dx9math.h
// Content: D3DX math types and functions
//
//////////////////////////////////////////////////////////////////////////////
#include "d3dx9.h"
#ifndef __D3DX9MATH_H__
#define __D3DX9MATH_H__
#include <math.h>
#if _MSC_VER >= 1200
#pragma warning(push)
#endif
#pragma warning(disable:4201) // anonymous unions warning
//===========================================================================
//
// General purpose utilities
//
//===========================================================================
#define D3DX_PI ((FLOAT) 3.141592654f)
#define D3DX_1BYPI ((FLOAT) 0.318309886f)
#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
#define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
//===========================================================================
//
// 16 bit floating point numbers
//
//===========================================================================
#define D3DX_16F_DIG 3 // # of decimal digits of precision
#define D3DX_16F_EPSILON 4.8875809e-4f // smallest such that 1.0 + epsilon != 1.0
#define D3DX_16F_MANT_DIG 11 // # of bits in mantissa
#define D3DX_16F_MAX 6.550400e+004 // max value
#define D3DX_16F_MAX_10_EXP 4 // max decimal exponent
#define D3DX_16F_MAX_EXP 15 // max binary exponent
#define D3DX_16F_MIN 6.1035156e-5f // min positive value
#define D3DX_16F_MIN_10_EXP (-4) // min decimal exponent
#define D3DX_16F_MIN_EXP (-14) // min binary exponent
#define D3DX_16F_RADIX 2 // exponent radix
#define D3DX_16F_ROUNDS 1 // addition rounding: near
typedef struct D3DXFLOAT16
{
#ifdef __cplusplus
public:
D3DXFLOAT16() {};
D3DXFLOAT16( FLOAT );
D3DXFLOAT16( CONST D3DXFLOAT16& );
// casting
operator FLOAT ();
// binary operators
BOOL operator == ( CONST D3DXFLOAT16& ) const;
BOOL operator != ( CONST D3DXFLOAT16& ) const;
protected:
#endif //__cplusplus
WORD value;
} D3DXFLOAT16, *LPD3DXFLOAT16;
//===========================================================================
//
// Vectors
//
//===========================================================================
//--------------------------
// 2D Vector
//--------------------------
typedef struct D3DXVECTOR2
{
#ifdef __cplusplus
public:
D3DXVECTOR2() {};
D3DXVECTOR2( CONST FLOAT * );
D3DXVECTOR2( CONST D3DXFLOAT16 * );
D3DXVECTOR2( FLOAT x, FLOAT y );
// casting
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& );
D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& );
D3DXVECTOR2& operator *= ( FLOAT );
D3DXVECTOR2& operator /= ( FLOAT );
// unary operators
D3DXVECTOR2 operator + () const;
D3DXVECTOR2 operator - () const;
// binary operators
D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const;
D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const;
D3DXVECTOR2 operator * ( FLOAT ) const;
D3DXVECTOR2 operator / ( FLOAT ) const;
friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& );
BOOL operator == ( CONST D3DXVECTOR2& ) const;
BOOL operator != ( CONST D3DXVECTOR2& ) const;
public:
#endif //__cplusplus
FLOAT x, y;
} D3DXVECTOR2, *LPD3DXVECTOR2;
//--------------------------
// 2D Vector (16 bit)
//--------------------------
typedef struct D3DXVECTOR2_16F
{
#ifdef __cplusplus
public:
D3DXVECTOR2_16F() {};
D3DXVECTOR2_16F( CONST FLOAT * );
D3DXVECTOR2_16F( CONST D3DXFLOAT16 * );
D3DXVECTOR2_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y );
// casting
operator D3DXFLOAT16* ();
operator CONST D3DXFLOAT16* () const;
// binary operators
BOOL operator == ( CONST D3DXVECTOR2_16F& ) const;
BOOL operator != ( CONST D3DXVECTOR2_16F& ) const;
public:
#endif //__cplusplus
D3DXFLOAT16 x, y;
} D3DXVECTOR2_16F, *LPD3DXVECTOR2_16F;
//--------------------------
// 3D Vector
//--------------------------
#ifdef __cplusplus
typedef struct D3DXVECTOR3 : public D3DVECTOR
{
public:
D3DXVECTOR3() {};
D3DXVECTOR3( CONST FLOAT * );
D3DXVECTOR3( CONST D3DVECTOR& );
D3DXVECTOR3( CONST D3DXFLOAT16 * );
D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );
// casting
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
D3DXVECTOR3& operator *= ( FLOAT );
D3DXVECTOR3& operator /= ( FLOAT );
// unary operators
D3DXVECTOR3 operator + () const;
D3DXVECTOR3 operator - () const;
// binary operators
D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
D3DXVECTOR3 operator * ( FLOAT ) const;
D3DXVECTOR3 operator / ( FLOAT ) const;
friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );
BOOL operator == ( CONST D3DXVECTOR3& ) const;
BOOL operator != ( CONST D3DXVECTOR3& ) const;
} D3DXVECTOR3, *LPD3DXVECTOR3;
#else //!__cplusplus
typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
#endif //!__cplusplus
//--------------------------
// 3D Vector (16 bit)
//--------------------------
typedef struct D3DXVECTOR3_16F
{
#ifdef __cplusplus
public:
D3DXVECTOR3_16F() {};
D3DXVECTOR3_16F( CONST FLOAT * );
D3DXVECTOR3_16F( CONST D3DVECTOR& );
D3DXVECTOR3_16F( CONST D3DXFLOAT16 * );
D3DXVECTOR3_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y, CONST D3DXFLOAT16 &z );
// casting
operator D3DXFLOAT16* ();
operator CONST D3DXFLOAT16* () const;
// binary operators
BOOL operator == ( CONST D3DXVECTOR3_16F& ) const;
BOOL operator != ( CONST D3DXVECTOR3_16F& ) const;
public:
#endif //__cplusplus
D3DXFLOAT16 x, y, z;
} D3DXVECTOR3_16F, *LPD3DXVECTOR3_16F;
//--------------------------
// 4D Vector
//--------------------------
typedef struct D3DXVECTOR4
{
#ifdef __cplusplus
public:
D3DXVECTOR4() {};
D3DXVECTOR4( CONST FLOAT* );
D3DXVECTOR4( CONST D3DXFLOAT16* );
D3DXVECTOR4( CONST D3DVECTOR& xyz, FLOAT w );
D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
// casting
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& );
D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& );
D3DXVECTOR4& operator *= ( FLOAT );
D3DXVECTOR4& operator /= ( FLOAT );
// unary operators
D3DXVECTOR4 operator + () const;
D3DXVECTOR4 operator - () const;
// binary operators
D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const;
D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const;
D3DXVECTOR4 operator * ( FLOAT ) const;
D3DXVECTOR4 operator / ( FLOAT ) const;
friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );
BOOL operator == ( CONST D3DXVECTOR4& ) const;
BOOL operator != ( CONST D3DXVECTOR4& ) const;
public:
#endif //__cplusplus
FLOAT x, y, z, w;
} D3DXVECTOR4, *LPD3DXVECTOR4;
//--------------------------
// 4D Vector (16 bit)
//--------------------------
typedef struct D3DXVECTOR4_16F
{
#ifdef __cplusplus
public:
D3DXVECTOR4_16F() {};
D3DXVECTOR4_16F( CONST FLOAT * );
D3DXVECTOR4_16F( CONST D3DXFLOAT16* );
D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& xyz, CONST D3DXFLOAT16& w );
D3DXVECTOR4_16F( CONST D3DXFLOAT16& x, CONST D3DXFLOAT16& y, CONST D3DXFLOAT16& z, CONST D3DXFLOAT16& w );
// casting
operator D3DXFLOAT16* ();
operator CONST D3DXFLOAT16* () const;
// binary operators
BOOL operator == ( CONST D3DXVECTOR4_16F& ) const;
BOOL operator != ( CONST D3DXVECTOR4_16F& ) const;
public:
#endif //__cplusplus
D3DXFLOAT16 x, y, z, w;
} D3DXVECTOR4_16F, *LPD3DXVECTOR4_16F;
//===========================================================================
//
// Matrices
//
//===========================================================================
#ifdef __cplusplus
typedef struct D3DXMATRIX : public D3DMATRIX
{
public:
D3DXMATRIX() {};
D3DXMATRIX( CONST FLOAT * );
D3DXMATRIX( CONST D3DMATRIX& );
D3DXMATRIX( CONST D3DXFLOAT16 * );
D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
// access grants
FLOAT& operator () ( UINT Row, UINT Col );
FLOAT operator () ( UINT Row, UINT Col ) const;
// casting operators
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
D3DXMATRIX& operator *= ( FLOAT );
D3DXMATRIX& operator /= ( FLOAT );
// unary operators
D3DXMATRIX operator + () const;
D3DXMATRIX operator - () const;
// binary operators
D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
D3DXMATRIX operator * ( FLOAT ) const;
D3DXMATRIX operator / ( FLOAT ) const;
friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
BOOL operator == ( CONST D3DXMATRIX& ) const;
BOOL operator != ( CONST D3DXMATRIX& ) const;
} D3DXMATRIX, *LPD3DXMATRIX;
#else //!__cplusplus
typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
#endif //!__cplusplus
//---------------------------------------------------------------------------
// Aligned Matrices
//
// This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
// It aligns matrices on the stack and on the heap or in global scope.
// It does this using __declspec(align(16)) which works on VC7 and on VC 6
// with the processor pack. Unfortunately there is no way to detect the
// latter so this is turned on only on VC7. On other compilers this is the
// the same as D3DXMATRIX.
//
// Using this class on a compiler that does not actually do the alignment
// can be dangerous since it will not expose bugs that ignore alignment.
// E.g if an object of this class in inside a struct or class, and some code
// memcopys data in it assuming tight packing. This could break on a compiler
// that eventually start aligning the matrix.
//---------------------------------------------------------------------------
#ifdef __cplusplus
typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
{
_D3DXMATRIXA16() {}
_D3DXMATRIXA16( CONST FLOAT * );
_D3DXMATRIXA16( CONST D3DMATRIX& );
_D3DXMATRIXA16( CONST D3DXFLOAT16 * );
_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
// new operators
void* operator new ( size_t );
void* operator new[] ( size_t );
// delete operators
void operator delete ( void* ); // These are NOT virtual; Do not
void operator delete[] ( void* ); // cast to D3DXMATRIX and delete.
// assignment operators
_D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
} _D3DXMATRIXA16;
#else //!__cplusplus
typedef D3DXMATRIX _D3DXMATRIXA16;
#endif //!__cplusplus
#if _MSC_VER >= 1300 // VC7
#define D3DX_ALIGN16 __declspec(align(16))
#else
#define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.
#endif
typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;
//===========================================================================
//
// Quaternions
//
//===========================================================================
typedef struct D3DXQUATERNION
{
#ifdef __cplusplus
public:
D3DXQUATERNION() {}
D3DXQUATERNION( CONST FLOAT * );
D3DXQUATERNION( CONST D3DXFLOAT16 * );
D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
// casting
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& );
D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& );
D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& );
D3DXQUATERNION& operator *= ( FLOAT );
D3DXQUATERNION& operator /= ( FLOAT );
// unary operators
D3DXQUATERNION operator + () const;
D3DXQUATERNION operator - () const;
// binary operators
D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const;
D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const;
D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const;
D3DXQUATERNION operator * ( FLOAT ) const;
D3DXQUATERNION operator / ( FLOAT ) const;
friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& );
BOOL operator == ( CONST D3DXQUATERNION& ) const;
BOOL operator != ( CONST D3DXQUATERNION& ) const;
#endif //__cplusplus
FLOAT x, y, z, w;
} D3DXQUATERNION, *LPD3DXQUATERNION;
//===========================================================================
//
// Planes
//
//===========================================================================
typedef struct D3DXPLANE
{
#ifdef __cplusplus
public:
D3DXPLANE() {}
D3DXPLANE( CONST FLOAT* );
D3DXPLANE( CONST D3DXFLOAT16* );
D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );
// casting
operator FLOAT* ();
operator CONST FLOAT* () const;
// assignment operators
D3DXPLANE& operator *= ( FLOAT );
D3DXPLANE& operator /= ( FLOAT );
// unary operators
D3DXPLANE operator + () const;
D3DXPLANE operator - () const;
// binary operators
D3DXPLANE operator * ( FLOAT ) const;
D3DXPLANE operator / ( FLOAT ) const;
friend D3DXPLANE operator * ( FLOAT, CONST D3DXPLANE& );
BOOL operator == ( CONST D3DXPLANE& ) const;
BOOL operator != ( CONST D3DXPLANE& ) const;
#endif //__cplusplus
FLOAT a, b, c, d;
} D3DXPLANE, *LPD3DXPLANE;
//===========================================================================
//
// Colors
//
//===========================================================================
typedef struct D3DXCOLOR
{
#ifdef __cplusplus
public:
D3DXCOLOR() {}
D3DXCOLOR( DWORD argb );
D3DXCOLOR( CONST FLOAT * );
D3DXCOLOR( CONST D3DXFLOAT16 * );
D3DXCOLOR( CONST D3DCOLORVALUE& );
D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
// casting
operator DWORD () const;
operator FLOAT* ();
operator CONST FLOAT* () const;
operator D3DCOLORVALUE* ();
operator CONST D3DCOLORVALUE* () const;
operator D3DCOLORVALUE& ();
operator CONST D3DCOLORVALUE& () const;
// assignment operators
D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
D3DXCOLOR& operator *= ( FLOAT );
D3DXCOLOR& operator /= ( FLOAT );
// unary operators
D3DXCOLOR operator + () const;
D3DXCOLOR operator - () const;
// binary operators
D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
D3DXCOLOR operator * ( FLOAT ) const;
D3DXCOLOR operator / ( FLOAT ) const;
friend D3DXCOLOR operator * ( FLOAT, CONST D3DXCOLOR& );
BOOL operator == ( CONST D3DXCOLOR& ) const;
BOOL operator != ( CONST D3DXCOLOR& ) const;
#endif //__cplusplus
FLOAT r, g, b, a;
} D3DXCOLOR, *LPD3DXCOLOR;
//===========================================================================
//
// D3DX math functions:
//
// NOTE:
// * All these functions can take the same object as in and out parameters.
//
// * Out parameters are typically also returned as return values, so that
// the output of one function may be used as a parameter to another.
//
//===========================================================================
//--------------------------
// Float16
//--------------------------
// non-inline
#ifdef __cplusplus
extern "C" {
#endif
// Converts an array 32-bit floats to 16-bit floats
D3DXFLOAT16* WINAPI D3DXFloat32To16Array
( D3DXFLOAT16 *pOut, CONST FLOAT *pIn, UINT n );
// Converts an array 16-bit floats to 32-bit floats
FLOAT* WINAPI D3DXFloat16To32Array
( FLOAT *pOut, CONST D3DXFLOAT16 *pIn, UINT n );
#ifdef __cplusplus
}
#endif
//--------------------------
// 2D Vector
//--------------------------
// inline
FLOAT D3DXVec2Length
( CONST D3DXVECTOR2 *pV );
FLOAT D3DXVec2LengthSq
( CONST D3DXVECTOR2 *pV );
FLOAT D3DXVec2Dot
( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
// Z component of ((x1,y1,0) cross (x2,y2,0))
FLOAT D3DXVec2CCW
( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
D3DXVECTOR2* D3DXVec2Add
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
D3DXVECTOR2* D3DXVec2Subtract
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
// Minimize each component. x = min(x1, x2), y = min(y1, y2)
D3DXVECTOR2* D3DXVec2Minimize
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
// Maximize each component. x = max(x1, x2), y = max(y1, y2)
D3DXVECTOR2* D3DXVec2Maximize
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
D3DXVECTOR2* D3DXVec2Scale
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s );
// Linear interpolation. V1 + s(V2-V1)
D3DXVECTOR2* D3DXVec2Lerp
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
FLOAT s );
// non-inline
#ifdef __cplusplus
extern "C" {
#endif
D3DXVECTOR2* WINAPI D3DXVec2Normalize
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV );
// Hermite interpolation between position V1, tangent T1 (when s == 0)
// and position V2, tangent T2 (when s == 1).
D3DXVECTOR2* WINAPI D3DXVec2Hermite
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pT1,
CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pT2, FLOAT s );
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
D3DXVECTOR2* WINAPI D3DXVec2CatmullRom
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV0, CONST D3DXVECTOR2 *pV1,
CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pV3, FLOAT s );
// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g);
// Transform (x, y, 0, 1) by matrix.
D3DXVECTOR4* WINAPI D3DXVec2Transform
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
// Transform (x, y, 0, 1) by matrix, project result back into w=1.
D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
// Transform (x, y, 0, 0) by matrix.
D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
// Transform Array (x, y, 0, 1) by matrix.
D3DXVECTOR4* WINAPI D3DXVec2TransformArray
( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n);
// Transform Array (x, y, 0, 1) by matrix, project result back into w=1.
D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray
( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
// Transform Array (x, y, 0, 0) by matrix.
D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray
( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
#ifdef __cplusplus
}
#endif
//--------------------------
// 3D Vector
//--------------------------
// inline
FLOAT D3DXVec3Length
( CONST D3DXVECTOR3 *pV );
FLOAT D3DXVec3LengthSq
( CONST D3DXVECTOR3 *pV );
FLOAT D3DXVec3Dot
( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
D3DXVECTOR3* D3DXVec3Cross
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
D3DXVECTOR3* D3DXVec3Add
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
D3DXVECTOR3* D3DXVec3Subtract
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
// Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
D3DXVECTOR3* D3DXVec3Minimize
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
// Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
D3DXVECTOR3* D3DXVec3Maximize
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
D3DXVECTOR3* D3DXVec3Scale
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s);
// Linear interpolation. V1 + s(V2-V1)
D3DXVECTOR3* D3DXVec3Lerp
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
FLOAT s );
// non-inline
#ifdef __cplusplus
extern "C" {
#endif
D3DXVECTOR3* WINAPI D3DXVec3Normalize
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV );
// Hermite interpolation between position V1, tangent T1 (when s == 0)
// and position V2, tangent T2 (when s == 1).
D3DXVECTOR3* WINAPI D3DXVec3Hermite
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pT1,
CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pT2, FLOAT s );
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
D3DXVECTOR3* WINAPI D3DXVec3CatmullRom
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV0, CONST D3DXVECTOR3 *pV1,
CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pV3, FLOAT s );
// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g);
// Transform (x, y, z, 1) by matrix.
D3DXVECTOR4* WINAPI D3DXVec3Transform
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
// Transform (x, y, z, 1) by matrix, project result back into w=1.
D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
// Transform (x, y, z, 0) by matrix. If you transforming a normal by a
// non-affine matrix, the matrix you pass to this function should be the
// transpose of the inverse of the matrix you would use to transform a coord.
D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
// Transform Array (x, y, z, 1) by matrix.
D3DXVECTOR4* WINAPI D3DXVec3TransformArray
( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
// Transform Array (x, y, z, 1) by matrix, project result back into w=1.
D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray
( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
// Transform (x, y, z, 0) by matrix. If you transforming a normal by a
// non-affine matrix, the matrix you pass to this function should be the
// transpose of the inverse of the matrix you would use to transform a coord.
D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray
( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
// Project vector from object space into screen space
D3DXVECTOR3* WINAPI D3DXVec3Project
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT9 *pViewport,
CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
// Project vector from screen space into object space
D3DXVECTOR3* WINAPI D3DXVec3Unproject
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT9 *pViewport,
CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
// Project vector Array from object space into screen space
D3DXVECTOR3* WINAPI D3DXVec3ProjectArray
( D3DXVECTOR3 *pOut, UINT OutStride,CONST D3DXVECTOR3 *pV, UINT VStride,CONST D3DVIEWPORT9 *pViewport,
CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
// Project vector Array from screen space into object space
D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray
( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DVIEWPORT9 *pViewport,
CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
#ifdef __cplusplus
}
#endif
//--------------------------
// 4D Vector
//--------------------------
// inline
FLOAT D3DXVec4Length
( CONST D3DXVECTOR4 *pV );
FLOAT D3DXVec4LengthSq
( CONST D3DXVECTOR4 *pV );
FLOAT D3DXVec4Dot
( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 );
D3DXVECTOR4* D3DXVec4Add
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
D3DXVECTOR4* D3DXVec4Subtract
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
// Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
D3DXVECTOR4* D3DXVec4Minimize
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
// Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
D3DXVECTOR4* D3DXVec4Maximize
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
D3DXVECTOR4* D3DXVec4Scale
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s);
// Linear interpolation. V1 + s(V2-V1)
D3DXVECTOR4* D3DXVec4Lerp
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
FLOAT s );
// non-inline
#ifdef __cplusplus
extern "C" {
#endif
// Cross-product in 4 dimensions.
D3DXVECTOR4* WINAPI D3DXVec4Cross
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
CONST D3DXVECTOR4 *pV3);
D3DXVECTOR4* WINAPI D3DXVec4Normalize
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
// Hermite interpolation between position V1, tangent T1 (when s == 0)
// and position V2, tangent T2 (when s == 1).
D3DXVECTOR4* WINAPI D3DXVec4Hermite
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pT1,
CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pT2, FLOAT s );
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
D3DXVECTOR4* WINAPI D3DXVec4CatmullRom
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV0, CONST D3DXVECTOR4 *pV1,
CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pV3, FLOAT s );
// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g);
// Transform vector by matrix.
D3DXVECTOR4* WINAPI D3DXVec4Transform
( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
// Transform vector array by matrix.
D3DXVECTOR4* WINAPI D3DXVec4TransformArray
( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR4 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
#ifdef __cplusplus
}
#endif
//--------------------------
// 4D Matrix
//--------------------------
// inline
D3DXMATRIX* D3DXMatrixIdentity
( D3DXMATRIX *pOut );
BOOL D3DXMatrixIsIdentity
( CONST D3DXMATRIX *pM );
// non-inline
#ifdef __cplusplus
extern "C" {
#endif
FLOAT WINAPI D3DXMatrixDeterminant
( CONST D3DXMATRIX *pM );
HRESULT WINAPI D3DXMatrixDecompose
( D3DXVECTOR3 *pOutScale, D3DXQUATERNION *pOutRotation,
D3DXVECTOR3 *pOutTranslation, CONST D3DXMATRIX *pM );
D3DXMATRIX* WINAPI D3DXMatrixTranspose
( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
// Matrix multiplication. The result represents the transformation M2
// followed by the transformation M1. (Out = M1 * M2)
D3DXMATRIX* WINAPI D3DXMatrixMultiply
( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
// Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose
( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
// Calculate inverse of matrix. Inversion my fail, in which case NULL will
// be returned. The determinant of pM is also returned it pfDeterminant
// is non-NULL.
D3DXMATRIX* WINAPI D3DXMatrixInverse
( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
// Build a matrix which scales by (sx, sy, sz)
D3DXMATRIX* WINAPI D3DXMatrixScaling
( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
// Build a matrix which translates by (x, y, z)
D3DXMATRIX* WINAPI D3DXMatrixTranslation
( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
// Build a matrix which rotates around the X axis
D3DXMATRIX* WINAPI D3DXMatrixRotationX
( D3DXMATRIX *pOut, FLOAT Angle );
// Build a matrix which rotates around the Y axis
D3DXMATRIX* WINAPI D3DXMatrixRotationY
( D3DXMATRIX *pOut, FLOAT Angle );
// Build a matrix which rotates around the Z axis
D3DXMATRIX* WINAPI D3DXMatrixRotationZ
( D3DXMATRIX *pOut, FLOAT Angle );
// Build a matrix which rotates around an arbitrary axis
D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
// Build a matrix from a quaternion
D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
( D3DXMATRIX *pOut, CONST D3DXQUATERNION *pQ);
// Yaw around the Y axis, a pitch around the X axis,
// and a roll around the Z axis.
D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
// Build transformation matrix. NULL arguments are treated as identity.
// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
D3DXMATRIX* WINAPI D3DXMatrixTransformation
( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter,
CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling,
CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation,
CONST D3DXVECTOR3 *pTranslation);
// Build 2D transformation matrix in XY plane. NULL arguments are treated as identity.
// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
D3DXMATRIX* WINAPI D3DXMatrixTransformation2D
( D3DXMATRIX *pOut, CONST D3DXVECTOR2* pScalingCenter,
FLOAT ScalingRotation, CONST D3DXVECTOR2* pScaling,
CONST D3DXVECTOR2* pRotationCenter, FLOAT Rotation,
CONST D3DXVECTOR2* pTranslation);
// Build affine transformation matrix. NULL arguments are treated as identity.
// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR3 *pRotationCenter,
CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation);
// Build 2D affine transformation matrix in XY plane. NULL arguments are treated as identity.
// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D
( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR2* pRotationCenter,
FLOAT Rotation, CONST D3DXVECTOR2* pTranslation);
// Build a lookat matrix. (right-handed)
D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
CONST D3DXVECTOR3 *pUp );
// Build a lookat matrix. (left-handed)