Source code of Windows XP (NT5)
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.

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