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:       D3DX10math.h
6
//  Content:    D3DX10 math types and functions
7
//
8
//////////////////////////////////////////////////////////////////////////////
9
 
10
#include "D3DX10.h"
11
 
12
// D3DX10 and D3DX9 math look the same. You can include either one into your project.
13
// We are intentionally using the header define from D3DX9 math to prevent double-inclusion.
14
#ifndef __D3DX9MATH_H__
15
#define __D3DX9MATH_H__
16
 
17
#include <math.h>
18
#if _MSC_VER >= 1200
19
#pragma warning(push)
20
#endif
21
#pragma warning(disable:4201) // anonymous unions warning
22
 
23
//===========================================================================
24
//
25
// Type definitions from D3D9
26
//
27
//===========================================================================
28
 
29
#ifndef D3DVECTOR_DEFINED
30
typedef struct _D3DVECTOR {
31
    float x;
32
    float y;
33
    float z;
34
} D3DVECTOR;
35
#define D3DVECTOR_DEFINED
36
#endif
37
 
38
#ifndef D3DMATRIX_DEFINED
39
typedef struct _D3DMATRIX {
40
    union {
41
        struct {
42
            float        _11, _12, _13, _14;
43
            float        _21, _22, _23, _24;
44
            float        _31, _32, _33, _34;
45
            float        _41, _42, _43, _44;
46
 
47
        };
48
        float m[4][4];
49
    };
50
} D3DMATRIX;
51
#define D3DMATRIX_DEFINED
52
#endif
53
 
54
//===========================================================================
55
//
56
// General purpose utilities
57
//
58
//===========================================================================
59
#define D3DX_PI    (3.14159265358979323846)
60
#define D3DX_1BYPI ( 1.0 / D3DX_PI )
61
 
62
#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0))
63
#define D3DXToDegree( radian ) ((radian) * (180.0 / D3DX_PI))
64
 
65
 
66
 
67
//===========================================================================
68
//
69
// 16 bit floating point numbers
70
//
71
//===========================================================================
72
 
73
#define D3DX_16F_DIG          3                // # of decimal digits of precision
74
#define D3DX_16F_EPSILON      4.8875809e-4f    // smallest such that 1.0 + epsilon != 1.0
75
#define D3DX_16F_MANT_DIG     11               // # of bits in mantissa
76
#define D3DX_16F_MAX          6.550400e+004    // max value
77
#define D3DX_16F_MAX_10_EXP   4                // max decimal exponent
78
#define D3DX_16F_MAX_EXP      15               // max binary exponent
79
#define D3DX_16F_MIN          6.1035156e-5f    // min positive value
80
#define D3DX_16F_MIN_10_EXP   (-4)             // min decimal exponent
81
#define D3DX_16F_MIN_EXP      (-14)            // min binary exponent
82
#define D3DX_16F_RADIX        2                // exponent radix
83
#define D3DX_16F_ROUNDS       1                // addition rounding: near
84
#define D3DX_16F_SIGN_MASK    0x8000
85
#define D3DX_16F_EXP_MASK     0x7C00
86
#define D3DX_16F_FRAC_MASK    0x03FF
87
 
88
typedef struct D3DXFLOAT16
89
{
90
#ifdef __cplusplus
91
public:
92
    D3DXFLOAT16() {};
93
    D3DXFLOAT16( FLOAT );
94
    D3DXFLOAT16( CONST D3DXFLOAT16& );
95
 
96
    // casting
97
    operator FLOAT ();
98
 
99
    // binary operators
100
    BOOL operator == ( CONST D3DXFLOAT16& ) const;
101
    BOOL operator != ( CONST D3DXFLOAT16& ) const;
102
 
103
protected:
104
#endif //__cplusplus
105
    WORD value;
106
} D3DXFLOAT16, *LPD3DXFLOAT16;
107
 
108
 
109
 
110
//===========================================================================
111
//
112
// Vectors
113
//
114
//===========================================================================
115
 
116
 
117
//--------------------------
118
// 2D Vector
119
//--------------------------
120
typedef struct D3DXVECTOR2
121
{
122
#ifdef __cplusplus
123
public:
124
    D3DXVECTOR2() {};
125
    D3DXVECTOR2( CONST FLOAT * );
126
    D3DXVECTOR2( CONST D3DXFLOAT16 * );
127
    D3DXVECTOR2( FLOAT x, FLOAT y );
128
 
129
    // casting
130
    operator FLOAT* ();
131
    operator CONST FLOAT* () const;
132
 
133
    // assignment operators
134
    D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& );
135
    D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& );
136
    D3DXVECTOR2& operator *= ( FLOAT );
137
    D3DXVECTOR2& operator /= ( FLOAT );
138
 
139
    // unary operators
140
    D3DXVECTOR2 operator + () const;
141
    D3DXVECTOR2 operator - () const;
142
 
143
    // binary operators
144
    D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const;
145
    D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const;
146
    D3DXVECTOR2 operator * ( FLOAT ) const;
147
    D3DXVECTOR2 operator / ( FLOAT ) const;
148
 
149
    friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& );
150
 
151
    BOOL operator == ( CONST D3DXVECTOR2& ) const;
152
    BOOL operator != ( CONST D3DXVECTOR2& ) const;
153
 
154
 
155
public:
156
#endif //__cplusplus
157
    FLOAT x, y;
158
} D3DXVECTOR2, *LPD3DXVECTOR2;
159
 
160
 
161
 
162
//--------------------------
163
// 2D Vector (16 bit)
164
//--------------------------
165
 
166
typedef struct D3DXVECTOR2_16F
167
{
168
#ifdef __cplusplus
169
public:
170
    D3DXVECTOR2_16F() {};
171
    D3DXVECTOR2_16F( CONST FLOAT * );
172
    D3DXVECTOR2_16F( CONST D3DXFLOAT16 * );
173
    D3DXVECTOR2_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y );
174
 
175
    // casting
176
    operator D3DXFLOAT16* ();
177
    operator CONST D3DXFLOAT16* () const;
178
 
179
    // binary operators
180
    BOOL operator == ( CONST D3DXVECTOR2_16F& ) const;
181
    BOOL operator != ( CONST D3DXVECTOR2_16F& ) const;
182
 
183
public:
184
#endif //__cplusplus
185
    D3DXFLOAT16 x, y;
186
 
187
} D3DXVECTOR2_16F, *LPD3DXVECTOR2_16F;
188
 
189
 
190
 
191
//--------------------------
192
// 3D Vector
193
//--------------------------
194
#ifdef __cplusplus
195
typedef struct D3DXVECTOR3 : public D3DVECTOR
196
{
197
public:
198
    D3DXVECTOR3() {};
199
    D3DXVECTOR3( CONST FLOAT * );
200
    D3DXVECTOR3( CONST D3DVECTOR& );
201
    D3DXVECTOR3( CONST D3DXFLOAT16 * );
202
    D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );
203
 
204
    // casting
205
    operator FLOAT* ();
206
    operator CONST FLOAT* () const;
207
 
208
    // assignment operators
209
    D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
210
    D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
211
    D3DXVECTOR3& operator *= ( FLOAT );
212
    D3DXVECTOR3& operator /= ( FLOAT );
213
 
214
    // unary operators
215
    D3DXVECTOR3 operator + () const;
216
    D3DXVECTOR3 operator - () const;
217
 
218
    // binary operators
219
    D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
220
    D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
221
    D3DXVECTOR3 operator * ( FLOAT ) const;
222
    D3DXVECTOR3 operator / ( FLOAT ) const;
223
 
224
    friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );
225
 
226
    BOOL operator == ( CONST D3DXVECTOR3& ) const;
227
    BOOL operator != ( CONST D3DXVECTOR3& ) const;
228
 
229
} D3DXVECTOR3, *LPD3DXVECTOR3;
230
 
231
#else //!__cplusplus
232
typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
233
#endif //!__cplusplus
234
 
235
 
236
 
237
//--------------------------
238
// 3D Vector (16 bit)
239
//--------------------------
240
typedef struct D3DXVECTOR3_16F
241
{
242
#ifdef __cplusplus
243
public:
244
    D3DXVECTOR3_16F() {};
245
    D3DXVECTOR3_16F( CONST FLOAT * );
246
    D3DXVECTOR3_16F( CONST D3DVECTOR& );
247
    D3DXVECTOR3_16F( CONST D3DXFLOAT16 * );
248
    D3DXVECTOR3_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y, CONST D3DXFLOAT16 &z );
