////////////////////////////////////////////////////////////////////////////////// Copyright (C) Microsoft Corporation. All Rights Reserved.//// File: d3dx9math.h// Content: D3DX math types and functions////////////////////////////////////////////////////////////////////////////////#include"d3dx9.h"#ifndef __D3DX9MATH_H__#define __D3DX9MATH_H__#ifdef _MSC_VER#include<math.h>#if _MSC_VER >= 1200#pragma warning(push)#endif#pragma warning(disable:4201) // anonymous unions warning#endif // _MSC_VER//===========================================================================//// General purpose utilities////===========================================================================#define D3DX_PI ((FLOAT) 3.141592654f)#define D3DX_1BYPI ((FLOAT) 0.318309886f)#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))#define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))//===========================================================================//// 16 bit floating point numbers////===========================================================================#define D3DX_16F_DIG 3 // # of decimal digits of precision#define D3DX_16F_EPSILON 4.8875809e-4f // smallest such that 1.0 + epsilon != 1.0#define D3DX_16F_MANT_DIG 11 // # of bits in mantissa#define D3DX_16F_MAX 6.550400e+004 // max value#define D3DX_16F_MAX_10_EXP 4 // max decimal exponent#define D3DX_16F_MAX_EXP 15 // max binary exponent#define D3DX_16F_MIN 6.1035156e-5f // min positive value#define D3DX_16F_MIN_10_EXP (-4) // min decimal exponent#define D3DX_16F_MIN_EXP (-14) // min binary exponent#define D3DX_16F_RADIX 2 // exponent radix#define D3DX_16F_ROUNDS 1 // addition rounding: neartypedefstructD3DXFLOAT16{#ifdef __cpluspluspublic:D3DXFLOAT16(){};D3DXFLOAT16(FLOAT);D3DXFLOAT16(CONSTD3DXFLOAT16&);// castingoperatorFLOAT();// binary operatorsBOOLoperator==(CONSTD3DXFLOAT16&)const;BOOLoperator!=(CONSTD3DXFLOAT16&)const;protected:#endif //__cplusplusWORDvalue;}D3DXFLOAT16,*LPD3DXFLOAT16;//===========================================================================//// Vectors////===========================================================================//--------------------------// 2D Vector//--------------------------typedefstructD3DXVECTOR2{#ifdef __cpluspluspublic:D3DXVECTOR2(){};D3DXVECTOR2(CONSTFLOAT*);D3DXVECTOR2(CONSTD3DXFLOAT16*);D3DXVECTOR2(FLOATx,FLOATy);// castingoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXVECTOR2&operator+=(CONSTD3DXVECTOR2&);D3DXVECTOR2&operator-=(CONSTD3DXVECTOR2&);D3DXVECTOR2&operator*=(FLOAT);D3DXVECTOR2&operator/=(FLOAT);// unary operatorsD3DXVECTOR2operator+()const;D3DXVECTOR2operator-()const;// binary operatorsD3DXVECTOR2operator+(CONSTD3DXVECTOR2&)const;D3DXVECTOR2operator-(CONSTD3DXVECTOR2&)const;D3DXVECTOR2operator*(FLOAT)const;D3DXVECTOR2operator/(FLOAT)const;friendD3DXVECTOR2operator*(FLOAT,CONSTD3DXVECTOR2&);BOOLoperator==(CONSTD3DXVECTOR2&)const;BOOLoperator!=(CONSTD3DXVECTOR2&)const;public:#endif //__cplusplusFLOATx,y;}D3DXVECTOR2,*LPD3DXVECTOR2;//--------------------------// 2D Vector (16 bit)//--------------------------typedefstructD3DXVECTOR2_16F{#ifdef __cpluspluspublic:D3DXVECTOR2_16F(){};D3DXVECTOR2_16F(CONSTFLOAT*);D3DXVECTOR2_16F(CONSTD3DXFLOAT16*);D3DXVECTOR2_16F(CONSTD3DXFLOAT16&x,CONSTD3DXFLOAT16&y);// castingoperatorD3DXFLOAT16*();operatorCONSTD3DXFLOAT16*()const;// binary operatorsBOOLoperator==(CONSTD3DXVECTOR2_16F&)const;BOOLoperator!=(CONSTD3DXVECTOR2_16F&)const;public:#endif //__cplusplusD3DXFLOAT16x,y;}D3DXVECTOR2_16F,*LPD3DXVECTOR2_16F;//--------------------------// 3D Vector//--------------------------#ifdef __cplusplustypedefstructD3DXVECTOR3:publicD3DVECTOR{public:D3DXVECTOR3(){};D3DXVECTOR3(CONSTFLOAT*);D3DXVECTOR3(CONSTD3DVECTOR&);D3DXVECTOR3(CONSTD3DXFLOAT16*);D3DXVECTOR3(FLOATx,FLOATy,FLOATz);// castingoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXVECTOR3&operator+=(CONSTD3DXVECTOR3&);D3DXVECTOR3&operator-=(CONSTD3DXVECTOR3&);D3DXVECTOR3&operator*=(FLOAT);D3DXVECTOR3&operator/=(FLOAT);// unary operatorsD3DXVECTOR3operator+()const;D3DXVECTOR3operator-()const;// binary operatorsD3DXVECTOR3operator+(CONSTD3DXVECTOR3&)const;D3DXVECTOR3operator-(CONSTD3DXVECTOR3&)const;D3DXVECTOR3operator*(FLOAT)const;D3DXVECTOR3operator/(FLOAT)const;friendD3DXVECTOR3operator*(FLOAT,CONSTstructD3DXVECTOR3&);BOOLoperator==(CONSTD3DXVECTOR3&)const;BOOLoperator!=(CONSTD3DXVECTOR3&)const;}D3DXVECTOR3,*LPD3DXVECTOR3;#else //!__cplusplustypedefstruct_D3DVECTORD3DXVECTOR3,*LPD3DXVECTOR3;#endif //!__cplusplus//--------------------------// 3D Vector (16 bit)//--------------------------typedefstructD3DXVECTOR3_16F{#ifdef __cpluspluspublic:D3DXVECTOR3_16F(){};D3DXVECTOR3_16F(CONSTFLOAT*);D3DXVECTOR3_16F(CONSTD3DVECTOR&);D3DXVECTOR3_16F(CONSTD3DXFLOAT16*);D3DXVECTOR3_16F(CONSTD3DXFLOAT16&x,CONSTD3DXFLOAT16&y,CONSTD3DXFLOAT16&z);// castingoperatorD3DXFLOAT16*();operatorCONSTD3DXFLOAT16*()const;// binary operatorsBOOLoperator==(CONSTD3DXVECTOR3_16F&)const;BOOLoperator!=(CONSTD3DXVECTOR3_16F&)const;public:#endif //__cplusplusD3DXFLOAT16x,y,z;}D3DXVECTOR3_16F,*LPD3DXVECTOR3_16F;//--------------------------// 4D Vector//--------------------------typedefstructD3DXVECTOR4{#ifdef __cpluspluspublic:D3DXVECTOR4(){};D3DXVECTOR4(CONSTFLOAT*);D3DXVECTOR4(CONSTD3DXFLOAT16*);D3DXVECTOR4(CONSTD3DVECTOR&xyz,FLOATw);D3DXVECTOR4(FLOATx,FLOATy,FLOATz,FLOATw);// castingoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXVECTOR4&operator+=(CONSTD3DXVECTOR4&);D3DXVECTOR4&operator-=(CONSTD3DXVECTOR4&);D3DXVECTOR4&operator*=(FLOAT);D3DXVECTOR4&operator/=(FLOAT);// unary operatorsD3DXVECTOR4operator+()const;D3DXVECTOR4operator-()const;// binary operatorsD3DXVECTOR4operator+(CONSTD3DXVECTOR4&)const;D3DXVECTOR4operator-(CONSTD3DXVECTOR4&)const;D3DXVECTOR4operator*(FLOAT)const;D3DXVECTOR4operator/(FLOAT)const;friendD3DXVECTOR4operator*(FLOAT,CONSTD3DXVECTOR4&);BOOLoperator==(CONSTD3DXVECTOR4&)const;BOOLoperator!=(CONSTD3DXVECTOR4&)const;public:#endif //__cplusplusFLOATx,y,z,w;}D3DXVECTOR4,*LPD3DXVECTOR4;//--------------------------// 4D Vector (16 bit)//--------------------------typedefstructD3DXVECTOR4_16F{#ifdef __cpluspluspublic:D3DXVECTOR4_16F(){};D3DXVECTOR4_16F(CONSTFLOAT*);D3DXVECTOR4_16F(CONSTD3DXFLOAT16*);D3DXVECTOR4_16F(CONSTD3DXVECTOR3_16F&xyz,CONSTD3DXFLOAT16&w);D3DXVECTOR4_16F(CONSTD3DXFLOAT16&x,CONSTD3DXFLOAT16&y,CONSTD3DXFLOAT16&z,CONSTD3DXFLOAT16&w);// castingoperatorD3DXFLOAT16*();operatorCONSTD3DXFLOAT16*()const;// binary operatorsBOOLoperator==(CONSTD3DXVECTOR4_16F&)const;BOOLoperator!=(CONSTD3DXVECTOR4_16F&)const;public:#endif //__cplusplusD3DXFLOAT16x,y,z,w;}D3DXVECTOR4_16F,*LPD3DXVECTOR4_16F;//===========================================================================//// Matrices////===========================================================================#ifdef __cplusplustypedefstructD3DXMATRIX:publicD3DMATRIX{public:D3DXMATRIX(){};D3DXMATRIX(CONSTFLOAT*);D3DXMATRIX(CONSTD3DMATRIX&);D3DXMATRIX(CONSTD3DXFLOAT16*);D3DXMATRIX(FLOAT_11,FLOAT_12,FLOAT_13,FLOAT_14,FLOAT_21,FLOAT_22,FLOAT_23,FLOAT_24,FLOAT_31,FLOAT_32,FLOAT_33,FLOAT_34,FLOAT_41,FLOAT_42,FLOAT_43,FLOAT_44);// access grantsFLOAT&operator()(UINTRow,UINTCol);FLOAToperator()(UINTRow,UINTCol)const;// casting operatorsoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXMATRIX&operator*=(CONSTD3DXMATRIX&);D3DXMATRIX&operator+=(CONSTD3DXMATRIX&);D3DXMATRIX&operator-=(CONSTD3DXMATRIX&);D3DXMATRIX&operator*=(FLOAT);D3DXMATRIX&operator/=(FLOAT);// unary operatorsD3DXMATRIXoperator+()const;D3DXMATRIXoperator-()const;// binary operatorsD3DXMATRIXoperator*(CONSTD3DXMATRIX&)const;D3DXMATRIXoperator+(CONSTD3DXMATRIX&)const;D3DXMATRIXoperator-(CONSTD3DXMATRIX&)const;D3DXMATRIXoperator*(FLOAT)const;D3DXMATRIXoperator/(FLOAT)const;friendD3DXMATRIXoperator*(FLOAT,CONSTD3DXMATRIX&);BOOLoperator==(CONSTD3DXMATRIX&)const;BOOLoperator!=(CONSTD3DXMATRIX&)const;}D3DXMATRIX,*LPD3DXMATRIX;#else //!__cplusplustypedefstruct_D3DMATRIXD3DXMATRIX,*LPD3DXMATRIX;#endif //!__cplusplus//---------------------------------------------------------------------------// Aligned Matrices//// This class helps keep matrices 16-byte aligned as preferred by P4 cpus.// It aligns matrices on the stack and on the heap or in global scope.// It does this using __declspec(align(16)) which works on VC7 and on VC 6// with the processor pack. Unfortunately there is no way to detect the // latter so this is turned on only on VC7. On other compilers this is the// the same as D3DXMATRIX.//// Using this class on a compiler that does not actually do the alignment// can be dangerous since it will not expose bugs that ignore alignment.// E.g if an object of this class in inside a struct or class, and some code// memcopys data in it assuming tight packing. This could break on a compiler// that eventually start aligning the matrix.//---------------------------------------------------------------------------#ifdef __cplusplustypedefstruct_D3DXMATRIXA16:publicD3DXMATRIX{_D3DXMATRIXA16(){}_D3DXMATRIXA16(CONSTFLOAT*);_D3DXMATRIXA16(CONSTD3DMATRIX&);_D3DXMATRIXA16(CONSTD3DXFLOAT16*);_D3DXMATRIXA16(FLOAT_11,FLOAT_12,FLOAT_13,FLOAT_14,FLOAT_21,FLOAT_22,FLOAT_23,FLOAT_24,FLOAT_31,FLOAT_32,FLOAT_33,FLOAT_34,FLOAT_41,FLOAT_42,FLOAT_43,FLOAT_44);// new operatorsvoid*operatornew(size_t);void*operatornew[](size_t);// delete operatorsvoidoperatordelete(void*);// These are NOT virtual; Do not voidoperatordelete[](void*);// cast to D3DXMATRIX and delete.// assignment operators_D3DXMATRIXA16&operator=(CONSTD3DXMATRIX&);}_D3DXMATRIXA16;#else //!__cplusplustypedefD3DXMATRIX_D3DXMATRIXA16;#endif //!__cplusplus#ifdef _MSC_VER#if _MSC_VER >= 1300 // VC7#define D3DX_ALIGN16 __declspec(align(16))#else#define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.#endif#else#define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.#endif // _MSC_VERtypedefD3DX_ALIGN16_D3DXMATRIXA16D3DXMATRIXA16,*LPD3DXMATRIXA16;//===========================================================================//// Quaternions////===========================================================================typedefstructD3DXQUATERNION{#ifdef __cpluspluspublic:D3DXQUATERNION(){}D3DXQUATERNION(CONSTFLOAT*);D3DXQUATERNION(CONSTD3DXFLOAT16*);D3DXQUATERNION(FLOATx,FLOATy,FLOATz,FLOATw);// castingoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXQUATERNION&operator+=(CONSTD3DXQUATERNION&);D3DXQUATERNION&operator-=(CONSTD3DXQUATERNION&);D3DXQUATERNION&operator*=(CONSTD3DXQUATERNION&);D3DXQUATERNION&operator*=(FLOAT);D3DXQUATERNION&operator/=(FLOAT);// unary operatorsD3DXQUATERNIONoperator+()const;D3DXQUATERNIONoperator-()const;// binary operatorsD3DXQUATERNIONoperator+(CONSTD3DXQUATERNION&)const;D3DXQUATERNIONoperator-(CONSTD3DXQUATERNION&)const;D3DXQUATERNIONoperator*(CONSTD3DXQUATERNION&)const;D3DXQUATERNIONoperator*(FLOAT)const;D3DXQUATERNIONoperator/(FLOAT)const;friendD3DXQUATERNIONoperator*(FLOAT,CONSTD3DXQUATERNION&);BOOLoperator==(CONSTD3DXQUATERNION&)const;BOOLoperator!=(CONSTD3DXQUATERNION&)const;#endif //__cplusplusFLOATx,y,z,w;}D3DXQUATERNION,*LPD3DXQUATERNION;//===========================================================================//// Planes////===========================================================================typedefstructD3DXPLANE{#ifdef __cpluspluspublic:D3DXPLANE(){}D3DXPLANE(CONSTFLOAT*);D3DXPLANE(CONSTD3DXFLOAT16*);D3DXPLANE(FLOATa,FLOATb,FLOATc,FLOATd);// castingoperatorFLOAT*();operatorCONSTFLOAT*()const;// assignment operatorsD3DXPLANE&operator*=(FLOAT);D3DXPLANE&operator/=(FLOAT);// unary operatorsD3DXPLANEoperator+()const;D3DXPLANEoperator-()const;// binary operatorsD3DXPLANEoperator*(FLOAT)const;D3DXPLANEoperator/(FLOAT)const;friendD3DXPLANEoperator*(FLOAT,CONSTD3DXPLANE&);BOOLoperator==(CONSTD3DXPLANE&)const;BOOLoperator!=(CONSTD3DXPLANE&)const;#endif //__cplusplusFLOATa,b,c,d;}D3DXPLANE,*LPD3DXPLANE;//===========================================================================//// Colors////===========================================================================typedefstructD3DXCOLOR{#ifdef __cpluspluspublic:D3DXCOLOR(){}D3DXCOLOR(DWORDargb);D3DXCOLOR(CONSTFLOAT*);D3DXCOLOR(CONSTD3DXFLOAT16*);D3DXCOLOR(CONSTD3DCOLORVALUE&);D3DXCOLOR(FLOATr,FLOATg,FLOATb,FLOATa);// castingoperatorDWORD()const;operatorFLOAT*();operatorCONSTFLOAT*()const;operatorD3DCOLORVALUE*();operatorCONSTD3DCOLORVALUE*()const;operatorD3DCOLORVALUE&();operatorCONSTD3DCOLORVALUE&()const;// assignment operatorsD3DXCOLOR&operator+=(CONSTD3DXCOLOR&);D3DXCOLOR&operator-=(CONSTD3DXCOLOR&);D3DXCOLOR&operator*=(FLOAT);D3DXCOLOR&operator/=(FLOAT);// unary operatorsD3DXCOLORoperator+()const;D3DXCOLORoperator-()const;// binary operatorsD3DXCOLORoperator+(CONSTD3DXCOLOR&)const;D3DXCOLORoperator-(CONSTD3DXCOLOR&)const;D3DXCOLORoperator*(FLOAT)const;D3DXCOLORoperator/(FLOAT)const;friendD3DXCOLORoperator*(FLOAT,CONSTD3DXCOLOR&);BOOLoperator==(CONSTD3DXCOLOR&)const;BOOLoperator!=(CONSTD3DXCOLOR&)const;#endif //__cplusplusFLOATr,g,b,a;}D3DXCOLOR,*LPD3DXCOLOR;//===========================================================================//// D3DX math functions://// NOTE:// * All these functions can take the same object as in and out parameters.//// * Out parameters are typically also returned as return values, so that// the output of one function may be used as a parameter to another.////===========================================================================//--------------------------// Float16//--------------------------// non-inline#ifdef __cplusplusextern"C"{#endif// Converts an array 32-bit floats to 16-bit floatsD3DXFLOAT16*WINAPID3DXFloat32To16Array(D3DXFLOAT16*pOut,CONSTFLOAT*pIn,UINTn);// Converts an array 16-bit floats to 32-bit floatsFLOAT*WINAPID3DXFloat16To32Array(FLOAT*pOut,CONSTD3DXFLOAT16*pIn,UINTn);#ifdef __cplusplus}#endif//--------------------------// 2D Vector//--------------------------// inlineFLOATD3DXVec2Length(CONSTD3DXVECTOR2*pV);FLOATD3DXVec2LengthSq(CONSTD3DXVECTOR2*pV);FLOATD3DXVec2Dot(CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);// Z component of ((x1,y1,0) cross (x2,y2,0))FLOATD3DXVec2CCW(CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);D3DXVECTOR2*D3DXVec2Add(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);D3DXVECTOR2*D3DXVec2Subtract(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);// Minimize each component. x = min(x1, x2), y = min(y1, y2)D3DXVECTOR2*D3DXVec2Minimize(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);// Maximize each component. x = max(x1, x2), y = max(y1, y2)D3DXVECTOR2*D3DXVec2Maximize(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2);D3DXVECTOR2*D3DXVec2Scale(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV,FLOATs);// Linear interpolation. V1 + s(V2-V1)D3DXVECTOR2*D3DXVec2Lerp(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2,FLOATs);// non-inline#ifdef __cplusplusextern"C"{#endifD3DXVECTOR2*WINAPID3DXVec2Normalize(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV);// Hermite interpolation between position V1, tangent T1 (when s == 0)// and position V2, tangent T2 (when s == 1).D3DXVECTOR2*WINAPID3DXVec2Hermite(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pT1,CONSTD3DXVECTOR2*pV2,CONSTD3DXVECTOR2*pT2,FLOATs);// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)D3DXVECTOR2*WINAPID3DXVec2CatmullRom(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV0,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2,CONSTD3DXVECTOR2*pV3,FLOATs);// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)D3DXVECTOR2*WINAPID3DXVec2BaryCentric(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV1,CONSTD3DXVECTOR2*pV2,CONSTD3DXVECTOR2*pV3,FLOATf,FLOATg);// Transform (x, y, 0, 1) by matrix.D3DXVECTOR4*WINAPID3DXVec2Transform(D3DXVECTOR4*pOut,CONSTD3DXVECTOR2*pV,CONSTD3DXMATRIX*pM);// Transform (x, y, 0, 1) by matrix, project result back into w=1.D3DXVECTOR2*WINAPID3DXVec2TransformCoord(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV,CONSTD3DXMATRIX*pM);// Transform (x, y, 0, 0) by matrix.D3DXVECTOR2*WINAPID3DXVec2TransformNormal(D3DXVECTOR2*pOut,CONSTD3DXVECTOR2*pV,CONSTD3DXMATRIX*pM);// Transform Array (x, y, 0, 1) by matrix.D3DXVECTOR4*WINAPID3DXVec2TransformArray(D3DXVECTOR4*pOut,UINTOutStride,CONSTD3DXVECTOR2*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);// Transform Array (x, y, 0, 1) by matrix, project result back into w=1.D3DXVECTOR2*WINAPID3DXVec2TransformCoordArray(D3DXVECTOR2*pOut,UINTOutStride,CONSTD3DXVECTOR2*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);// Transform Array (x, y, 0, 0) by matrix.D3DXVECTOR2*WINAPID3DXVec2TransformNormalArray(D3DXVECTOR2*pOut,UINTOutStride,CONSTD3DXVECTOR2*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);#ifdef __cplusplus}#endif//--------------------------// 3D Vector//--------------------------// inlineFLOATD3DXVec3Length(CONSTD3DXVECTOR3*pV);FLOATD3DXVec3LengthSq(CONSTD3DXVECTOR3*pV);FLOATD3DXVec3Dot(CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);D3DXVECTOR3*D3DXVec3Cross(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);D3DXVECTOR3*D3DXVec3Add(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);D3DXVECTOR3*D3DXVec3Subtract(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);// Minimize each component. x = min(x1, x2), y = min(y1, y2), ...D3DXVECTOR3*D3DXVec3Minimize(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);// Maximize each component. x = max(x1, x2), y = max(y1, y2), ...D3DXVECTOR3*D3DXVec3Maximize(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);D3DXVECTOR3*D3DXVec3Scale(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV,FLOATs);// Linear interpolation. V1 + s(V2-V1)D3DXVECTOR3*D3DXVec3Lerp(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2,FLOATs);// non-inline#ifdef __cplusplusextern"C"{#endifD3DXVECTOR3*WINAPID3DXVec3Normalize(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV);// Hermite interpolation between position V1, tangent T1 (when s == 0)// and position V2, tangent T2 (when s == 1).D3DXVECTOR3*WINAPID3DXVec3Hermite(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pT1,CONSTD3DXVECTOR3*pV2,CONSTD3DXVECTOR3*pT2,FLOATs);// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)D3DXVECTOR3*WINAPID3DXVec3CatmullRom(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV0,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2,CONSTD3DXVECTOR3*pV3,FLOATs);// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)D3DXVECTOR3*WINAPID3DXVec3BaryCentric(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2,CONSTD3DXVECTOR3*pV3,FLOATf,FLOATg);// Transform (x, y, z, 1) by matrix.D3DXVECTOR4*WINAPID3DXVec3Transform(D3DXVECTOR4*pOut,CONSTD3DXVECTOR3*pV,CONSTD3DXMATRIX*pM);// Transform (x, y, z, 1) by matrix, project result back into w=1.D3DXVECTOR3*WINAPID3DXVec3TransformCoord(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV,CONSTD3DXMATRIX*pM);// Transform (x, y, z, 0) by matrix. If you transforming a normal by a // non-affine matrix, the matrix you pass to this function should be the // transpose of the inverse of the matrix you would use to transform a coord.D3DXVECTOR3*WINAPID3DXVec3TransformNormal(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV,CONSTD3DXMATRIX*pM);// Transform Array (x, y, z, 1) by matrix. D3DXVECTOR4*WINAPID3DXVec3TransformArray(D3DXVECTOR4*pOut,UINTOutStride,CONSTD3DXVECTOR3*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);// Transform Array (x, y, z, 1) by matrix, project result back into w=1.D3DXVECTOR3*WINAPID3DXVec3TransformCoordArray(D3DXVECTOR3*pOut,UINTOutStride,CONSTD3DXVECTOR3*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);// Transform (x, y, z, 0) by matrix. If you transforming a normal by a // non-affine matrix, the matrix you pass to this function should be the // transpose of the inverse of the matrix you would use to transform a coord.D3DXVECTOR3*WINAPID3DXVec3TransformNormalArray(D3DXVECTOR3*pOut,UINTOutStride,CONSTD3DXVECTOR3*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);// Project vector from object space into screen spaceD3DXVECTOR3*WINAPID3DXVec3Project(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV,CONSTD3DVIEWPORT9*pViewport,CONSTD3DXMATRIX*pProjection,CONSTD3DXMATRIX*pView,CONSTD3DXMATRIX*pWorld);// Project vector from screen space into object spaceD3DXVECTOR3*WINAPID3DXVec3Unproject(D3DXVECTOR3*pOut,CONSTD3DXVECTOR3*pV,CONSTD3DVIEWPORT9*pViewport,CONSTD3DXMATRIX*pProjection,CONSTD3DXMATRIX*pView,CONSTD3DXMATRIX*pWorld);// Project vector Array from object space into screen spaceD3DXVECTOR3*WINAPID3DXVec3ProjectArray(D3DXVECTOR3*pOut,UINTOutStride,CONSTD3DXVECTOR3*pV,UINTVStride,CONSTD3DVIEWPORT9*pViewport,CONSTD3DXMATRIX*pProjection,CONSTD3DXMATRIX*pView,CONSTD3DXMATRIX*pWorld,UINTn);// Project vector Array from screen space into object spaceD3DXVECTOR3*WINAPID3DXVec3UnprojectArray(D3DXVECTOR3*pOut,UINTOutStride,CONSTD3DXVECTOR3*pV,UINTVStride,CONSTD3DVIEWPORT9*pViewport,CONSTD3DXMATRIX*pProjection,CONSTD3DXMATRIX*pView,CONSTD3DXMATRIX*pWorld,UINTn);#ifdef __cplusplus}#endif//--------------------------// 4D Vector//--------------------------// inlineFLOATD3DXVec4Length(CONSTD3DXVECTOR4*pV);FLOATD3DXVec4LengthSq(CONSTD3DXVECTOR4*pV);FLOATD3DXVec4Dot(CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2);D3DXVECTOR4*D3DXVec4Add(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2);D3DXVECTOR4*D3DXVec4Subtract(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2);// Minimize each component. x = min(x1, x2), y = min(y1, y2), ...D3DXVECTOR4*D3DXVec4Minimize(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2);// Maximize each component. x = max(x1, x2), y = max(y1, y2), ...D3DXVECTOR4*D3DXVec4Maximize(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2);D3DXVECTOR4*D3DXVec4Scale(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV,FLOATs);// Linear interpolation. V1 + s(V2-V1)D3DXVECTOR4*D3DXVec4Lerp(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2,FLOATs);// non-inline#ifdef __cplusplusextern"C"{#endif// Cross-product in 4 dimensions.D3DXVECTOR4*WINAPID3DXVec4Cross(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2,CONSTD3DXVECTOR4*pV3);D3DXVECTOR4*WINAPID3DXVec4Normalize(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV);// Hermite interpolation between position V1, tangent T1 (when s == 0)// and position V2, tangent T2 (when s == 1).D3DXVECTOR4*WINAPID3DXVec4Hermite(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pT1,CONSTD3DXVECTOR4*pV2,CONSTD3DXVECTOR4*pT2,FLOATs);// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)D3DXVECTOR4*WINAPID3DXVec4CatmullRom(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV0,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2,CONSTD3DXVECTOR4*pV3,FLOATs);// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)D3DXVECTOR4*WINAPID3DXVec4BaryCentric(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV1,CONSTD3DXVECTOR4*pV2,CONSTD3DXVECTOR4*pV3,FLOATf,FLOATg);// Transform vector by matrix.D3DXVECTOR4*WINAPID3DXVec4Transform(D3DXVECTOR4*pOut,CONSTD3DXVECTOR4*pV,CONSTD3DXMATRIX*pM);// Transform vector array by matrix.D3DXVECTOR4*WINAPID3DXVec4TransformArray(D3DXVECTOR4*pOut,UINTOutStride,CONSTD3DXVECTOR4*pV,UINTVStride,CONSTD3DXMATRIX*pM,UINTn);#ifdef __cplusplus}#endif//--------------------------// 4D Matrix//--------------------------// inlineD3DXMATRIX*D3DXMatrixIdentity(D3DXMATRIX*pOut);BOOLD3DXMatrixIsIdentity(CONSTD3DXMATRIX*pM);// non-inline#ifdef __cplusplusextern"C"{#endifFLOATWINAPID3DXMatrixDeterminant(CONSTD3DXMATRIX*pM);HRESULTWINAPID3DXMatrixDecompose(D3DXVECTOR3*pOutScale,D3DXQUATERNION*pOutRotation,D3DXVECTOR3*pOutTranslation,CONSTD3DXMATRIX*pM);D3DXMATRIX*WINAPID3DXMatrixTranspose(D3DXMATRIX*pOut,CONSTD3DXMATRIX*pM);// Matrix multiplication. The result represents the transformation M2// followed by the transformation M1. (Out = M1 * M2)D3DXMATRIX*WINAPID3DXMatrixMultiply(D3DXMATRIX*pOut,CONSTD3DXMATRIX*pM1,CONSTD3DXMATRIX*pM2);// Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))D3DXMATRIX*WINAPID3DXMatrixMultiplyTranspose(D3DXMATRIX*pOut,CONSTD3DXMATRIX*pM1,CONSTD3DXMATRIX*pM2);// Calculate inverse of matrix. Inversion my fail, in which case NULL will// be returned. The determinant of pM is also returned it pfDeterminant// is non-NULL.D3DXMATRIX*WINAPID3DXMatrixInverse(D3DXMATRIX*pOut,FLOAT*pDeterminant,CONSTD3DXMATRIX*pM);// Build a matrix which scales by (sx, sy, sz)D3DXMATRIX*WINAPID3DXMatrixScaling(D3DXMATRIX*pOut,FLOATsx,FLOATsy,FLOATsz);// Build a matrix which translates by (x, y, z)D3DXMATRIX*WINAPID3DXMatrixTranslation(D3DXMATRIX*pOut,FLOATx,FLOATy,FLOATz);// Build a matrix which rotates around the X axisD3DXMATRIX*WINAPID3DXMatrixRotationX(D3DXMATRIX*pOut,FLOATAngle);// Build a matrix which rotates around the Y axisD3DXMATRIX*WINAPID3DXMatrixRotationY(D3DXMATRIX*pOut,FLOATAngle);// Build a matrix which rotates around the Z axisD3DXMATRIX*WINAPID3DXMatrixRotationZ(D3DXMATRIX*pOut,FLOATAngle);// Build a matrix which rotates around an arbitrary axisD3DXMATRIX*WINAPID3DXMatrixRotationAxis(D3DXMATRIX*pOut,CONSTD3DXVECTOR3*pV,FLOATAngle);// Build a matrix from a quaternionD3DXMATRIX*WINAPID3DXMatrixRotationQuaternion(D3DXMATRIX*pOut,CONSTD3DXQUATERNION*pQ);// Yaw around the Y axis, a pitch around the X axis,// and a roll around the Z axis.D3DXMATRIX*WINAPID3DXMatrixRotationYawPitchRoll(D3DXMATRIX*pOut,FLOATYaw,FLOATPitch,FLOATRoll);// Build transformation matrix. NULL arguments are treated as identity.// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * MtD3DXMATRIX*WINAPID3DXMatrixTransformation(D3DXMATRIX*pOut,CONSTD3DXVECTOR3*pScalingCenter,CONSTD3DXQUATERNION*pScalingRotation,CONSTD3DXVECTOR3*pScaling,CONSTD3DXVECTOR3*pRotationCenter,CONSTD3DXQUATERNION*pRotation,CONSTD3DXVECTOR3*pTranslation);// Build 2D transformation matrix in XY plane. NULL arguments are treated as identity.// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * MtD3DXMATRIX*WINAPID3DXMatrixTransformation2D(D3DXMATRIX*pOut,CONSTD3DXVECTOR2*pScalingCenter,FLOATScalingRotation,CONSTD3DXVECTOR2*pScaling,CONSTD3DXVECTOR2*pRotationCenter,FLOATRotation,CONSTD3DXVECTOR2*pTranslation);// Build affine transformation matrix. NULL arguments are treated as identity.// Mout = Ms * Mrc-1 * Mr * Mrc * MtD3DXMATRIX*WINAPID3DXMatrixAffineTransformation(D3DXMATRIX*pOut,FLOATScaling,CONSTD3DXVECTOR3*pRotationCenter,CONSTD3DXQUATERNION*pRotation,CONSTD3DXVECTOR3*pTranslation);// Build 2D affine transformation matrix in XY plane. NULL arguments are treated as identity.// Mout = Ms * Mrc-1 * Mr * Mrc * MtD3DXMATRIX*WINAPID3DXMatrixAffineTransformation2D(D3DXMATRIX*pOut,FLOATScaling,CONSTD3DXVECTOR2*pRotationCenter,FLOATRotation,CONSTD3DXVECTOR2*pTranslation);// Build a lookat matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixLookAtRH(D3DXMATRIX*pOut,CONSTD3DXVECTOR3*pEye,CONSTD3DXVECTOR3*pAt,CONSTD3DXVECTOR3*pUp);// Build a lookat matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixLookAtLH(D3DXMATRIX*pOut,CONSTD3DXVECTOR3*pEye,CONSTD3DXVECTOR3*pAt,CONSTD3DXVECTOR3*pUp);// Build a perspective projection matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveRH(D3DXMATRIX*pOut,FLOATw,FLOATh,FLOATzn,FLOATzf);// Build a perspective projection matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveLH(D3DXMATRIX*pOut,FLOATw,FLOATh,FLOATzn,FLOATzf);// Build a perspective projection matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveFovRH(D3DXMATRIX*pOut,FLOATfovy,FLOATAspect,FLOATzn,FLOATzf);// Build a perspective projection matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveFovLH(D3DXMATRIX*pOut,FLOATfovy,FLOATAspect,FLOATzn,FLOATzf);// Build a perspective projection matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX*pOut,FLOATl,FLOATr,FLOATb,FLOATt,FLOATzn,FLOATzf);// Build a perspective projection matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX*pOut,FLOATl,FLOATr,FLOATb,FLOATt,FLOATzn,FLOATzf);// Build an ortho projection matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixOrthoRH(D3DXMATRIX*pOut,FLOATw,FLOATh,FLOATzn,FLOATzf);// Build an ortho projection matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixOrthoLH(D3DXMATRIX*pOut,FLOATw,FLOATh,FLOATzn,FLOATzf);// Build an ortho projection matrix. (right-handed)D3DXMATRIX*WINAPID3DXMatrixOrthoOffCenterRH(D3DXMATRIX*pOut,FLOATl,FLOATr,FLOATb,FLOATt,FLOATzn,FLOATzf);// Build an ortho projection matrix. (left-handed)D3DXMATRIX*WINAPID3DXMatrixOrthoOffCenterLH(D3DXMATRIX*pOut,FLOATl,FLOATr,FLOATb,FLOATt,FLOATzn,FLOATzf);// Build a matrix which flattens geometry into a plane, as if casting// a shadow from a light.D3DXMATRIX*WINAPID3DXMatrixShadow(D3DXMATRIX*pOut,CONSTD3DXVECTOR4*pLight,CONSTD3DXPLANE*pPlane);// Build a matrix which reflects the coordinate system about a planeD3DXMATRIX*WINAPID3DXMatrixReflect(D3DXMATRIX*pOut,CONSTD3DXPLANE*pPlane);#ifdef __cplusplus}#endif//--------------------------// Quaternion//--------------------------// inlineFLOATD3DXQuaternionLength(CONSTD3DXQUATERNION*pQ);// Length squared, or "norm"FLOATD3DXQuaternionLengthSq(CONSTD3DXQUATERNION*pQ);FLOATD3DXQuaternionDot(CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pQ2);// (0, 0, 0, 1)D3DXQUATERNION*D3DXQuaternionIdentity(D3DXQUATERNION*pOut);BOOLD3DXQuaternionIsIdentity(CONSTD3DXQUATERNION*pQ);// (-x, -y, -z, w)D3DXQUATERNION*D3DXQuaternionConjugate(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ);// non-inline#ifdef __cplusplusextern"C"{#endif// Compute a quaternin's axis and angle of rotation. Expects unit quaternions.voidWINAPID3DXQuaternionToAxisAngle(CONSTD3DXQUATERNION*pQ,D3DXVECTOR3*pAxis,FLOAT*pAngle);// Build a quaternion from a rotation matrix.D3DXQUATERNION*WINAPID3DXQuaternionRotationMatrix(D3DXQUATERNION*pOut,CONSTD3DXMATRIX*pM);// Rotation about arbitrary axis.D3DXQUATERNION*WINAPID3DXQuaternionRotationAxis(D3DXQUATERNION*pOut,CONSTD3DXVECTOR3*pV,FLOATAngle);// Yaw around the Y axis, a pitch around the X axis,// and a roll around the Z axis.D3DXQUATERNION*WINAPID3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION*pOut,FLOATYaw,FLOATPitch,FLOATRoll);// Quaternion multiplication. The result represents the rotation Q2// followed by the rotation Q1. (Out = Q2 * Q1)D3DXQUATERNION*WINAPID3DXQuaternionMultiply(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pQ2);D3DXQUATERNION*WINAPID3DXQuaternionNormalize(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ);// Conjugate and re-normD3DXQUATERNION*WINAPID3DXQuaternionInverse(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ);// Expects unit quaternions.// if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)D3DXQUATERNION*WINAPID3DXQuaternionLn(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ);// Expects pure quaternions. (w == 0) w is ignored in calculation.// if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)D3DXQUATERNION*WINAPID3DXQuaternionExp(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ);// Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).// Expects unit quaternions.D3DXQUATERNION*WINAPID3DXQuaternionSlerp(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pQ2,FLOATt);// Spherical quadrangle interpolation.// Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))D3DXQUATERNION*WINAPID3DXQuaternionSquad(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pA,CONSTD3DXQUATERNION*pB,CONSTD3DXQUATERNION*pC,FLOATt);// Setup control points for spherical quadrangle interpolation// from Q1 to Q2. The control points are chosen in such a way // to ensure the continuity of tangents with adjacent segments.voidWINAPID3DXQuaternionSquadSetup(D3DXQUATERNION*pAOut,D3DXQUATERNION*pBOut,D3DXQUATERNION*pCOut,CONSTD3DXQUATERNION*pQ0,CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pQ2,CONSTD3DXQUATERNION*pQ3);// Barycentric interpolation.// Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))D3DXQUATERNION*WINAPID3DXQuaternionBaryCentric(D3DXQUATERNION*pOut,CONSTD3DXQUATERNION*pQ1,CONSTD3DXQUATERNION*pQ2,CONSTD3DXQUATERNION*pQ3,FLOATf,FLOATg);#ifdef __cplusplus}#endif//--------------------------// Plane//--------------------------// inline// ax + by + cz + dwFLOATD3DXPlaneDot(CONSTD3DXPLANE*pP,CONSTD3DXVECTOR4*pV);// ax + by + cz + dFLOATD3DXPlaneDotCoord(CONSTD3DXPLANE*pP,CONSTD3DXVECTOR3*pV);// ax + by + czFLOATD3DXPlaneDotNormal(CONSTD3DXPLANE*pP,CONSTD3DXVECTOR3*pV);D3DXPLANE*D3DXPlaneScale(D3DXPLANE*pOut,CONSTD3DXPLANE*pP,FLOATs);// non-inline#ifdef __cplusplusextern"C"{#endif// Normalize plane (so that |a,b,c| == 1)D3DXPLANE*WINAPID3DXPlaneNormalize(D3DXPLANE*pOut,CONSTD3DXPLANE*pP);// Find the intersection between a plane and a line. If the line is// parallel to the plane, NULL is returned.D3DXVECTOR3*WINAPID3DXPlaneIntersectLine(D3DXVECTOR3*pOut,CONSTD3DXPLANE*pP,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2);// Construct a plane from a point and a normalD3DXPLANE*WINAPID3DXPlaneFromPointNormal(D3DXPLANE*pOut,CONSTD3DXVECTOR3*pPoint,CONSTD3DXVECTOR3*pNormal);// Construct a plane from 3 pointsD3DXPLANE*WINAPID3DXPlaneFromPoints(D3DXPLANE*pOut,CONSTD3DXVECTOR3*pV1,CONSTD3DXVECTOR3*pV2,CONSTD3DXVECTOR3*pV3);// Transform a plane by a matrix. The vector (a,b,c) must be normal.// M should be the inverse transpose of the transformation desired.D3DXPLANE*WINAPID3DXPlaneTransform(D3DXPLANE*pOut,CONSTD3DXPLANE*pP,CONSTD3DXMATRIX*pM);// Transform an array of planes by a matrix. The vectors (a,b,c) must be normal.// M should be the inverse transpose of the transformation desired.D3DXPLANE*WINAPID3DXPlaneTransformArray(D3DXPLANE*pOut,UINTOutStride,CONSTD3DXPLANE*pP,UINTPStride,CONSTD3DXMATRIX*pM,UINTn);#ifdef __cplusplus}#endif//--------------------------// Color//--------------------------// inline// (1-r, 1-g, 1-b, a)D3DXCOLOR*D3DXColorNegative(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC);D3DXCOLOR*D3DXColorAdd(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC1,CONSTD3DXCOLOR*pC2);D3DXCOLOR*D3DXColorSubtract(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC1,CONSTD3DXCOLOR*pC2);D3DXCOLOR*D3DXColorScale(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC,FLOATs);// (r1*r2, g1*g2, b1*b2, a1*a2)D3DXCOLOR*D3DXColorModulate(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC1,CONSTD3DXCOLOR*pC2);// Linear interpolation of r,g,b, and a. C1 + s(C2-C1)D3DXCOLOR*D3DXColorLerp(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC1,CONSTD3DXCOLOR*pC2,FLOATs);// non-inline#ifdef __cplusplusextern"C"{#endif// Interpolate r,g,b between desaturated color and color.// DesaturatedColor + s(Color - DesaturatedColor)D3DXCOLOR*WINAPID3DXColorAdjustSaturation(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC,FLOATs);// Interpolate r,g,b between 50% grey and color. Grey + s(Color - Grey)D3DXCOLOR*WINAPID3DXColorAdjustContrast(D3DXCOLOR*pOut,CONSTD3DXCOLOR*pC,FLOATc);#ifdef __cplusplus}#endif//--------------------------// Misc//--------------------------#ifdef __cplusplusextern"C"{#endif// Calculate Fresnel term given the cosine of theta (likely obtained by// taking the dot of two normals), and the refraction index of the material.FLOATWINAPID3DXFresnelTerm(FLOATCosTheta,FLOATRefractionIndex);#ifdef __cplusplus}#endif//===========================================================================//// Matrix Stack////===========================================================================typedefinterfaceID3DXMatrixStackID3DXMatrixStack;typedefinterfaceID3DXMatrixStack*LPD3DXMATRIXSTACK;// {C7885BA7-F990-4fe7-922D-8515E477DD85}DEFINE_GUID(IID_ID3DXMatrixStack,0xc7885ba7,0xf990,0x4fe7,0x92,0x2d,0x85,0x15,0xe4,0x77,0xdd,0x85);#undef INTERFACE#define INTERFACE ID3DXMatrixStackDECLARE_INTERFACE_(ID3DXMatrixStack,IUnknown){//// IUnknown methods//STDMETHOD(QueryInterface)(THIS_REFIIDriid,LPVOID*ppvObj)PURE;STDMETHOD_(ULONG,AddRef)(THIS)PURE;STDMETHOD_(ULONG,Release)(THIS)PURE;//// ID3DXMatrixStack methods//// Pops the top of the stack, returns the current top// *after* popping the top.STDMETHOD(Pop)(THIS)PURE;// Pushes the stack by one, duplicating the current matrix.STDMETHOD(Push)(THIS)PURE;// Loads identity in the current matrix.STDMETHOD(LoadIdentity)(THIS)PURE;// Loads the given matrix into the current matrixSTDMETHOD(LoadMatrix)(THIS_CONSTD3DXMATRIX*pM)PURE;// Right-Multiplies the given matrix to the current matrix.// (transformation is about the current world origin)STDMETHOD(MultMatrix)(THIS_CONSTD3DXMATRIX*pM)PURE;// Left-Multiplies the given matrix to the current matrix// (transformation is about the local origin of the object)STDMETHOD(MultMatrixLocal)(THIS_CONSTD3DXMATRIX*pM)PURE;// Right multiply the current matrix with the computed rotation// matrix, counterclockwise about the given axis with the given angle.// (rotation is about the current world origin)STDMETHOD(RotateAxis)(THIS_CONSTD3DXVECTOR3*pV,FLOATAngle)PURE;// Left multiply the current matrix with the computed rotation// matrix, counterclockwise about the given axis with the given angle.// (rotation is about the local origin of the object)STDMETHOD(RotateAxisLocal)(THIS_CONSTD3DXVECTOR3*pV,FLOATAngle)PURE;// Right multiply the current matrix with the computed rotation// matrix. All angles are counterclockwise. (rotation is about the// current world origin)// The rotation is composed of a yaw around the Y axis, a pitch around// the X axis, and a roll around the Z axis.STDMETHOD(RotateYawPitchRoll)(THIS_FLOATYaw,FLOATPitch,FLOATRoll)PURE;// Left multiply the current matrix with the computed rotation// matrix. All angles are counterclockwise. (rotation is about the// local origin of the object)// The rotation is composed of a yaw around the Y axis, a pitch around// the X axis, and a roll around the Z axis.STDMETHOD(RotateYawPitchRollLocal)(THIS_FLOATYaw,FLOATPitch,FLOATRoll)PURE;// Right multiply the current matrix with the computed scale// matrix. (transformation is about the current world origin)STDMETHOD(Scale)(THIS_FLOATx,FLOATy,FLOATz)PURE;// Left multiply the current matrix with the computed scale// matrix. (transformation is about the local origin of the object)STDMETHOD(ScaleLocal)(THIS_FLOATx,FLOATy,FLOATz)PURE;// Right multiply the current matrix with the computed translation// matrix. (transformation is about the current world origin)STDMETHOD(Translate)(THIS_FLOATx,FLOATy,FLOATz)PURE;// Left multiply the current matrix with the computed translation// matrix. (transformation is about the local origin of the object)STDMETHOD(TranslateLocal)(THIS_FLOATx,FLOATy,FLOATz)PURE;// Obtain the current matrix at the top of the stackSTDMETHOD_(D3DXMATRIX*,GetTop)(THIS)PURE;};#ifdef __cplusplusextern"C"{#endifHRESULTWINAPID3DXCreateMatrixStack(DWORDFlags,LPD3DXMATRIXSTACK*ppStack);#ifdef __cplusplus}#endif//===========================================================================//// Spherical Harmonic Runtime Routines//// NOTE:// * Most of these functions can take the same object as in and out parameters.// The exceptions are the rotation functions. //// * Out parameters are typically also returned as return values, so that// the output of one function may be used as a parameter to another.////============================================================================// non-inline#ifdef __cplusplusextern"C"{#endif//============================================================================//// Basic Spherical Harmonic math routines////============================================================================#define D3DXSH_MINORDER 2#define D3DXSH_MAXORDER 6//============================================================================//// D3DXSHEvalDirection:// --------------------// Evaluates the Spherical Harmonic basis functions//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned.// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pDir// Direction to evaluate in - assumed to be normalized////============================================================================FLOAT*WINAPID3DXSHEvalDirection(FLOAT*pOut,UINTOrder,CONSTD3DXVECTOR3*pDir);//============================================================================//// D3DXSHRotate:// --------------------// Rotates SH vector by a rotation matrix//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned (should not alias with pIn.)// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pMatrix// Matrix used for rotation - rotation sub matrix should be orthogonal// and have a unit determinant.// pIn// Input SH coeffs (rotated), incorect results if this is also output.////============================================================================FLOAT*WINAPID3DXSHRotate(FLOAT*pOut,UINTOrder,CONSTD3DXMATRIX*pMatrix,CONSTFLOAT*pIn);//============================================================================//// D3DXSHRotateZ:// --------------------// Rotates the SH vector in the Z axis by an angle//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned (should not alias with pIn.)// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// Angle// Angle in radians to rotate around the Z axis.// pIn// Input SH coeffs (rotated), incorect results if this is also output.////============================================================================FLOAT*WINAPID3DXSHRotateZ(FLOAT*pOut,UINTOrder,FLOATAngle,CONSTFLOAT*pIn);//============================================================================//// D3DXSHAdd:// --------------------// Adds two SH vectors, pOut[i] = pA[i] + pB[i];//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned.// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pA// Input SH coeffs.// pB// Input SH coeffs (second vector.)////============================================================================FLOAT*WINAPID3DXSHAdd(FLOAT*pOut,UINTOrder,CONSTFLOAT*pA,CONSTFLOAT*pB);//============================================================================//// D3DXSHScale:// --------------------// Adds two SH vectors, pOut[i] = pA[i]*Scale;//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned.// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pIn// Input SH coeffs.// Scale// Scale factor.////============================================================================FLOAT*WINAPID3DXSHScale(FLOAT*pOut,UINTOrder,CONSTFLOAT*pIn,CONSTFLOATScale);//============================================================================//// D3DXSHDot:// --------------------// Computes the dot product of two SH vectors//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pA// Input SH coeffs.// pB// Second set of input SH coeffs.////============================================================================FLOATWINAPID3DXSHDot(UINTOrder,CONSTFLOAT*pA,CONSTFLOAT*pB);//============================================================================//// D3DXSHMultiply[O]:// --------------------// Computes the product of two functions represented using SH (f and g), where:// pOut[i] = int(y_i(s) * f(s) * g(s)), where y_i(s) is the ith SH basis// function, f(s) and g(s) are SH functions (sum_i(y_i(s)*c_i)). The order O// determines the lengths of the arrays, where there should always be O^2 // coefficients. In general the product of two SH functions of order O generates// and SH function of order 2*O - 1, but we truncate the result. This means// that the product commutes (f*g == g*f) but doesn't associate // (f*(g*h) != (f*g)*h.//// Parameters:// pOut// Output SH coefficients - basis function Ylm is stored at l*l + m+l// This is the pointer that is returned.// pF// Input SH coeffs for first function.// pG// Second set of input SH coeffs.////============================================================================FLOAT*WINAPID3DXSHMultiply2(FLOAT*pOut,CONSTFLOAT*pF,CONSTFLOAT*pG);FLOAT*WINAPID3DXSHMultiply3(FLOAT*pOut,CONSTFLOAT*pF,CONSTFLOAT*pG);FLOAT*WINAPID3DXSHMultiply4(FLOAT*pOut,CONSTFLOAT*pF,CONSTFLOAT*pG);FLOAT*WINAPID3DXSHMultiply5(FLOAT*pOut,CONSTFLOAT*pF,CONSTFLOAT*pG);FLOAT*WINAPID3DXSHMultiply6(FLOAT*pOut,CONSTFLOAT*pF,CONSTFLOAT*pG);//============================================================================//// Basic Spherical Harmonic lighting routines////============================================================================//============================================================================//// D3DXSHEvalDirectionalLight:// --------------------// Evaluates a directional light and returns spectral SH data. The output // vector is computed so that if the intensity of R/G/B is unit the resulting// exit radiance of a point directly under the light on a diffuse object with// an albedo of 1 would be 1.0. This will compute 3 spectral samples, pROut// has to be specified, while pGout and pBout are optional.//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pDir// Direction light is coming from (assumed to be normalized.)// RIntensity// Red intensity of light.// GIntensity// Green intensity of light.// BIntensity// Blue intensity of light.// pROut// Output SH vector for Red.// pGOut// Output SH vector for Green (optional.)// pBOut// Output SH vector for Blue (optional.) ////============================================================================HRESULTWINAPID3DXSHEvalDirectionalLight(UINTOrder,CONSTD3DXVECTOR3*pDir,FLOATRIntensity,FLOATGIntensity,FLOATBIntensity,FLOAT*pROut,FLOAT*pGOut,FLOAT*pBOut);//============================================================================//// D3DXSHEvalSphericalLight:// --------------------// Evaluates a spherical light and returns spectral SH data. There is no // normalization of the intensity of the light like there is for directional// lights, care has to be taken when specifiying the intensities. This will // compute 3 spectral samples, pROut has to be specified, while pGout and // pBout are optional.//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pPos// Position of light - reciever is assumed to be at the origin.// Radius// Radius of the spherical light source.// RIntensity// Red intensity of light.// GIntensity// Green intensity of light.// BIntensity// Blue intensity of light.// pROut// Output SH vector for Red.// pGOut// Output SH vector for Green (optional.)// pBOut// Output SH vector for Blue (optional.) ////============================================================================HRESULTWINAPID3DXSHEvalSphericalLight(UINTOrder,CONSTD3DXVECTOR3*pPos,FLOATRadius,FLOATRIntensity,FLOATGIntensity,FLOATBIntensity,FLOAT*pROut,FLOAT*pGOut,FLOAT*pBOut);//============================================================================//// D3DXSHEvalConeLight:// --------------------// Evaluates a light that is a cone of constant intensity and returns spectral// SH data. The output vector is computed so that if the intensity of R/G/B is// unit the resulting exit radiance of a point directly under the light oriented// in the cone direction on a diffuse object with an albedo of 1 would be 1.0.// This will compute 3 spectral samples, pROut has to be specified, while pGout// and pBout are optional.//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pDir// Direction light is coming from (assumed to be normalized.)// Radius// Radius of cone in radians.// RIntensity// Red intensity of light.// GIntensity// Green intensity of light.// BIntensity// Blue intensity of light.// pROut// Output SH vector for Red.// pGOut// Output SH vector for Green (optional.)// pBOut// Output SH vector for Blue (optional.) ////============================================================================HRESULTWINAPID3DXSHEvalConeLight(UINTOrder,CONSTD3DXVECTOR3*pDir,FLOATRadius,FLOATRIntensity,FLOATGIntensity,FLOATBIntensity,FLOAT*pROut,FLOAT*pGOut,FLOAT*pBOut);//============================================================================//// D3DXSHEvalHemisphereLight:// --------------------// Evaluates a light that is a linear interpolant between two colors over the// sphere. The interpolant is linear along the axis of the two points, not// over the surface of the sphere (ie: if the axis was (0,0,1) it is linear in// Z, not in the azimuthal angle.) The resulting spherical lighting function// is normalized so that a point on a perfectly diffuse surface with no// shadowing and a normal pointed in the direction pDir would result in exit// radiance with a value of 1 if the top color was white and the bottom color// was black. This is a very simple model where Top represents the intensity // of the "sky" and Bottom represents the intensity of the "ground".//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pDir// Axis of the hemisphere.// Top// Color of the upper hemisphere.// Bottom// Color of the lower hemisphere.// pROut// Output SH vector for Red.// pGOut// Output SH vector for Green// pBOut// Output SH vector for Blue ////============================================================================HRESULTWINAPID3DXSHEvalHemisphereLight(UINTOrder,CONSTD3DXVECTOR3*pDir,D3DXCOLORTop,D3DXCOLORBottom,FLOAT*pROut,FLOAT*pGOut,FLOAT*pBOut);//============================================================================//// Basic Spherical Harmonic projection routines////============================================================================//============================================================================//// D3DXSHProjectCubeMap:// --------------------// Projects a function represented on a cube map into spherical harmonics.//// Parameters:// Order// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1// pCubeMap// CubeMap that is going to be projected into spherical harmonics// pROut// Output SH vector for Red.// pGOut// Output SH vector for Green// pBOut// Output SH vector for Blue ////============================================================================HRESULTWINAPID3DXSHProjectCubeMap(UINTuOrder,LPDIRECT3DCUBETEXTURE9pCubeMap,FLOAT*pROut,FLOAT*pGOut,FLOAT*pBOut);#ifdef __cplusplus}#endif#include"d3dx9math.inl"#ifdef _MSC_VER#if _MSC_VER >= 1200#pragma warning(pop)#else#pragma warning(default:4201)#endif#endif // _MSC_VER#endif // __D3DX9MATH_H__