Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1092 lines
32 KiB

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