249
 
250
    // casting
251
    operator D3DXFLOAT16* ();
252
    operator CONST D3DXFLOAT16* () const;
253
 
254
    // binary operators
255
    BOOL operator == ( CONST D3DXVECTOR3_16F& ) const;
256
    BOOL operator != ( CONST D3DXVECTOR3_16F& ) const;
257
 
258
public:
259
#endif //__cplusplus
260
    D3DXFLOAT16 x, y, z;
261
 
262
} D3DXVECTOR3_16F, *LPD3DXVECTOR3_16F;
263
 
264
 
265
 
266
//--------------------------
267
// 4D Vector
268
//--------------------------
269
typedef struct D3DXVECTOR4
270
{
271
#ifdef __cplusplus
272
public:
273
    D3DXVECTOR4() {};
274
    D3DXVECTOR4( CONST FLOAT* );
275
    D3DXVECTOR4( CONST D3DXFLOAT16* );
276
    D3DXVECTOR4( CONST D3DVECTOR& xyz, FLOAT w );
277
    D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
278
 
279
    // casting
280
    operator FLOAT* ();
281
    operator CONST FLOAT* () const;
282
 
283
    // assignment operators
284
    D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& );
285
    D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& );
286
    D3DXVECTOR4& operator *= ( FLOAT );
287
    D3DXVECTOR4& operator /= ( FLOAT );
288
 
289
    // unary operators
290
    D3DXVECTOR4 operator + () const;
291
    D3DXVECTOR4 operator - () const;
292
 
293
    // binary operators
294
    D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const;
295
    D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const;
296
    D3DXVECTOR4 operator * ( FLOAT ) const;
297
    D3DXVECTOR4 operator / ( FLOAT ) const;
298
 
299
    friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );
300
 
301
    BOOL operator == ( CONST D3DXVECTOR4& ) const;
302
    BOOL operator != ( CONST D3DXVECTOR4& ) const;
303
 
304
public:
305
#endif //__cplusplus
306
    FLOAT x, y, z, w;
307
} D3DXVECTOR4, *LPD3DXVECTOR4;
308
 
309
 
310
//--------------------------
311
// 4D Vector (16 bit)
312
//--------------------------
313
typedef struct D3DXVECTOR4_16F
314
{
315
#ifdef __cplusplus
316
public:
317
    D3DXVECTOR4_16F() {};
318
    D3DXVECTOR4_16F( CONST FLOAT * );
319
    D3DXVECTOR4_16F( CONST D3DXFLOAT16* );
320
    D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& xyz, CONST D3DXFLOAT16& w );
321
    D3DXVECTOR4_16F( CONST D3DXFLOAT16& x, CONST D3DXFLOAT16& y, CONST D3DXFLOAT16& z, CONST D3DXFLOAT16& w );
322
 
323
    // casting
324
    operator D3DXFLOAT16* ();
325
    operator CONST D3DXFLOAT16* () const;
326
 
327
    // binary operators
328
    BOOL operator == ( CONST D3DXVECTOR4_16F& ) const;
329
    BOOL operator != ( CONST D3DXVECTOR4_16F& ) const;
330
 
331
public:
332
#endif //__cplusplus
333
    D3DXFLOAT16 x, y, z, w;
334
 
335
} D3DXVECTOR4_16F, *LPD3DXVECTOR4_16F;
336
 
337
 
338
 
339
//===========================================================================
340
//
341
// Matrices
342
//
343
//===========================================================================
344
#ifdef __cplusplus
345
typedef struct D3DXMATRIX : public D3DMATRIX
346
{
347
public:
348
    D3DXMATRIX() {};
349
    D3DXMATRIX( CONST FLOAT * );
350
    D3DXMATRIX( CONST D3DMATRIX& );
351
    D3DXMATRIX( CONST D3DXFLOAT16 * );
352
    D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
353
                FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
354
                FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
355
                FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
356
 
357
 
358
    // access grants
359
    FLOAT& operator () ( UINT Row, UINT Col );
360
    FLOAT  operator () ( UINT Row, UINT Col ) const;
361
 
362
    // casting operators
363
    operator FLOAT* ();
364
    operator CONST FLOAT* () const;
365
 
366
    // assignment operators
367
    D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
368
    D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
369
    D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
370
    D3DXMATRIX& operator *= ( FLOAT );
371
    D3DXMATRIX& operator /= ( FLOAT );
372
 
373
    // unary operators
374
    D3DXMATRIX operator + () const;
375
    D3DXMATRIX operator - () const;
376
 
377
    // binary operators
378
    D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
379
    D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
380
    D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
381
    D3DXMATRIX operator * ( FLOAT ) const;
382
    D3DXMATRIX operator / ( FLOAT ) const;
383
 
384
    friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
385
 
386
    BOOL operator == ( CONST D3DXMATRIX& ) const;
387
    BOOL operator != ( CONST D3DXMATRIX& ) const;
388
 
389
} D3DXMATRIX, *LPD3DXMATRIX;
390
 
391
#else //!__cplusplus
392
typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
393
#endif //!__cplusplus
394
 
395
 
396
//---------------------------------------------------------------------------
397
// Aligned Matrices
398
//
399
// This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
400
// It aligns matrices on the stack and on the heap or in global scope.
401
// It does this using __declspec(align(16)) which works on VC7 and on VC 6
402
// with the processor pack. Unfortunately there is no way to detect the 
403
// latter so this is turned on only on VC7. On other compilers this is the
404
// the same as D3DXMATRIX.
405
//
406
// Using this class on a compiler that does not actually do the alignment
407
// can be dangerous since it will not expose bugs that ignore alignment.
408
// E.g if an object of this class in inside a struct or class, and some code
409
// memcopys data in it assuming tight packing. This could break on a compiler
410
// that eventually start aligning the matrix.
411
//---------------------------------------------------------------------------
412
#ifdef __cplusplus
413
typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
414
{
415
    _D3DXMATRIXA16() {};
416
    _D3DXMATRIXA16( CONST FLOAT * );
417
    _D3DXMATRIXA16( CONST D3DMATRIX& );
418
    _D3DXMATRIXA16( CONST D3DXFLOAT16 * );
419
    _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
420
                    FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
421
                    FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
422
                    FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
423
 
424
    // new operators
425
    void* operator new   ( size_t );
426
    void* operator new[] ( size_t );
427
 
428
    // delete operators
429
    void operator delete   ( void* );   // These are NOT virtual; Do not 
430
    void operator delete[] ( void* );   // cast to D3DXMATRIX and delete.
431
 
432
    // assignment operators
433
    _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
434
 
435
} _D3DXMATRIXA16;
436
 
437
#else //!__cplusplus
438
typedef D3DXMATRIX  _D3DXMATRIXA16;
439
#endif //!__cplusplus
440
 
441
 
442
 
443
#if _MSC_VER >= 1300  // VC7
444
#define D3DX_ALIGN16 __declspec(align(16))
445
#else
446
#define D3DX_ALIGN16  // Earlier compiler may not understand this, do nothing.
447
#endif
448
 
449
typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;
450
 
451
 
452
 
453
//===========================================================================
454
//
455
//    Quaternions
456
//
457
//===========================================================================
458
typedef struct D3DXQUATERNION
459
{
460
#ifdef __cplusplus
461
public:
462
    D3DXQUATERNION() {};
463
    D3DXQUATERNION( CONST FLOAT * );
464
    D3DXQUATERNION( CONST D3DXFLOAT16 * );
465
    D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
466
 
467
    // casting
468
    operator FLOAT* ();
469
    operator CONST FLOAT* () const;
470
 
471
    // assignment operators
472
    D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& );
473
    D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& );
474
    D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& );
475
    D3DXQUATERNION& operator *= ( FLOAT );
476
    D3DXQUATERNION& operator /= ( FLOAT );
477
 
478
    // unary operators
479
    D3DXQUATERNION  operator + () const;
480
    D3DXQUATERNION  operator - () const;
481
 
482
    // binary operators
483
    D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const;
484
    D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const;
485
    D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const;
