Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

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