d3dxmath.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:33k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dxmath.h
  6. //  Content:    D3DX math types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #ifndef __D3DXMATH_H__
  10. #define __D3DXMATH_H__
  11. #include <d3d.h>
  12. #include <math.h>
  13. #include <limits.h>
  14. #include "d3dxerr.h"
  15. #ifndef D3DXINLINE
  16. #ifdef __cplusplus
  17. #define D3DXINLINE inline
  18. #else
  19. #define D3DXINLINE _inline
  20. #endif
  21. #endif
  22. #pragma warning(disable:4201) // anonymous unions warning
  23. typedef struct ID3DXMatrixStack *LPD3DXMATRIXSTACK;
  24. // {E3357330-CC5E-11d2-A434-00A0C90629A8}
  25. DEFINE_GUID( IID_ID3DXMatrixStack,
  26.              0xe3357330, 0xcc5e, 0x11d2, 0xa4, 0x34, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0xa8);
  27. //===========================================================================
  28. //
  29. // General purpose utilities
  30. //
  31. //===========================================================================
  32. #define D3DX_PI    ((float)  3.141592654f)
  33. #define D3DX_1BYPI ((float)  0.318309886f)
  34. #define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
  35. #define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
  36. //===========================================================================
  37. //
  38. // Vectors
  39. //
  40. //===========================================================================
  41. //--------------------------
  42. // 2D Vector
  43. //--------------------------
  44. typedef struct D3DXVECTOR2
  45. {
  46. #ifdef __cplusplus
  47. public:
  48.     D3DXVECTOR2() {};
  49.     D3DXVECTOR2( const float * );
  50.     D3DXVECTOR2( float x, float y );
  51.     // casting
  52.     operator float* ();
  53.     operator const float* () const;
  54.     // assignment operators
  55.     D3DXVECTOR2& operator += ( const D3DXVECTOR2& );
  56.     D3DXVECTOR2& operator -= ( const D3DXVECTOR2& );
  57.     D3DXVECTOR2& operator *= ( float );
  58.     D3DXVECTOR2& operator /= ( float );
  59.     // unary operators
  60.     D3DXVECTOR2 operator + () const;
  61.     D3DXVECTOR2 operator - () const;
  62.     // binary operators
  63.     D3DXVECTOR2 operator + ( const D3DXVECTOR2& ) const;
  64.     D3DXVECTOR2 operator - ( const D3DXVECTOR2& ) const;
  65.     D3DXVECTOR2 operator * ( float ) const;
  66.     D3DXVECTOR2 operator / ( float ) const;
  67.     friend D3DXVECTOR2 operator * ( float, const D3DXVECTOR2& );
  68.     BOOL operator == ( const D3DXVECTOR2& ) const;
  69.     BOOL operator != ( const D3DXVECTOR2& ) const;
  70. public:
  71. #endif //__cplusplus
  72.     float x, y;
  73. } D3DXVECTOR2, *LPD3DXVECTOR2;
  74. //--------------------------
  75. // 3D Vector
  76. //--------------------------
  77. typedef struct D3DXVECTOR3
  78. {
  79. #ifdef __cplusplus
  80. public:
  81.     D3DXVECTOR3() {};
  82.     D3DXVECTOR3( const float * );
  83.     D3DXVECTOR3( const D3DVECTOR& );
  84.     D3DXVECTOR3( float x, float y, float z );
  85.     // casting
  86.     operator float* ();
  87.     operator const float* () const;
  88.     operator D3DVECTOR* ();
  89.     operator const D3DVECTOR* () const;
  90.     operator D3DVECTOR& ();
  91.     operator const D3DVECTOR& () const;
  92.     // assignment operators
  93.     D3DXVECTOR3& operator += ( const D3DXVECTOR3& );
  94.     D3DXVECTOR3& operator -= ( const D3DXVECTOR3& );
  95.     D3DXVECTOR3& operator *= ( float );
  96.     D3DXVECTOR3& operator /= ( float );
  97.     // unary operators
  98.     D3DXVECTOR3 operator + () const;
  99.     D3DXVECTOR3 operator - () const;
  100.     // binary operators
  101.     D3DXVECTOR3 operator + ( const D3DXVECTOR3& ) const;
  102.     D3DXVECTOR3 operator - ( const D3DXVECTOR3& ) const;
  103.     D3DXVECTOR3 operator * ( float ) const;
  104.     D3DXVECTOR3 operator / ( float ) const;
  105.     friend D3DXVECTOR3 operator * ( float, const struct D3DXVECTOR3& );
  106.     BOOL operator == ( const D3DXVECTOR3& ) const;
  107.     BOOL operator != ( const D3DXVECTOR3& ) const;
  108. public:
  109. #endif //__cplusplus
  110.     float x, y, z;
  111. } D3DXVECTOR3, *LPD3DXVECTOR3;
  112. //--------------------------
  113. // 4D Vector
  114. //--------------------------
  115. typedef struct D3DXVECTOR4
  116. {
  117. #ifdef __cplusplus
  118. public:
  119.     D3DXVECTOR4() {};
  120.     D3DXVECTOR4( const float* );
  121.     D3DXVECTOR4( float x, float y, float z, float w );
  122.     // casting
  123.     operator float* ();
  124.     operator const float* () const;
  125.     // assignment operators
  126.     D3DXVECTOR4& operator += ( const D3DXVECTOR4& );
  127.     D3DXVECTOR4& operator -= ( const D3DXVECTOR4& );
  128.     D3DXVECTOR4& operator *= ( float );
  129.     D3DXVECTOR4& operator /= ( float );
  130.     // unary operators
  131.     D3DXVECTOR4 operator + () const;
  132.     D3DXVECTOR4 operator - () const;
  133.     // binary operators
  134.     D3DXVECTOR4 operator + ( const D3DXVECTOR4& ) const;
  135.     D3DXVECTOR4 operator - ( const D3DXVECTOR4& ) const;
  136.     D3DXVECTOR4 operator * ( float ) const;
  137.     D3DXVECTOR4 operator / ( float ) const;
  138.     friend D3DXVECTOR4 operator * ( float, const D3DXVECTOR4& );
  139.     BOOL operator == ( const D3DXVECTOR4& ) const;
  140.     BOOL operator != ( const D3DXVECTOR4& ) const;
  141. public:
  142. #endif //__cplusplus
  143.     float x, y, z, w;
  144. } D3DXVECTOR4, *LPD3DXVECTOR4;
  145. //===========================================================================
  146. //
  147. // Matrices
  148. //
  149. //===========================================================================
  150. typedef struct D3DXMATRIX
  151. {
  152. #ifdef __cplusplus
  153. public:
  154.     D3DXMATRIX() {};
  155.     D3DXMATRIX( const float * );
  156.     D3DXMATRIX( const D3DMATRIX& );
  157.     D3DXMATRIX( float m00, float m01, float m02, float m03,
  158.                 float m10, float m11, float m12, float m13,
  159.                 float m20, float m21, float m22, float m23,
  160.                 float m30, float m31, float m32, float m33 );
  161.     // access grants
  162.     float& operator () ( UINT iRow, UINT iCol );
  163.     float  operator () ( UINT iRow, UINT iCol ) const;
  164.     // casting operators
  165.     operator float* ();
  166.     operator const float* () const;
  167.     operator D3DMATRIX* ();
  168.     operator const D3DMATRIX* () const;
  169.     operator D3DMATRIX& ();
  170.     operator const D3DMATRIX& () const;
  171.     // assignment operators
  172.     D3DXMATRIX& operator *= ( const D3DXMATRIX& );
  173.     D3DXMATRIX& operator += ( const D3DXMATRIX& );
  174.     D3DXMATRIX& operator -= ( const D3DXMATRIX& );
  175.     D3DXMATRIX& operator *= ( float );
  176.     D3DXMATRIX& operator /= ( float );
  177.     // unary operators
  178.     D3DXMATRIX operator + () const;
  179.     D3DXMATRIX operator - () const;
  180.     // binary operators
  181.     D3DXMATRIX operator * ( const D3DXMATRIX& ) const;
  182.     D3DXMATRIX operator + ( const D3DXMATRIX& ) const;
  183.     D3DXMATRIX operator - ( const D3DXMATRIX& ) const;
  184.     D3DXMATRIX operator * ( float ) const;
  185.     D3DXMATRIX operator / ( float ) const;
  186.     friend D3DXMATRIX operator * ( float, const D3DXMATRIX& );
  187.     BOOL operator == ( const D3DXMATRIX& ) const;
  188.     BOOL operator != ( const D3DXMATRIX& ) const;
  189. #endif //__cplusplus
  190.     union
  191.     {
  192.         float m[4][4];
  193. #ifdef __cplusplus
  194.         struct
  195.         {
  196.             float m00, m01, m02, m03;
  197.             float m10, m11, m12, m13;
  198.             float m20, m21, m22, m23;
  199.             float m30, m31, m32, m33;
  200.         };
  201. #endif //__cplusplus
  202.     };
  203. } D3DXMATRIX, *LPD3DXMATRIX;
  204. //===========================================================================
  205. //
  206. //    Quaternions
  207. //
  208. //===========================================================================
  209. typedef struct D3DXQUATERNION
  210. {
  211. #ifdef __cplusplus
  212. public:
  213.     D3DXQUATERNION() {}
  214.     D3DXQUATERNION( const float * );
  215.     D3DXQUATERNION( float x, float y, float z, float w );
  216.     // casting
  217.     operator float* ();
  218.     operator const float* () const;
  219.     // assignment operators
  220.     D3DXQUATERNION& operator += ( const D3DXQUATERNION& );
  221.     D3DXQUATERNION& operator -= ( const D3DXQUATERNION& );
  222.     D3DXQUATERNION& operator *= ( const D3DXQUATERNION& );
  223.     D3DXQUATERNION& operator *= ( float );
  224.     D3DXQUATERNION& operator /= ( float );
  225.     // unary operators
  226.     D3DXQUATERNION  operator + () const;
  227.     D3DXQUATERNION  operator - () const;
  228.     // binary operators
  229.     D3DXQUATERNION operator + ( const D3DXQUATERNION& ) const;
  230.     D3DXQUATERNION operator - ( const D3DXQUATERNION& ) const;
  231.     D3DXQUATERNION operator * ( const D3DXQUATERNION& ) const;
  232.     D3DXQUATERNION operator * ( float ) const;
  233.     D3DXQUATERNION operator / ( float ) const;
  234.     friend D3DXQUATERNION operator * (float, const D3DXQUATERNION& );
  235.     BOOL operator == ( const D3DXQUATERNION& ) const;
  236.     BOOL operator != ( const D3DXQUATERNION& ) const;
  237. #endif //__cplusplus
  238.     float x, y, z, w;
  239. } D3DXQUATERNION, *LPD3DXQUATERNION;
  240. //===========================================================================
  241. //
  242. // Planes
  243. //
  244. //===========================================================================
  245. typedef struct D3DXPLANE
  246. {
  247. #ifdef __cplusplus
  248. public:
  249.     D3DXPLANE() {}
  250.     D3DXPLANE( const float* );
  251.     D3DXPLANE( float a, float b, float c, float d );
  252.     // casting
  253.     operator float* ();
  254.     operator const float* () const;
  255.     // unary operators
  256.     D3DXPLANE operator + () const;
  257.     D3DXPLANE operator - () const;
  258.     // binary operators
  259.     BOOL operator == ( const D3DXPLANE& ) const;
  260.     BOOL operator != ( const D3DXPLANE& ) const;
  261. #endif //__cplusplus
  262.     float a, b, c, d;
  263. } D3DXPLANE, *LPD3DXPLANE;
  264. //===========================================================================
  265. //
  266. // Colors
  267. //
  268. //===========================================================================
  269. typedef struct D3DXCOLOR
  270. {
  271. #ifdef __cplusplus
  272. public:
  273.     D3DXCOLOR() {}
  274.     D3DXCOLOR( DWORD argb );
  275.     D3DXCOLOR( const float * );
  276.     D3DXCOLOR( const D3DCOLORVALUE& );
  277.     D3DXCOLOR( float r, float g, float b, float a );
  278.     // casting
  279.     operator DWORD () const;
  280.     operator float* ();
  281.     operator const float* () const;
  282.     operator D3DCOLORVALUE* ();
  283.     operator const D3DCOLORVALUE* () const;
  284.     operator D3DCOLORVALUE& ();
  285.     operator const D3DCOLORVALUE& () const;
  286.     // assignment operators
  287.     D3DXCOLOR& operator += ( const D3DXCOLOR& );
  288.     D3DXCOLOR& operator -= ( const D3DXCOLOR& );
  289.     D3DXCOLOR& operator *= ( float );
  290.     D3DXCOLOR& operator /= ( float );
  291.     // unary operators
  292.     D3DXCOLOR operator + () const;
  293.     D3DXCOLOR operator - () const;
  294.     // binary operators
  295.     D3DXCOLOR operator + ( const D3DXCOLOR& ) const;
  296.     D3DXCOLOR operator - ( const D3DXCOLOR& ) const;
  297.     D3DXCOLOR operator * ( float ) const;
  298.     D3DXCOLOR operator / ( float ) const;
  299.     friend D3DXCOLOR operator * (float, const D3DXCOLOR& );
  300.     BOOL operator == ( const D3DXCOLOR& ) const;
  301.     BOOL operator != ( const D3DXCOLOR& ) const;
  302. #endif //__cplusplus
  303.     FLOAT r, g, b, a;
  304. } D3DXCOLOR, *LPD3DXCOLOR;
  305. //===========================================================================
  306. //
  307. // D3DX math functions:
  308. //
  309. // NOTE:
  310. //  * All these functions can take the same object as in and out parameters.
  311. //
  312. //  * Out parameters are typically also returned as return values, so that
  313. //    the output of one function may be used as a parameter to another.
  314. //
  315. //===========================================================================
  316. //--------------------------
  317. // 2D Vector
  318. //--------------------------
  319. // inline
  320. float D3DXVec2Length
  321.     ( const D3DXVECTOR2 *pV );
  322. float D3DXVec2LengthSq
  323.     ( const D3DXVECTOR2 *pV );
  324. float D3DXVec2Dot
  325.     ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  326. // Z component of ((x1,y1,0) cross (x2,y2,0))
  327. float D3DXVec2CCW
  328.     ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  329. D3DXVECTOR2* D3DXVec2Add
  330.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  331. D3DXVECTOR2* D3DXVec2Subtract
  332.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  333. // Minimize each component.  x = min(x1, x2), y = min(y1, y2)
  334. D3DXVECTOR2* D3DXVec2Minimize
  335.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  336. // Maximize each component.  x = max(x1, x2), y = max(y1, y2)
  337. D3DXVECTOR2* D3DXVec2Maximize
  338.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  339. D3DXVECTOR2* D3DXVec2Scale
  340.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, float s );
  341. // Linear interpolation. V1 + s(V2-V1)
  342. D3DXVECTOR2* D3DXVec2Lerp
  343.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
  344.       float s );
  345. // non-inline
  346. #ifdef __cplusplus
  347. extern "C" {
  348. #endif
  349. D3DXVECTOR2* WINAPI D3DXVec2Normalize
  350.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV );
  351. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  352. // and position V2, tangent T2 (when s == 1).
  353. D3DXVECTOR2* WINAPI D3DXVec2Hermite
  354.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pT1,
  355.       const D3DXVECTOR2 *pV2, const D3DXVECTOR2 *pT2, float s );
  356. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  357. D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
  358.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
  359.       D3DXVECTOR2 *pV3, float f, float g);
  360. // Transform (x, y, 0, 1) by matrix.
  361. D3DXVECTOR4* WINAPI D3DXVec2Transform
  362.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  363. // Transform (x, y, 0, 1) by matrix, project result back into w=1.
  364. D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
  365.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  366. // Transform (x, y, 0, 0) by matrix.
  367. D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
  368.     ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  369. #ifdef __cplusplus
  370. }
  371. #endif
  372. //--------------------------
  373. // 3D Vector
  374. //--------------------------
  375. // inline
  376. float D3DXVec3Length
  377.     ( const D3DXVECTOR3 *pV );
  378. float D3DXVec3LengthSq
  379.     ( const D3DXVECTOR3 *pV );
  380. float D3DXVec3Dot
  381.     ( const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  382. D3DXVECTOR3* D3DXVec3Cross
  383.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  384. D3DXVECTOR3* D3DXVec3Add
  385.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  386. D3DXVECTOR3* D3DXVec3Subtract
  387.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  388. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  389. D3DXVECTOR3* D3DXVec3Minimize
  390.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  391. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  392. D3DXVECTOR3* D3DXVec3Maximize
  393.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  394. D3DXVECTOR3* D3DXVec3Scale
  395.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, float s);
  396. // Linear interpolation. V1 + s(V2-V1)
  397. D3DXVECTOR3* D3DXVec3Lerp
  398.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  399.       float s );
  400. // non-inline
  401. #ifdef __cplusplus
  402. extern "C" {
  403. #endif
  404. D3DXVECTOR3* WINAPI D3DXVec3Normalize
  405.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV );
  406. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  407. // and position V2, tangent T2 (when s == 1).
  408. D3DXVECTOR3* WINAPI D3DXVec3Hermite
  409.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pT1,
  410.       const D3DXVECTOR3 *pV2, const D3DXVECTOR3 *pT2, float s );
  411. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  412. D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
  413.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  414.       const D3DXVECTOR3 *pV3, float f, float g);
  415. // Transform (x, y, z, 1) by matrix.
  416. D3DXVECTOR4* WINAPI D3DXVec3Transform
  417.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  418. // Transform (x, y, z, 1) by matrix, project result back into w=1.
  419. D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
  420.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  421. // Transform (x, y, z, 0) by matrix.
  422. D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
  423.     ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  424. #ifdef __cplusplus
  425. }
  426. #endif
  427. //--------------------------
  428. // 4D Vector
  429. //--------------------------
  430. // inline
  431. float D3DXVec4Length
  432.     ( const D3DXVECTOR4 *pV );
  433. float D3DXVec4LengthSq
  434.     ( const D3DXVECTOR4 *pV );
  435. float D3DXVec4Dot
  436.     ( const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2 );
  437. D3DXVECTOR4* D3DXVec4Add
  438.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  439. D3DXVECTOR4* D3DXVec4Subtract
  440.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  441. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  442. D3DXVECTOR4* D3DXVec4Minimize
  443.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  444. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  445. D3DXVECTOR4* D3DXVec4Maximize
  446.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  447. D3DXVECTOR4* D3DXVec4Scale
  448.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, float s);
  449. // Linear interpolation. V1 + s(V2-V1)
  450. D3DXVECTOR4* D3DXVec4Lerp
  451.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  452.       float s );
  453. // non-inline
  454. #ifdef __cplusplus
  455. extern "C" {
  456. #endif
  457. // Cross-product in 4 dimensions.
  458. D3DXVECTOR4* WINAPI D3DXVec4Cross
  459.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  460.       const D3DXVECTOR4 *pV3);
  461. D3DXVECTOR4* WINAPI D3DXVec4Normalize
  462.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV );
  463. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  464. // and position V2, tangent T2 (when s == 1).
  465. D3DXVECTOR4* WINAPI D3DXVec4Hermite
  466.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pT1,
  467.       const D3DXVECTOR4 *pV2, const D3DXVECTOR4 *pT2, float s );
  468. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  469. D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
  470.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  471.       const D3DXVECTOR4 *pV3, float f, float g);
  472. // Transform vector by matrix.
  473. D3DXVECTOR4* WINAPI D3DXVec4Transform
  474.     ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, const D3DXMATRIX *pM );
  475. #ifdef __cplusplus
  476. }
  477. #endif
  478. //--------------------------
  479. // 4D Matrix
  480. //--------------------------
  481. // inline
  482. D3DXMATRIX* D3DXMatrixIdentity
  483.     ( D3DXMATRIX *pOut );
  484. BOOL D3DXMatrixIsIdentity
  485.     ( const D3DXMATRIX *pM );
  486. // non-inline
  487. #ifdef __cplusplus
  488. extern "C" {
  489. #endif
  490. float WINAPI D3DXMatrixfDeterminant
  491.     ( const D3DXMATRIX *pM );
  492. // Matrix multiplication.  The result represents the transformation M2 
  493. // followed by the transformation M1.  (Out = M1 * M2)
  494. D3DXMATRIX* WINAPI D3DXMatrixMultiply
  495.     ( D3DXMATRIX *pOut, const D3DXMATRIX *pM1, const D3DXMATRIX *pM2 );
  496. D3DXMATRIX* WINAPI D3DXMatrixTranspose
  497.     ( D3DXMATRIX *pOut, const D3DXMATRIX *pM );
  498. // Calculate inverse of matrix.  Inversion my fail, in which case NULL will
  499. // be returned.  The determinant of pM is also returned it pfDeterminant
  500. // is non-NULL.
  501. D3DXMATRIX* WINAPI D3DXMatrixInverse
  502.     ( D3DXMATRIX *pOut, float *pfDeterminant, const D3DXMATRIX *pM );
  503. // Build a matrix which scales by (sx, sy, sz)
  504. D3DXMATRIX* WINAPI D3DXMatrixScaling
  505.     ( D3DXMATRIX *pOut, float sx, float sy, float sz );
  506. // Build a matrix which translates by (x, y, z)
  507. D3DXMATRIX* WINAPI D3DXMatrixTranslation
  508.     ( D3DXMATRIX *pOut, float x, float y, float z );
  509. // Build a matrix which rotates around the X axis
  510. D3DXMATRIX* WINAPI D3DXMatrixRotationX
  511.     ( D3DXMATRIX *pOut, float angle );
  512. // Build a matrix which rotates around the Y axis
  513. D3DXMATRIX* WINAPI D3DXMatrixRotationY
  514.     ( D3DXMATRIX *pOut, float angle );
  515. // Build a matrix which rotates around the Z axis
  516. D3DXMATRIX* WINAPI D3DXMatrixRotationZ
  517.     ( D3DXMATRIX *pOut, float angle );
  518. // Build a matrix which rotates around an arbitrary axis
  519. D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
  520.     ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pV, float angle );
  521. // Build a matrix from a quaternion
  522. D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
  523.     ( D3DXMATRIX *pOut, const D3DXQUATERNION *pQ);
  524. // Yaw around the Y axis, a pitch around the X axis,
  525. // and a roll around the Z axis.
  526. D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
  527.     ( D3DXMATRIX *pOut, float yaw, float pitch, float roll );
  528. // Build transformation matrix.  NULL arguments are treated as identity.
  529. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  530. D3DXMATRIX* WINAPI D3DXMatrixTransformation
  531.     ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pScalingCenter,
  532.       const D3DXQUATERNION *pScalingRotation, const D3DXVECTOR3 *pScaling,
  533.       const D3DXVECTOR3 *pRotationCenter, const D3DXQUATERNION *pRotation,
  534.       const D3DXVECTOR3 *pTranslation);
  535. // Build affine transformation matrix.  NULL arguments are treated as identity.
  536. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  537. D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
  538.     ( D3DXMATRIX *pOut, float Scaling, const D3DXVECTOR3 *pRotationCenter,
  539.       const D3DXQUATERNION *pRotation, const D3DXVECTOR3 *pTranslation);
  540. // Build a lookat matrix. (right-handed)
  541. D3DXMATRIX* WINAPI D3DXMatrixLookAt
  542.     ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
  543.       const D3DXVECTOR3 *pUp );
  544. // Build a lookat matrix. (left-handed)
  545. D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
  546.     ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
  547.       const D3DXVECTOR3 *pUp );
  548. // Build a perspective projection matrix. (right-handed)
  549. D3DXMATRIX* WINAPI D3DXMatrixPerspective
  550.     ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  551. // Build a perspective projection matrix. (left-handed)
  552. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH
  553.     ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  554. // Build a perspective projection matrix. (right-handed)
  555. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFov
  556.     ( D3DXMATRIX *pOut, float fovy, float aspect, float zn, float zf );
  557. // Build a perspective projection matrix. (left-handed)
  558. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH
  559.     ( D3DXMATRIX *pOut, float fovy, float aspect, float zn, float zf );
  560. // Build a perspective projection matrix. (right-handed)
  561. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenter
  562.     ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  563.       float zf );
  564. // Build a perspective projection matrix. (left-handed)
  565. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH
  566.     ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  567.       float zf );
  568. // Build an ortho projection matrix. (right-handed)
  569. D3DXMATRIX* WINAPI D3DXMatrixOrtho
  570.     ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  571. // Build an ortho projection matrix. (left-handed)
  572. D3DXMATRIX* WINAPI D3DXMatrixOrthoLH
  573.     ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  574. // Build an ortho projection matrix. (right-handed)
  575. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenter
  576.     ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  577.       float zf );
  578. // Build an ortho projection matrix. (left-handed)
  579. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH
  580.     ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  581.       float zf );
  582. // Build a matrix which flattens geometry into a plane, as if casting
  583. // a shadow from a light.
  584. D3DXMATRIX* WINAPI D3DXMatrixShadow
  585.     ( D3DXMATRIX *pOut, const D3DXVECTOR4 *pLight,
  586.       const D3DXPLANE *pPlane );
  587. // Build a matrix which reflects the coordinate system about a plane
  588. D3DXMATRIX* WINAPI D3DXMatrixReflect
  589.     ( D3DXMATRIX *pOut, const D3DXPLANE *pPlane );
  590. #ifdef __cplusplus
  591. }
  592. #endif
  593. //--------------------------
  594. // Quaternion
  595. //--------------------------
  596. // inline
  597. float D3DXQuaternionLength
  598.     ( const D3DXQUATERNION *pQ );
  599. // Length squared, or "norm"
  600. float D3DXQuaternionLengthSq
  601.     ( const D3DXQUATERNION *pQ );
  602. float D3DXQuaternionDot
  603.     ( const D3DXQUATERNION *pQ1, const D3DXQUATERNION *pQ2 );
  604. // (0, 0, 0, 1)
  605. D3DXQUATERNION* D3DXQuaternionIdentity
  606.     ( D3DXQUATERNION *pOut );
  607. BOOL D3DXQuaternionIsIdentity
  608.     ( const D3DXQUATERNION *pQ );
  609. // (-x, -y, -z, w)
  610. D3DXQUATERNION* D3DXQuaternionConjugate
  611.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  612. // non-inline
  613. #ifdef __cplusplus
  614. extern "C" {
  615. #endif
  616. // Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
  617. void WINAPI D3DXQuaternionToAxisAngle
  618.     ( const D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, float *pAngle );
  619. // Build a quaternion from a rotation matrix.
  620. D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix
  621.     ( D3DXQUATERNION *pOut, const D3DXMATRIX *pM);
  622. // Rotation about arbitrary axis.
  623. D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis
  624.     ( D3DXQUATERNION *pOut, const D3DXVECTOR3 *pV, float angle );
  625. // Yaw around the Y axis, a pitch around the X axis,
  626. // and a roll around the Z axis.
  627. D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll
  628.     ( D3DXQUATERNION *pOut, float yaw, float pitch, float roll );
  629. // Quaternion multiplication.  The result represents the rotation Q2 
  630. // followed by the rotation Q1.  (Out = Q2 * Q1)
  631. D3DXQUATERNION* WINAPI D3DXQuaternionMultiply
  632.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  633.       const D3DXQUATERNION *pQ2 );
  634. D3DXQUATERNION* WINAPI D3DXQuaternionNormalize
  635.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  636. // Conjugate and re-norm
  637. D3DXQUATERNION* WINAPI D3DXQuaternionInverse
  638.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  639. // Expects unit quaternions.
  640. // if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
  641. D3DXQUATERNION* WINAPI D3DXQuaternionLn
  642.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  643. // Expects pure quaternions. (w == 0)  w is ignored in calculation.
  644. // if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
  645. D3DXQUATERNION* WINAPI D3DXQuaternionExp
  646.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  647. // Spherical linear interpolation between Q1 (s == 0) and Q2 (s == 1).
  648. // Expects unit quaternions.
  649. D3DXQUATERNION* WINAPI D3DXQuaternionSlerp
  650.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  651.       const D3DXQUATERNION *pQ2, float t );
  652. // Spherical quadrangle interpolation.
  653. // Slerp(Slerp(Q1, Q4, t), Slerp(Q2, Q3, t), 2t(1-t))
  654. D3DXQUATERNION* WINAPI D3DXQuaternionSquad
  655.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  656.       const D3DXQUATERNION *pQ2, const D3DXQUATERNION *pQ3,
  657.       const D3DXQUATERNION *pQ4, float t );
  658. // Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
  659. D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric
  660.     ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  661.       const D3DXQUATERNION *pQ2, const D3DXQUATERNION *pQ3,
  662.       float f, float g );
  663. #ifdef __cplusplus
  664. }
  665. #endif
  666. //--------------------------
  667. // Plane
  668. //--------------------------
  669. // inline
  670. // ax + by + cz + dw
  671. float D3DXPlaneDot
  672.     ( const D3DXPLANE *pP, const D3DXVECTOR4 *pV);
  673. // ax + by + cz + d
  674. float D3DXPlaneDotCoord
  675.     ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV);
  676. // ax + by + cz
  677. float D3DXPlaneDotNormal
  678.     ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV);
  679. // non-inline
  680. #ifdef __cplusplus
  681. extern "C" {
  682. #endif
  683. // Normalize plane (so that |a,b,c| == 1)
  684. D3DXPLANE* WINAPI D3DXPlaneNormalize
  685.     ( D3DXPLANE *pOut, const D3DXPLANE *pP);
  686. // Find the intersection between a plane and a line.  If the line is
  687. // parallel to the plane, NULL is returned.
  688. D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine
  689.     ( D3DXVECTOR3 *pOut, const D3DXPLANE *pP, const D3DXVECTOR3 *pV1,
  690.       const D3DXVECTOR3 *pV2);
  691. // Construct a plane from a point and a normal
  692. D3DXPLANE* WINAPI D3DXPlaneFromPointNormal
  693.     ( D3DXPLANE *pOut, const D3DXVECTOR3 *pPoint, const D3DXVECTOR3 *pNormal);
  694. // Construct a plane from 3 points
  695. D3DXPLANE* WINAPI D3DXPlaneFromPoints
  696.     ( D3DXPLANE *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  697.       const D3DXVECTOR3 *pV3);
  698. // Transform a plane by a matrix.  The vector (a,b,c) must be normal.
  699. // M must be an affine transform.
  700. D3DXPLANE* WINAPI D3DXPlaneTransform
  701.     ( D3DXPLANE *pOut, const D3DXPLANE *pP, const D3DXMATRIX *pM );
  702. #ifdef __cplusplus
  703. }
  704. #endif
  705. //--------------------------
  706. // Color
  707. //--------------------------
  708. // inline
  709. // (1-r, 1-g, 1-b, a)
  710. D3DXCOLOR* D3DXColorNegative
  711.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC);
  712. D3DXCOLOR* D3DXColorAdd
  713.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  714. D3DXCOLOR* D3DXColorSubtract
  715.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  716. D3DXCOLOR* D3DXColorScale
  717.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s);
  718. // (r1*r2, g1*g2, b1*b2, a1*a2)
  719. D3DXCOLOR* D3DXColorModulate
  720.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  721. // Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
  722. D3DXCOLOR* D3DXColorLerp
  723.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2, float s);
  724. // non-inline
  725. #ifdef __cplusplus
  726. extern "C" {
  727. #endif
  728. // Interpolate r,g,b between desaturated color and color.
  729. // DesaturatedColor + s(Color - DesaturatedColor)
  730. D3DXCOLOR* WINAPI D3DXColorAdjustSaturation
  731.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s);
  732. // Interpolate r,g,b between 50% grey and color.  Grey + s(Color - Grey)
  733. D3DXCOLOR* WINAPI D3DXColorAdjustContrast
  734.     (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float c);
  735. #ifdef __cplusplus
  736. }
  737. #endif
  738. //===========================================================================
  739. //
  740. //    Matrix Stack
  741. //
  742. //===========================================================================
  743. DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
  744. {
  745.     //
  746.     // IUnknown methods
  747.     //
  748.     STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  749.     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
  750.     STDMETHOD_(ULONG,Release)(THIS) PURE;
  751.     //
  752.     // ID3DXMatrixStack methods
  753.     //
  754.     // Pops the top of the stack, returns the current top
  755.     // *after* popping the top.
  756.     STDMETHOD(Pop)(THIS) PURE;
  757.     // Pushes the stack by one, duplicating the current matrix.
  758.     STDMETHOD(Push)(THIS) PURE;
  759.     // Loads identity in the current matrix.
  760.     STDMETHOD(LoadIdentity)(THIS) PURE;
  761.     // Loads the given matrix into the current matrix
  762.     STDMETHOD(LoadMatrix)(THIS_ const D3DXMATRIX* pM ) PURE;
  763.     // Right-Multiplies the given matrix to the current matrix.
  764.     // (transformation is about the current world origin)
  765.     STDMETHOD(MultMatrix)(THIS_ const D3DXMATRIX* pM ) PURE;
  766.     // Left-Multiplies the given matrix to the current matrix
  767.     // (transformation is about the local origin of the object)
  768.     STDMETHOD(MultMatrixLocal)(THIS_ const D3DXMATRIX* pM ) PURE;
  769.     // Right multiply the current matrix with the computed rotation
  770.     // matrix, counterclockwise about the given axis with the given angle.
  771.     // (rotation is about the current world origin)
  772.     STDMETHOD(RotateAxis)
  773.         (THIS_ const D3DXVECTOR3* pV, float angle) PURE;
  774.     // Left multiply the current matrix with the computed rotation
  775.     // matrix, counterclockwise about the given axis with the given angle.
  776.     // (rotation is about the local origin of the object)
  777.     STDMETHOD(RotateAxisLocal)
  778.         (THIS_ const D3DXVECTOR3* pV, float angle) PURE;
  779.     // Right multiply the current matrix with the computed rotation
  780.     // matrix. All angles are counterclockwise. (rotation is about the
  781.     // current world origin)
  782.     // The rotation is composed of a yaw around the Y axis, a pitch around
  783.     // the X axis, and a roll around the Z axis.
  784.     STDMETHOD(RotateYawPitchRoll)
  785.         (THIS_ float yaw, float pitch, float roll) PURE;
  786.     // Left multiply the current matrix with the computed rotation
  787.     // matrix. All angles are counterclockwise. (rotation is about the
  788.     // local origin of the object)
  789.     // The rotation is composed of a yaw around the Y axis, a pitch around
  790.     // the X axis, and a roll around the Z axis.
  791.     STDMETHOD(RotateYawPitchRollLocal)
  792.         (THIS_ float yaw, float pitch, float roll) PURE;
  793.     // Right multiply the current matrix with the computed scale
  794.     // matrix. (transformation is about the current world origin)
  795.     STDMETHOD(Scale)(THIS_ float x, float y, float z) PURE;
  796.     // Left multiply the current matrix with the computed scale
  797.     // matrix. (transformation is about the local origin of the object)
  798.     STDMETHOD(ScaleLocal)(THIS_ float x, float y, float z) PURE;
  799.     // Right multiply the current matrix with the computed translation
  800.     // matrix. (transformation is about the current world origin)
  801.     STDMETHOD(Translate)(THIS_ float x, float y, float z ) PURE;
  802.     // Left multiply the current matrix with the computed translation
  803.     // matrix. (transformation is about the local origin of the object)
  804.     STDMETHOD(TranslateLocal)(THIS_ float x, float y, float z) PURE;
  805.     // Obtain the current matrix at the top of the stack
  806.     STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
  807. };
  808. #ifdef __cplusplus
  809. extern "C" {
  810. #endif
  811. HRESULT WINAPI D3DXCreateMatrixStack( DWORD flags, LPD3DXMATRIXSTACK *ppStack );
  812. #ifdef __cplusplus
  813. }
  814. #endif
  815. #include "d3dxmath.inl"
  816. #pragma warning(default:4201)
  817. #endif // __D3DXMATH_H__