486
    D3DXQUATERNION operator * ( FLOAT ) const;
487
    D3DXQUATERNION operator / ( FLOAT ) const;
488
 
489
    friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& );
490
 
491
    BOOL operator == ( CONST D3DXQUATERNION& ) const;
492
    BOOL operator != ( CONST D3DXQUATERNION& ) const;
493
 
494
#endif //__cplusplus
495
    FLOAT x, y, z, w;
496
} D3DXQUATERNION, *LPD3DXQUATERNION;
497
 
498
 
499
//===========================================================================
500
//
501
// Planes
502
//
503
//===========================================================================
504
typedef struct D3DXPLANE
505
{
506
#ifdef __cplusplus
507
public:
508
    D3DXPLANE() {};
509
    D3DXPLANE( CONST FLOAT* );
510
    D3DXPLANE( CONST D3DXFLOAT16* );
511
    D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );
512
 
513
    // casting
514
    operator FLOAT* ();
515
    operator CONST FLOAT* () const;
516
 
517
    // assignment operators
518
    D3DXPLANE& operator *= ( FLOAT );
519
    D3DXPLANE& operator /= ( FLOAT );
520
 
521
    // unary operators
522
    D3DXPLANE operator + () const;
523
    D3DXPLANE operator - () const;
524
 
525
    // binary operators
526
    D3DXPLANE operator * ( FLOAT ) const;
527
    D3DXPLANE operator / ( FLOAT ) const;
528
 
529
    friend D3DXPLANE operator * ( FLOAT, CONST D3DXPLANE& );
530
 
531
    BOOL operator == ( CONST D3DXPLANE& ) const;
532
    BOOL operator != ( CONST D3DXPLANE& ) const;
533
 
534
#endif //__cplusplus
535
    FLOAT a, b, c, d;
536
} D3DXPLANE, *LPD3DXPLANE;
537
 
538
 
539
//===========================================================================
540
//
541
// Colors
542
//
543
//===========================================================================
544
 
545
typedef struct D3DXCOLOR
546
{
547
#ifdef __cplusplus
548
public:
549
    D3DXCOLOR() {};
550
    D3DXCOLOR( UINT  argb );
551
    D3DXCOLOR( CONST FLOAT * );
552
    D3DXCOLOR( CONST D3DXFLOAT16 * );
553
    D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
554
 
555
    // casting
556
    operator UINT  () const;
557
 
558
    operator FLOAT* ();
559
    operator CONST FLOAT* () const;
560
 
561
    // assignment operators
562
    D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
563
    D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
564
    D3DXCOLOR& operator *= ( FLOAT );
565
    D3DXCOLOR& operator /= ( FLOAT );
566
 
567
    // unary operators
568
    D3DXCOLOR operator + () const;
569
    D3DXCOLOR operator - () const;
570
 
571
    // binary operators
572
    D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
573
    D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
574
    D3DXCOLOR operator * ( FLOAT ) const;
575
    D3DXCOLOR operator / ( FLOAT ) const;
576
 
577
    friend D3DXCOLOR operator * ( FLOAT, CONST D3DXCOLOR& );
578
 
579
    BOOL operator == ( CONST D3DXCOLOR& ) const;
580
    BOOL operator != ( CONST D3DXCOLOR& ) const;
581
 
582
#endif //__cplusplus
583
    FLOAT r, g, b, a;
584
} D3DXCOLOR, *LPD3DXCOLOR;
585
 
586
 
587
 
588
//===========================================================================
589
//
590
// D3DX math functions:
591
//
592
// NOTE:
593
//  * All these functions can take the same object as in and out parameters.
594
//
595
//  * Out parameters are typically also returned as return values, so that
596
//    the output of one function may be used as a parameter to another.
597
//
598
//===========================================================================
599
 
600
//--------------------------
601
// Float16
602
//--------------------------
603
 
604
// non-inline
605
#ifdef __cplusplus
606
extern "C" {
607
#endif
608
 
609
// Converts an array 32-bit floats to 16-bit floats
610
D3DXFLOAT16* WINAPI D3DXFloat32To16Array
611
    ( D3DXFLOAT16 *pOut, CONST FLOAT *pIn, UINT n );
612
 
613
// Converts an array 16-bit floats to 32-bit floats
614
FLOAT* WINAPI D3DXFloat16To32Array
615
    ( __out_ecount(n) FLOAT *pOut, __in_ecount(n) CONST D3DXFLOAT16 *pIn, UINT n );
616
 
617
#ifdef __cplusplus
618
}
619
#endif
620
 
621
 
622
//--------------------------
623
// 2D Vector
624
//--------------------------
625
 
626
// inline
627
 
628
FLOAT D3DXVec2Length
629
    ( CONST D3DXVECTOR2 *pV );
630
 
631
FLOAT D3DXVec2LengthSq
632
    ( CONST D3DXVECTOR2 *pV );
633
 
634
FLOAT D3DXVec2Dot
635
    ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
636
 
637
// Z component of ((x1,y1,0) cross (x2,y2,0))
638
FLOAT D3DXVec2CCW
639
    ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
640
 
641
D3DXVECTOR2* D3DXVec2Add
642
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
643
 
644
D3DXVECTOR2* D3DXVec2Subtract
645
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
646
 
647
// Minimize each component.  x = min(x1, x2), y = min(y1, y2)
648
D3DXVECTOR2* D3DXVec2Minimize
649
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
650
 
651
// Maximize each component.  x = max(x1, x2), y = max(y1, y2)
652
D3DXVECTOR2* D3DXVec2Maximize
653
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
654
 
655
D3DXVECTOR2* D3DXVec2Scale
656
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s );
657
 
658
// Linear interpolation. V1 + s(V2-V1)
659
D3DXVECTOR2* D3DXVec2Lerp
660
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
661
      FLOAT s );
662
 
663
// non-inline
664
#ifdef __cplusplus
665
extern "C" {
666
#endif
667
 
668
D3DXVECTOR2* WINAPI D3DXVec2Normalize
669
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV );
670
 
671
// Hermite interpolation between position V1, tangent T1 (when s == 0)
672
// and position V2, tangent T2 (when s == 1).
673
D3DXVECTOR2* WINAPI D3DXVec2Hermite
674
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pT1,
675
      CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pT2, FLOAT s );
676
 
677
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
678
D3DXVECTOR2* WINAPI D3DXVec2CatmullRom
679
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV0, CONST D3DXVECTOR2 *pV1,
680
      CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pV3, FLOAT s );
681
 
682
// Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
683
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
684
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
685
      CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g);
686
 
687
// Transform (x, y, 0, 1) by matrix.
688
D3DXVECTOR4* WINAPI D3DXVec2Transform
689
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
690
 
691
// Transform (x, y, 0, 1) by matrix, project result back into w=1.
692
D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
693
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
694
 
695
// Transform (x, y, 0, 0) by matrix.
696
D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
697
    ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
698
 
699
// Transform Array (x, y, 0, 1) by matrix.
700
D3DXVECTOR4* WINAPI D3DXVec2TransformArray
701
    ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n);
702
 
703
// Transform Array (x, y, 0, 1) by matrix, project result back into w=1.
704
D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray
705
    ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
706
 
707
// Transform Array (x, y, 0, 0) by matrix.
708
D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray
709
    ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
710
 
711
 
712
 
713
#ifdef __cplusplus
714
}
715
#endif
716
 
717
 
718
//--------------------------
719
// 3D Vector
720
//--------------------------
721
 
722
// inline
723
 
724
FLOAT D3DXVec3Length
725
    ( CONST D3DXVECTOR3 *pV );
726
 
727
FLOAT D3DXVec3LengthSq
728
    ( CONST D3DXVECTOR3 *pV );
729
 
730
FLOAT D3DXVec3Dot
731
    ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
732
 
733
D3DXVECTOR3* D3DXVec3Cross
734
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
735
 
736
D3DXVECTOR3* D3DXVec3Add
737
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
738
 
739
D3DXVECTOR3* D3DXVec3Subtract
740
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
741
 
742
// Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
743
D3DXVECTOR3* D3DXVec3Minimize
744
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
745
 
746
// Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
747
D3DXVECTOR3* D3DXVec3Maximize
748
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
749
 
750
D3DXVECTOR3* D3DXVec3Scale
751
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s);
752
 
