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.

1215 lines
37 KiB

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