753
// Linear interpolation. V1 + s(V2-V1)
754
D3DXVECTOR3* D3DXVec3Lerp
755
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
756
      FLOAT s );
757
 
758
// non-inline
759
#ifdef __cplusplus
760
extern "C" {
761
#endif
762
 
763
D3DXVECTOR3* WINAPI D3DXVec3Normalize
764
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV );
765
 
766
// Hermite interpolation between position V1, tangent T1 (when s == 0)
767
// and position V2, tangent T2 (when s == 1).
768
D3DXVECTOR3* WINAPI D3DXVec3Hermite
769
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pT1,
770
      CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pT2, FLOAT s );
771
 
772
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
773
D3DXVECTOR3* WINAPI D3DXVec3CatmullRom
774
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV0, CONST D3DXVECTOR3 *pV1,
775
      CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pV3, FLOAT s );
776
 
777
// Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
778
D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
779
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
780
      CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g);
781
 
782
// Transform (x, y, z, 1) by matrix.
783
D3DXVECTOR4* WINAPI D3DXVec3Transform
784
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
785
 
786
// Transform (x, y, z, 1) by matrix, project result back into w=1.
787
D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
788
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
789
 
790
// Transform (x, y, z, 0) by matrix.  If you transforming a normal by a 
791
// non-affine matrix, the matrix you pass to this function should be the 
792
// transpose of the inverse of the matrix you would use to transform a coord.
793
D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
794
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
795
 
796
 
797
// Transform Array (x, y, z, 1) by matrix. 
798
D3DXVECTOR4* WINAPI D3DXVec3TransformArray
799
    ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
800
 
801
// Transform Array (x, y, z, 1) by matrix, project result back into w=1.
802
D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray
803
    ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
804
 
805
// Transform (x, y, z, 0) by matrix.  If you transforming a normal by a 
806
// non-affine matrix, the matrix you pass to this function should be the 
807
// transpose of the inverse of the matrix you would use to transform a coord.
808
D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray
809
    ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
810
 
811
// Project vector from object space into screen space
812
D3DXVECTOR3* WINAPI D3DXVec3Project
813
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport,
814
      CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
815
 
816
// Project vector from screen space into object space
817
D3DXVECTOR3* WINAPI D3DXVec3Unproject
818
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport,
819
      CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
820
 
821
// Project vector Array from object space into screen space
822
D3DXVECTOR3* WINAPI D3DXVec3ProjectArray
823
    ( D3DXVECTOR3 *pOut, UINT OutStride,CONST D3DXVECTOR3 *pV, UINT VStride,CONST D3D10_VIEWPORT *pViewport,
824
      CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
825
 
826
// Project vector Array from screen space into object space
827
D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray
828
    ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3D10_VIEWPORT *pViewport,
829
      CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
830
 
831
 
832
#ifdef __cplusplus
833
}
834
#endif
835
 
836
 
837
 
838
//--------------------------
839
// 4D Vector
840
//--------------------------
841
 
842
// inline
843
 
844
FLOAT D3DXVec4Length
845
    ( CONST D3DXVECTOR4 *pV );
846
 
847
FLOAT D3DXVec4LengthSq
848
    ( CONST D3DXVECTOR4 *pV );
849
 
850
FLOAT D3DXVec4Dot
851
    ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 );
852
 
853
D3DXVECTOR4* D3DXVec4Add
854
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
855
 
856
D3DXVECTOR4* D3DXVec4Subtract
857
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
858
 
859
// Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
860
D3DXVECTOR4* D3DXVec4Minimize
861
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
862
 
863
// Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
864
D3DXVECTOR4* D3DXVec4Maximize
865
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
866
 
867
D3DXVECTOR4* D3DXVec4Scale
868
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s);
869
 
870
// Linear interpolation. V1 + s(V2-V1)
871
D3DXVECTOR4* D3DXVec4Lerp
872
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
873
      FLOAT s );
874
 
875
// non-inline
876
#ifdef __cplusplus
877
extern "C" {
878
#endif
879
 
880
// Cross-product in 4 dimensions.
881
D3DXVECTOR4* WINAPI D3DXVec4Cross
882
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
883
      CONST D3DXVECTOR4 *pV3);
884
 
885
D3DXVECTOR4* WINAPI D3DXVec4Normalize
886
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
887
 
888
// Hermite interpolation between position V1, tangent T1 (when s == 0)
889
// and position V2, tangent T2 (when s == 1).
890
D3DXVECTOR4* WINAPI D3DXVec4Hermite
891
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pT1,
892
      CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pT2, FLOAT s );
893
 
894
// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
895
D3DXVECTOR4* WINAPI D3DXVec4CatmullRom
896
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV0, CONST D3DXVECTOR4 *pV1,
897
      CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pV3, FLOAT s );
898
 
899
// Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
900
D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
901
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
902
      CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g);
903
 
904
// Transform vector by matrix.
905
D3DXVECTOR4* WINAPI D3DXVec4Transform
906
    ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
907
 
908
// Transform vector array by matrix.
909
D3DXVECTOR4* WINAPI D3DXVec4TransformArray
910
    ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR4 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
911
 
912
#ifdef __cplusplus
913
}
914
#endif
915
 
916
 
917
//--------------------------
918
// 4D Matrix
919
//--------------------------
920
 
921
// inline
922
 
923
D3DXMATRIX* D3DXMatrixIdentity
924
    ( D3DXMATRIX *pOut );
925
 
926
BOOL D3DXMatrixIsIdentity
927
    ( CONST D3DXMATRIX *pM );
928
 
929
 
930
// non-inline
931
#ifdef __cplusplus
932
extern "C" {
933
#endif
934
 
935
FLOAT WINAPI D3DXMatrixDeterminant
936
    ( CONST D3DXMATRIX *pM );
937
 
938
HRESULT WINAPI D3DXMatrixDecompose
939
    ( D3DXVECTOR3 *pOutScale, D3DXQUATERNION *pOutRotation,
940
          D3DXVECTOR3 *pOutTranslation, CONST D3DXMATRIX *pM );
941
 
942
D3DXMATRIX* WINAPI D3DXMatrixTranspose
943
    ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
944
 
945
// Matrix multiplication.  The result represents the transformation M2
946
// followed by the transformation M1.  (Out = M1 * M2)
947
D3DXMATRIX* WINAPI D3DXMatrixMultiply
948
    ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
949
 
950
// Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
951
D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose
952
    ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
953
 
954
// Calculate inverse of matrix.  Inversion my fail, in which case NULL will
955
// be returned.  The determinant of pM is also returned it pfDeterminant
956
// is non-NULL.
957
D3DXMATRIX* WINAPI D3DXMatrixInverse
958
    ( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
959
 
960
// Build a matrix which scales by (sx, sy, sz)
961
D3DXMATRIX* WINAPI D3DXMatrixScaling
962
    ( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
963
 
964
// Build a matrix which translates by (x, y, z)
965
D3DXMATRIX* WINAPI D3DXMatrixTranslation
966
    ( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
967
 
968
// Build a matrix which rotates around the X axis
969
D3DXMATRIX* WINAPI D3DXMatrixRotationX
970
    ( D3DXMATRIX *pOut, FLOAT Angle );
971
 
972
// Build a matrix which rotates around the Y axis
973
D3DXMATRIX* WINAPI D3DXMatrixRotationY
974
    ( D3DXMATRIX *pOut, FLOAT Angle );
975
 
976
// Build a matrix which rotates around the Z axis
977
D3DXMATRIX* WINAPI D3DXMatrixRotationZ
978
    ( D3DXMATRIX *pOut, FLOAT Angle );
979
 
980
// Build a matrix which rotates around an arbitrary axis
981
D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
982
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
983
 
984
// Build a matrix from a quaternion
985
D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
986
    ( D3DXMATRIX *pOut, CONST D3DXQUATERNION *pQ);
987
 
988
// Yaw around the Y axis, a pitch around the X axis,
989
// and a roll around the Z axis.
990
D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
991
    ( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
992
 
993
// Build transformation matrix.  NULL arguments are treated as identity.
994
// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
995
D3DXMATRIX* WINAPI D3DXMatrixTransformation
996
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter,
997
      CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling,
998
      CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation,
999
      CONST D3DXVECTOR3 *pTranslation);
1000
 
1001
// Build 2D transformation matrix in XY plane.  NULL arguments are treated as identity.
1002
// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
1003
D3DXMATRIX* WINAPI D3DXMatrixTransformation2D
1004
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR2* pScalingCenter,
1005
      FLOAT ScalingRotation, CONST D3DXVECTOR2* pScaling,
1006
      CONST D3DXVECTOR2* pRotationCenter, FLOAT Rotation,
1007
      CONST D3DXVECTOR2* pTranslation);
1008
 
1009
// Build affine transformation matrix.  NULL arguments are treated as identity.
1010
// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
1011
D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
1012
    ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR3 *pRotationCenter,
1013
      CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation);
1014
 
1015
// Build 2D affine transformation matrix in XY plane.  NULL arguments are treated as identity.
1016
// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
1017
D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D
1018
    ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR2* pRotationCenter,
1019
      FLOAT Rotation, CONST D3DXVECTOR2* pTranslation);
1020
 
1021
// Build a lookat matrix. (right-handed)
1022
D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
1023
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
1024
      CONST D3DXVECTOR3 *pUp );
1025
 
1026
// Build a lookat matrix. (left-handed)
1027
D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
1028
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
1029
      CONST D3DXVECTOR3 *pUp );
1030
 
1031
// Build a perspective projection matrix. (right-handed)
1032
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveRH
1033
    ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
1034
 
1035
// Build a perspective projection matrix. (left-handed)
1036
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH
1037
    ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
1038
 
1039
// Build a perspective projection matrix. (right-handed)
1040
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH
1041
    ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
1042
 
1043
// Build a perspective projection matrix. (left-handed)
1044
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH
1045
    ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
1046
 
1047
// Build a perspective projection matrix. (right-handed)
1048
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterRH
1049
    ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
1050
      FLOAT zf );
1051
 
1052
// Build a perspective projection matrix. (left-handed)
1053
D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH
1054
    ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
1055
      FLOAT zf );
1056
 
1057
// Build an ortho projection matrix. (right-handed)
1058
D3DXMATRIX* WINAPI D3DXMatrixOrthoRH
1059
    ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
1060
 
1061
// Build an ortho projection matrix. (left-handed)
1062
D3DXMATRIX* WINAPI D3DXMatrixOrthoLH
1063
    ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
1064
 
1065
// Build an ortho projection matrix. (right-handed)
1066
D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterRH
1067
    ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
1068
      FLOAT zf );
1069
 
1070
// Build an ortho projection matrix. (left-handed)
1071
D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH
1072
    ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
1073
      FLOAT zf );
1074
 
1075
// Build a matrix which flattens geometry into a plane, as if casting
1076
// a shadow from a light.
1077
D3DXMATRIX* WINAPI D3DXMatrixShadow
1078
    ( D3DXMATRIX *pOut, CONST D3DXVECTOR4 *pLight,
1079
      CONST D3DXPLANE *pPlane );
1080
 
1081
// Build a matrix which reflects the coordinate system about a plane
1082
D3DXMATRIX* WINAPI D3DXMatrixReflect
1083
    ( D3DXMATRIX *pOut, CONST D3DXPLANE *pPlane );
1084
 
1085
#ifdef __cplusplus
1086
}
1087
#endif
1088
 
1089
 
1090
//--------------------------
1091
// Quaternion
1092
//--------------------------
1093
 
1094
// inline
1095
 
1096
FLOAT D3DXQuaternionLength
1097
    ( CONST D3DXQUATERNION *pQ );
1098
 
1099
// Length squared, or "norm"
1100
FLOAT D3DXQuaternionLengthSq
1101
    ( CONST D3DXQUATERNION *pQ );
1102
 
1103
FLOAT D3DXQuaternionDot
1104
    ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 );
1105
 
1106
// (0, 0, 0, 1)
1107
D3DXQUATERNION* D3DXQuaternionIdentity
1108
    ( D3DXQUATERNION *pOut );
1109
 
1110
BOOL D3DXQuaternionIsIdentity
1111
    ( CONST D3DXQUATERNION *pQ );
1112
 
1113
// (-x, -y, -z, w)
1114
D3DXQUATERNION* D3DXQuaternionConjugate
1115
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
1116
 
1117
 
1118
// non-inline
1119
#ifdef __cplusplus
1120
extern "C" {
1121
#endif
1122
 
1123
// Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
1124
void WINAPI D3DXQuaternionToAxisAngle
1125
    ( CONST D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, FLOAT *pAngle );
1126
 
1127
// Build a quaternion from a rotation matrix.
1128
D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix
1129
    ( D3DXQUATERNION *pOut, CONST D3DXMATRIX *pM);
1130
 
1131
// Rotation about arbitrary axis.
1132
D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis
1133
    ( D3DXQUATERNION *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
1134
 
1135
// Yaw around the Y axis, a pitch around the X axis,
1136
// and a roll around the Z axis.
1137
D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll
1138
    ( D3DXQUATERNION *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
1139
 
1140
// Quaternion multiplication.  The result represents the rotation Q2
1141
// followed by the rotation Q1.  (Out = Q2 * Q1)
1142
D3DXQUATERNION* WINAPI D3DXQuaternionMultiply
1143
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
1144
      CONST D3DXQUATERNION *pQ2 );
1145
 
1146
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize
1147
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
1148
 
1149
// Conjugate and re-norm
1150
D3DXQUATERNION* WINAPI D3DXQuaternionInverse
1151
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
1152
 
1153
// Expects unit quaternions.
1154
// if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
1155
D3DXQUATERNION* WINAPI D3DXQuaternionLn
1156
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
1157
 
1158
// Expects pure quaternions. (w == 0)  w is ignored in calculation.
1159
// if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
1160
D3DXQUATERNION* WINAPI D3DXQuaternionExp
1161
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
1162
 
1163
// Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).
1164
// Expects unit quaternions.
1165
D3DXQUATERNION* WINAPI D3DXQuaternionSlerp
1166
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
1167
      CONST D3DXQUATERNION *pQ2, FLOAT t );
1168
 
1169
// Spherical quadrangle interpolation.
1170
// Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))
1171
D3DXQUATERNION* WINAPI D3DXQuaternionSquad
1172
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
1173
      CONST D3DXQUATERNION *pA, CONST D3DXQUATERNION *pB,
1174
      CONST D3DXQUATERNION *pC, FLOAT t );
1175
 
1176
// Setup control points for spherical quadrangle interpolation
1177
// from Q1 to Q2.  The control points are chosen in such a way 
1178
// to ensure the continuity of tangents with adjacent segments.
1179
void WINAPI D3DXQuaternionSquadSetup
1180
    ( D3DXQUATERNION *pAOut, D3DXQUATERNION *pBOut, D3DXQUATERNION *pCOut,
1181
      CONST D3DXQUATERNION *pQ0, CONST D3DXQUATERNION *pQ1,
1182
      CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3 );
1183
 
1184
// Barycentric interpolation.
1185
// Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
1186
D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric
1187
    ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
1188
      CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3,
1189
      FLOAT f, FLOAT g );
1190
 
1191
#ifdef __cplusplus
1192
}
1193
#endif
1194
 
1195
 
1196
//--------------------------
1197
// Plane
1198
//--------------------------
1199
 
1200
// inline
1201
 
1202
// ax + by + cz + dw
1203
FLOAT D3DXPlaneDot
1204
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV);
1205
 
1206
// ax + by + cz + d
1207
FLOAT D3DXPlaneDotCoord
1208
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
1209
 
1210
// ax + by + cz
1211
FLOAT D3DXPlaneDotNormal
1212
    ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
1213
 
1214
D3DXPLANE* D3DXPlaneScale
1215
    (D3DXPLANE *pOut, CONST D3DXPLANE *pP, FLOAT s);
1216
 
1217
// non-inline
1218
#ifdef __cplusplus
1219
extern "C" {
1220
#endif
1221
 
1222
// Normalize plane (so that |a,b,c| == 1)
1223
D3DXPLANE* WINAPI D3DXPlaneNormalize
1224
    ( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
1225
 
1226
// Find the intersection between a plane and a line.  If the line is
1227
// parallel to the plane, NULL is returned.
1228
D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine
1229
    ( D3DXVECTOR3 *pOut, CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV1,
1230
      CONST D3DXVECTOR3 *pV2);
1231
 
1232
// Construct a plane from a point and a normal
1233
D3DXPLANE* WINAPI D3DXPlaneFromPointNormal
1234
    ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pPoint, CONST D3DXVECTOR3 *pNormal);
1235
 
1236
// Construct a plane from 3 points
1237
D3DXPLANE* WINAPI D3DXPlaneFromPoints
1238
    ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
1239
      CONST D3DXVECTOR3 *pV3);
1240
 
1241
// Transform a plane by a matrix.  The vector (a,b,c) must be normal.
1242
// M should be the inverse transpose of the transformation desired.
1243
D3DXPLANE* WINAPI D3DXPlaneTransform
1244
    ( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
1245
 
1246
// Transform an array of planes by a matrix.  The vectors (a,b,c) must be normal.
1247
// M should be the inverse transpose of the transformation desired.
1248
D3DXPLANE* WINAPI D3DXPlaneTransformArray
1249
    ( D3DXPLANE *pOut, UINT OutStride, CONST D3DXPLANE *pP, UINT PStride, CONST D3DXMATRIX *pM, UINT n );
1250
 
1251
#ifdef __cplusplus
1252
}
1253
#endif
1254
 
1255
 
1256
//--------------------------
1257
// Color
1258
//--------------------------
1259
 
1260
// inline
1261
 
1262
// (1-r, 1-g, 1-b, a)
1263
D3DXCOLOR* D3DXColorNegative
1264
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC);
1265
 
1266
D3DXCOLOR* D3DXColorAdd
1267
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
1268
 
1269
D3DXCOLOR* D3DXColorSubtract
1270
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
1271
 
1272
D3DXCOLOR* D3DXColorScale
1273
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
1274
 
1275
// (r1*r2, g1*g2, b1*b2, a1*a2)
1276
D3DXCOLOR* D3DXColorModulate
1277
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
1278
 
1279
// Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
1280
D3DXCOLOR* D3DXColorLerp
1281
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s);
1282
 
1283
// non-inline
1284
#ifdef __cplusplus
1285
extern "C" {
1286
#endif
1287
 
1288
// Interpolate r,g,b between desaturated color and color.
1289
// DesaturatedColor + s(Color - DesaturatedColor)
1290
D3DXCOLOR* WINAPI D3DXColorAdjustSaturation
1291
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
1292
 
1293
// Interpolate r,g,b between 50% grey and color.  Grey + s(Color - Grey)
1294
D3DXCOLOR* WINAPI D3DXColorAdjustContrast
1295
    (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT c);
1296
 
1297
#ifdef __cplusplus
1298
}
1299
#endif
1300
 
1301
 
1302
 
1303
 
1304
//--------------------------
1305
// Misc
1306
//--------------------------
1307
 
1308
#ifdef __cplusplus
1309
extern "C" {
1310
#endif
1311
 
1312
// Calculate Fresnel term given the cosine of theta (likely obtained by
1313
// taking the dot of two normals), and the refraction index of the material.
1314
FLOAT WINAPI D3DXFresnelTerm
1315
    (FLOAT CosTheta, FLOAT RefractionIndex);    
1316
 
1317
#ifdef __cplusplus
1318
}
1319
#endif
1320
 
1321
 
1322
 
1323
//===========================================================================
1324
//
1325
//    Matrix Stack
1326
//
1327
//===========================================================================
1328
 
1329
typedef interface ID3DXMatrixStack ID3DXMatrixStack;
1330
typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
1331
 
1332
// {C7885BA7-F990-4fe7-922D-8515E477DD85}
1333
DEFINE_GUID(IID_ID3DXMatrixStack,
1334
0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
1335
 
1336
 
1337
#undef INTERFACE
1338
#define INTERFACE ID3DXMatrixStack
1339
 
1340
DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
1341
{
1342
    //
1343
    // IUnknown methods
1344
    //
1345
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
1346
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
1347
    STDMETHOD_(ULONG,Release)(THIS) PURE;
1348
 
1349
    //
1350
    // ID3DXMatrixStack methods
1351
    //
1352
 
1353
    // Pops the top of the stack, returns the current top
1354
    // *after* popping the top.
1355
    STDMETHOD(Pop)(THIS) PURE;
1356
 
1357
    // Pushes the stack by one, duplicating the current matrix.
1358
    STDMETHOD(Push)(THIS) PURE;
1359
 
1360
    // Loads identity in the current matrix.
1361
    STDMETHOD(LoadIdentity)(THIS) PURE;
1362
 
1363
    // Loads the given matrix into the current matrix
1364
    STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
1365
 
1366
    // Right-Multiplies the given matrix to the current matrix.
1367
    // (transformation is about the current world origin)
1368
    STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
1369
 
1370
    // Left-Multiplies the given matrix to the current matrix
1371
    // (transformation is about the local origin of the object)
1372
    STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
1373
 
1374
    // Right multiply the current matrix with the computed rotation
1375
    // matrix, counterclockwise about the given axis with the given angle.
1376
    // (rotation is about the current world origin)
1377
    STDMETHOD(RotateAxis)
1378
        (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
1379
 
1380
    // Left multiply the current matrix with the computed rotation
1381
    // matrix, counterclockwise about the given axis with the given angle.
1382
    // (rotation is about the local origin of the object)
1383
    STDMETHOD(RotateAxisLocal)
1384
        (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
1385
 
1386
    // Right multiply the current matrix with the computed rotation
1387
    // matrix. All angles are counterclockwise. (rotation is about the
1388
    // current world origin)
1389
 
1390
    // The rotation is composed of a yaw around the Y axis, a pitch around
1391
    // the X axis, and a roll around the Z axis.
1392
    STDMETHOD(RotateYawPitchRoll)
1393
        (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
1394
 
1395
    // Left multiply the current matrix with the computed rotation
1396
    // matrix. All angles are counterclockwise. (rotation is about the
1397
    // local origin of the object)
1398
 
1399
    // The rotation is composed of a yaw around the Y axis, a pitch around
1400
    // the X axis, and a roll around the Z axis.
1401
    STDMETHOD(RotateYawPitchRollLocal)
1402
        (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
1403
 
1404
    // Right multiply the current matrix with the computed scale
1405
    // matrix. (transformation is about the current world origin)
1406
    STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
1407
 
1408
    // Left multiply the current matrix with the computed scale
1409
    // matrix. (transformation is about the local origin of the object)
1410
    STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
1411
 
1412
    // Right multiply the current matrix with the computed translation
1413
    // matrix. (transformation is about the current world origin)
1414
    STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
1415
 
1416
    // Left multiply the current matrix with the computed translation
1417
    // matrix. (transformation is about the local origin of the object)
1418
    STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
1419
 
1420
    // Obtain the current matrix at the top of the stack
1421
    STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
1422
};
1423
 
1424
#ifdef __cplusplus
1425
extern "C" {
1426
#endif
1427
 
1428
HRESULT WINAPI
1429
    D3DXCreateMatrixStack(
1430
        UINT                Flags,
1431
        LPD3DXMATRIXSTACK*  ppStack);
1432
 
1433
#ifdef __cplusplus
1434
}
1435
#endif
1436
 
1437
// non-inline
1438
#ifdef __cplusplus
1439
extern "C" {
1440
#endif
1441
 
1442
//============================================================================
1443
//
1444
//  Basic Spherical Harmonic math routines
1445
//
1446
//============================================================================
1447
 
1448
#define D3DXSH_MINORDER 2
1449
#define D3DXSH_MAXORDER 6
1450
 
1451
//============================================================================
1452
//
1453
//  D3DXSHEvalDirection:
1454
//  --------------------
1455
//  Evaluates the Spherical Harmonic basis functions
1456
//
1457
//  Parameters:
1458
//   pOut
1459
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1460
//      This is the pointer that is returned.
1461
//   Order
1462
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1463
//   pDir
1464
//      Direction to evaluate in - assumed to be normalized
1465
//
1466
//============================================================================
1467
 
1468
FLOAT* WINAPI D3DXSHEvalDirection
1469
    (  FLOAT *pOut, UINT Order, CONST D3DXVECTOR3 *pDir );
1470
 
1471
//============================================================================
1472
//
1473
//  D3DXSHRotate:
1474
//  --------------------
1475
//  Rotates SH vector by a rotation matrix
1476
//
1477
//  Parameters:
1478
//   pOut
1479
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1480
//      This is the pointer that is returned (should not alias with pIn.)
1481
//   Order
1482
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1483
//   pMatrix
1484
//      Matrix used for rotation - rotation sub matrix should be orthogonal
1485
//      and have a unit determinant.
1486
//   pIn
1487
//      Input SH coeffs (rotated), incorect results if this is also output.
1488
//
1489
//============================================================================
1490
 
1491
FLOAT* WINAPI D3DXSHRotate
1492
    ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST D3DXMATRIX *pMatrix, CONST FLOAT *pIn );
1493
 
1494
//============================================================================
1495
//
1496
//  D3DXSHRotateZ:
1497
//  --------------------
1498
//  Rotates the SH vector in the Z axis by an angle
1499
//
1500
//  Parameters:
1501
//   pOut
1502
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1503
//      This is the pointer that is returned (should not alias with pIn.)
1504
//   Order
1505
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1506
//   Angle
1507
//      Angle in radians to rotate around the Z axis.
1508
//   pIn
1509
//      Input SH coeffs (rotated), incorect results if this is also output.
1510
//
1511
//============================================================================
1512
 
1513
 
1514
FLOAT* WINAPI D3DXSHRotateZ
1515
    ( FLOAT *pOut, UINT Order, FLOAT Angle, CONST FLOAT *pIn );
1516
 
1517
//============================================================================
1518
//
1519
//  D3DXSHAdd:
1520
//  --------------------
1521
//  Adds two SH vectors, pOut[i] = pA[i] + pB[i];
1522
//
1523
//  Parameters:
1524
//   pOut
1525
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1526
//      This is the pointer that is returned.
1527
//   Order
1528
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1529
//   pA
1530
//      Input SH coeffs.
1531
//   pB
1532
//      Input SH coeffs (second vector.)
1533
//
1534
//============================================================================
1535
 
1536
FLOAT* WINAPI D3DXSHAdd
1537
    ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST FLOAT *pA, CONST FLOAT *pB );
1538
 
1539
//============================================================================
1540
//
1541
//  D3DXSHScale:
1542
//  --------------------
1543
//  Adds two SH vectors, pOut[i] = pA[i]*Scale;
1544
//
1545
//  Parameters:
1546
//   pOut
1547
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1548
//      This is the pointer that is returned.
1549
//   Order
1550
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1551
//   pIn
1552
//      Input SH coeffs.
1553
//   Scale
1554
//      Scale factor.
1555
//
1556
//============================================================================
1557
 
1558
FLOAT* WINAPI D3DXSHScale
1559
    ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST FLOAT *pIn, CONST FLOAT Scale );
1560
 
1561
//============================================================================
1562
//
1563
//  D3DXSHDot:
1564
//  --------------------
1565
//  Computes the dot product of two SH vectors
1566
//
1567
//  Parameters:
1568
//   Order
1569
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1570
//   pA
1571
//      Input SH coeffs.
1572
//   pB
1573
//      Second set of input SH coeffs.
1574
//
1575
//============================================================================
1576
 
1577
FLOAT WINAPI D3DXSHDot
1578
    ( UINT Order, CONST FLOAT *pA, CONST FLOAT *pB );
1579
 
1580
//============================================================================
1581
//
1582
//  D3DXSHMultiply[O]:
1583
//  --------------------
1584
//  Computes the product of two functions represented using SH (f and g), where:
1585
//  pOut[i] = int(y_i(s) * f(s) * g(s)), where y_i(s) is the ith SH basis
1586
//  function, f(s) and g(s) are SH functions (sum_i(y_i(s)*c_i)).  The order O
1587
//  determines the lengths of the arrays, where there should always be O^2 
1588
//  coefficients.  In general the product of two SH functions of order O generates
1589
//  and SH function of order 2*O - 1, but we truncate the result.  This means
1590
//  that the product commutes (f*g == g*f) but doesn't associate 
1591
//  (f*(g*h) != (f*g)*h.
1592
//
1593
//  Parameters:
1594
//   pOut
1595
//      Output SH coefficients - basis function Ylm is stored at l*l + m+l
1596
//      This is the pointer that is returned.
1597
//   pF
1598
//      Input SH coeffs for first function.
1599
//   pG
1600
//      Second set of input SH coeffs.
1601
//
1602
//============================================================================
1603
 
1604
__out_ecount(4)  FLOAT* WINAPI D3DXSHMultiply2(__out_ecount(4)  FLOAT *pOut,__in_ecount(4)  CONST FLOAT *pF,__in_ecount(4)  CONST FLOAT *pG);
1605
__out_ecount(9)  FLOAT* WINAPI D3DXSHMultiply3(__out_ecount(9)  FLOAT *pOut,__in_ecount(9)  CONST FLOAT *pF,__in_ecount(9)  CONST FLOAT *pG);
1606
__out_ecount(16) FLOAT* WINAPI D3DXSHMultiply4(__out_ecount(16) FLOAT *pOut,__in_ecount(16) CONST FLOAT *pF,__in_ecount(16) CONST FLOAT *pG);
1607
__out_ecount(25) FLOAT* WINAPI D3DXSHMultiply5(__out_ecount(25) FLOAT *pOut,__in_ecount(25) CONST FLOAT *pF,__in_ecount(25) CONST FLOAT *pG);
1608
__out_ecount(36) FLOAT* WINAPI D3DXSHMultiply6(__out_ecount(36) FLOAT *pOut,__in_ecount(36) CONST FLOAT *pF,__in_ecount(36) CONST FLOAT *pG);
1609
 
1610
 
1611
//============================================================================
1612
//
1613
//  Basic Spherical Harmonic lighting routines
1614
//
1615
//============================================================================
1616
 
1617
//============================================================================
1618
//
1619
//  D3DXSHEvalDirectionalLight:
1620
//  --------------------
1621
//  Evaluates a directional light and returns spectral SH data.  The output 
1622
//  vector is computed so that if the intensity of R/G/B is unit the resulting
1623
//  exit radiance of a point directly under the light on a diffuse object with
1624
//  an albedo of 1 would be 1.0.  This will compute 3 spectral samples, pROut
1625
//  has to be specified, while pGout and pBout are optional.
1626
//
1627
//  Parameters:
1628
//   Order
1629
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1630
//   pDir
1631
//      Direction light is coming from (assumed to be normalized.)
1632
//   RIntensity
1633
//      Red intensity of light.
1634
//   GIntensity
1635
//      Green intensity of light.
1636
//   BIntensity
1637
//      Blue intensity of light.
1638
//   pROut
1639
//      Output SH vector for Red.
1640
//   pGOut
1641
//      Output SH vector for Green (optional.)
1642
//   pBOut
1643
//      Output SH vector for Blue (optional.)        
1644
//
1645
//============================================================================
1646
 
1647
HRESULT WINAPI D3DXSHEvalDirectionalLight
1648
    ( UINT Order, CONST D3DXVECTOR3 *pDir,
1649
      FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
1650
      __out_ecount_opt(Order*Order) FLOAT *pROut,
1651
      __out_ecount_opt(Order*Order) FLOAT *pGOut,
1652
      __out_ecount_opt(Order*Order) FLOAT *pBOut );
1653
 
1654
//============================================================================
1655
//
1656
//  D3DXSHEvalSphericalLight:
1657
//  --------------------
1658
//  Evaluates a spherical light and returns spectral SH data.  There is no 
1659
//  normalization of the intensity of the light like there is for directional
1660
//  lights, care has to be taken when specifiying the intensities.  This will 
1661
//  compute 3 spectral samples, pROut has to be specified, while pGout and 
1662
//  pBout are optional.
1663
//
1664
//  Parameters:
1665
//   Order
1666
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1667
//   pPos
1668
//      Position of light - reciever is assumed to be at the origin.
1669
//   Radius
1670
//      Radius of the spherical light source.
1671
//   RIntensity
1672
//      Red intensity of light.
1673
//   GIntensity
1674
//      Green intensity of light.
1675
//   BIntensity
1676
//      Blue intensity of light.
1677
//   pROut
1678
//      Output SH vector for Red.
1679
//   pGOut
1680
//      Output SH vector for Green (optional.)
1681
//   pBOut
1682
//      Output SH vector for Blue (optional.)        
1683
//
1684
//============================================================================
1685
 
1686
HRESULT WINAPI D3DXSHEvalSphericalLight
1687
    ( UINT Order, CONST D3DXVECTOR3 *pPos, FLOAT Radius,
1688
      FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
1689
      __out_ecount_opt(Order*Order) FLOAT *pROut,
1690
      __out_ecount_opt(Order*Order) FLOAT *pGOut,
1691
      __out_ecount_opt(Order*Order) FLOAT *pBOut );
1692
 
1693
//============================================================================
1694
//
1695
//  D3DXSHEvalConeLight:
1696
//  --------------------
1697
//  Evaluates a light that is a cone of constant intensity and returns spectral
1698
//  SH data.  The output vector is computed so that if the intensity of R/G/B is
1699
//  unit the resulting exit radiance of a point directly under the light oriented
1700
//  in the cone direction on a diffuse object with an albedo of 1 would be 1.0.
1701
//  This will compute 3 spectral samples, pROut has to be specified, while pGout
1702
//  and pBout are optional.
1703
//
1704
//  Parameters:
1705
//   Order
1706
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1707
//   pDir
1708
//      Direction light is coming from (assumed to be normalized.)
1709
//   Radius
1710
//      Radius of cone in radians.
1711
//   RIntensity
1712
//      Red intensity of light.
1713
//   GIntensity
1714
//      Green intensity of light.
1715
//   BIntensity
1716
//      Blue intensity of light.
1717
//   pROut
1718
//      Output SH vector for Red.
1719
//   pGOut
1720
//      Output SH vector for Green (optional.)
1721
//   pBOut
1722
//      Output SH vector for Blue (optional.)        
1723
//
1724
//============================================================================
1725
 
1726
HRESULT WINAPI D3DXSHEvalConeLight
1727
    ( UINT Order, CONST D3DXVECTOR3 *pDir, FLOAT Radius,
1728
      FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
1729
      __out_ecount_opt(Order*Order) FLOAT *pROut,
1730
      __out_ecount_opt(Order*Order) FLOAT *pGOut,
1731
      __out_ecount_opt(Order*Order) FLOAT *pBOut );
1732
 
1733
//============================================================================
1734
//
1735
//  D3DXSHEvalHemisphereLight:
1736
//  --------------------
1737
//  Evaluates a light that is a linear interpolant between two colors over the
1738
//  sphere.  The interpolant is linear along the axis of the two points, not
1739
//  over the surface of the sphere (ie: if the axis was (0,0,1) it is linear in
1740
//  Z, not in the azimuthal angle.)  The resulting spherical lighting function
1741
//  is normalized so that a point on a perfectly diffuse surface with no
1742
//  shadowing and a normal pointed in the direction pDir would result in exit
1743
//  radiance with a value of 1 if the top color was white and the bottom color
1744
//  was black.  This is a very simple model where Top represents the intensity 
1745
//  of the "sky" and Bottom represents the intensity of the "ground".
1746
//
1747
//  Parameters:
1748
//   Order
1749
//      Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
1750
//   pDir
1751
//      Axis of the hemisphere.
1752
//   Top
1753
//      Color of the upper hemisphere.
1754
//   Bottom
1755
//      Color of the lower hemisphere.
1756
//   pROut
1757
//      Output SH vector for Red.
1758
//   pGOut
1759
//      Output SH vector for Green
1760
//   pBOut
1761
//      Output SH vector for Blue        
1762
//
1763
//============================================================================
1764
 
1765
HRESULT WINAPI D3DXSHEvalHemisphereLight
1766
    ( UINT Order, CONST D3DXVECTOR3 *pDir, D3DXCOLOR Top, D3DXCOLOR Bottom,
1767
      __out_ecount_opt(Order*Order) FLOAT *pROut,
1768
      __out_ecount_opt(Order*Order) FLOAT *pGOut,
1769
      __out_ecount_opt(Order*Order) FLOAT *pBOut );
1770
 
1771
// Math intersection functions
1772
 
1773
BOOL WINAPI D3DXIntersectTri
1774
(
1775
    CONST D3DXVECTOR3 *p0,           // Triangle vertex 0 position
1776
    CONST D3DXVECTOR3 *p1,           // Triangle vertex 1 position
1777
    CONST D3DXVECTOR3 *p2,           // Triangle vertex 2 position
1778
    CONST D3DXVECTOR3 *pRayPos,      // Ray origin
1779
    CONST D3DXVECTOR3 *pRayDir,      // Ray direction
1780
    FLOAT *pU,                         // Barycentric Hit Coordinates
1781
    FLOAT *pV,                         // Barycentric Hit Coordinates
1782
    FLOAT *pDist);                     // Ray-Intersection Parameter Distance
1783
 
1784
BOOL WINAPI
1785
    D3DXSphereBoundProbe(
1786
        CONST D3DXVECTOR3 *pCenter,
1787
        FLOAT Radius,
1788
        CONST D3DXVECTOR3 *pRayPosition,
1789
        CONST D3DXVECTOR3 *pRayDirection);
1790
 
1791
BOOL WINAPI
1792
    D3DXBoxBoundProbe(
1793
        CONST D3DXVECTOR3 *pMin,
1794
        CONST D3DXVECTOR3 *pMax,
1795
        CONST D3DXVECTOR3 *pRayPosition,
1796
        CONST D3DXVECTOR3 *pRayDirection);
1797
 
1798
HRESULT WINAPI
1799
    D3DXComputeBoundingSphere(
1800
        CONST D3DXVECTOR3 *pFirstPosition,      // pointer to first position
1801
        DWORD NumVertices,
1802
        DWORD dwStride,                                                 // count in bytes to subsequent position vectors
1803
        D3DXVECTOR3 *pCenter,
1804
        FLOAT *pRadius);
1805
 
1806
HRESULT WINAPI
1807
    D3DXComputeBoundingBox(
1808
        CONST D3DXVECTOR3 *pFirstPosition,      // pointer to first position
1809
        DWORD NumVertices,
1810
        DWORD dwStride,                                                 // count in bytes to subsequent position vectors
1811
        D3DXVECTOR3 *pMin,
1812
        D3DXVECTOR3 *pMax);
1813
 
1814
 
1815
///////////////////////////////////////////////////////////////////////////
1816
// CPU Optimization:
1817
///////////////////////////////////////////////////////////////////////////
1818
 
1819
//-------------------------------------------------------------------------
1820
// D3DX_CPU_OPTIMIZATION flags:
1821
// ----------------------------
1822
// D3DX_NOT_OPTIMIZED       Use Intel Pentium optimizations
1823
// D3DX_3DNOW_OPTIMIZED     Use AMD 3DNow optimizations
1824
// D3DX_SSE_OPTIMIZED       Use Intel Pentium III SSE optimizations
1825
// D3DX_SSE2_OPTIMIZED      Use Intel Pentium IV SSE2 optimizations
1826
//-------------------------------------------------------------------------
1827
 
1828
 
1829
typedef enum _D3DX_CPU_OPTIMIZATION
1830
{
1831
    D3DX_NOT_OPTIMIZED = 0,
1832
    D3DX_3DNOW_OPTIMIZED,
1833
    D3DX_SSE2_OPTIMIZED,
1834
    D3DX_SSE_OPTIMIZED
1835
} D3DX_CPU_OPTIMIZATION;
1836
 
1837
 
1838
//-------------------------------------------------------------------------
1839
// D3DXCpuOptimizations:
1840
// ---------------------
1841
// Enables or disables CPU optimizations. Returns the type of CPU, which 
1842
// was detected, and for which optimizations exist.
1843
//
1844
// Parameters:
1845
//  Enable
1846
//      TRUE to enable CPU optimizations. FALSE to disable.
1847
//-------------------------------------------------------------------------
1848
 
1849
D3DX_CPU_OPTIMIZATION WINAPI
1850
    D3DXCpuOptimizations(BOOL Enable);
1851
 
1852
#ifdef __cplusplus
1853
}
1854
#endif
1855
 
1856
 
1857
#include "D3DX10math.inl"
1858
 
1859
#if _MSC_VER >= 1200
1860
#pragma warning(pop)
1861
#else
1862
#pragma warning(default:4201)
1863
#endif
1864
 
1865
#endif // __D3DX9MATH_H__
1866