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.

1866 lines
59 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: D3DX10math.h
  6. // Content: D3DX10 math types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #include "D3DX10.h"
  10. // D3DX10 and D3DX9 math look the same. You can include either one into your project.
  11. // We are intentionally using the header define from D3DX9 math to prevent double-inclusion.
  12. #ifndef __D3DX9MATH_H__
  13. #define __D3DX9MATH_H__
  14. #include <math.h>
  15. #if _MSC_VER >= 1200
  16. #pragma warning(push)
  17. #endif
  18. #pragma warning(disable:4201) // anonymous unions warning
  19. //===========================================================================
  20. //
  21. // Type definitions from D3D9
  22. //
  23. //===========================================================================
  24. #ifndef D3DVECTOR_DEFINED
  25. typedef struct _D3DVECTOR {
  26. float x;
  27. float y;
  28. float z;
  29. } D3DVECTOR;
  30. #define D3DVECTOR_DEFINED
  31. #endif
  32. #ifndef D3DMATRIX_DEFINED
  33. typedef struct _D3DMATRIX {
  34. union {
  35. struct {
  36. float _11, _12, _13, _14;
  37. float _21, _22, _23, _24;
  38. float _31, _32, _33, _34;
  39. float _41, _42, _43, _44;
  40. };
  41. float m[4][4];
  42. };
  43. } D3DMATRIX;
  44. #define D3DMATRIX_DEFINED
  45. #endif
  46. //===========================================================================
  47. //
  48. // General purpose utilities
  49. //
  50. //===========================================================================
  51. #define D3DX_PI (3.14159265358979323846)
  52. #define D3DX_1BYPI ( 1.0 / D3DX_PI )
  53. #define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0))
  54. #define D3DXToDegree( radian ) ((radian) * (180.0 / D3DX_PI))
  55. //===========================================================================
  56. //
  57. // 16 bit floating point numbers
  58. //
  59. //===========================================================================
  60. #define D3DX_16F_DIG 3 // # of decimal digits of precision
  61. #define D3DX_16F_EPSILON 4.8875809e-4f // smallest such that 1.0 + epsilon != 1.0
  62. #define D3DX_16F_MANT_DIG 11 // # of bits in mantissa
  63. #define D3DX_16F_MAX 6.550400e+004 // max value
  64. #define D3DX_16F_MAX_10_EXP 4 // max decimal exponent
  65. #define D3DX_16F_MAX_EXP 15 // max binary exponent
  66. #define D3DX_16F_MIN 6.1035156e-5f // min positive value
  67. #define D3DX_16F_MIN_10_EXP (-4) // min decimal exponent
  68. #define D3DX_16F_MIN_EXP (-14) // min binary exponent
  69. #define D3DX_16F_RADIX 2 // exponent radix
  70. #define D3DX_16F_ROUNDS 1 // addition rounding: near
  71. #define D3DX_16F_SIGN_MASK 0x8000
  72. #define D3DX_16F_EXP_MASK 0x7C00
  73. #define D3DX_16F_FRAC_MASK 0x03FF
  74. typedef struct D3DXFLOAT16
  75. {
  76. #ifdef __cplusplus
  77. public:
  78. D3DXFLOAT16() {};
  79. D3DXFLOAT16( FLOAT );
  80. D3DXFLOAT16( CONST D3DXFLOAT16& );
  81. // casting
  82. operator FLOAT ();
  83. // binary operators
  84. BOOL operator == ( CONST D3DXFLOAT16& ) const;
  85. BOOL operator != ( CONST D3DXFLOAT16& ) const;
  86. protected:
  87. #endif //__cplusplus
  88. WORD value;
  89. } D3DXFLOAT16, *LPD3DXFLOAT16;
  90. //===========================================================================
  91. //
  92. // Vectors
  93. //
  94. //===========================================================================
  95. //--------------------------
  96. // 2D Vector
  97. //--------------------------
  98. typedef struct D3DXVECTOR2
  99. {
  100. #ifdef __cplusplus
  101. public:
  102. D3DXVECTOR2() {};
  103. D3DXVECTOR2( CONST FLOAT * );
  104. D3DXVECTOR2( CONST D3DXFLOAT16 * );
  105. D3DXVECTOR2( FLOAT x, FLOAT y );
  106. // casting
  107. operator FLOAT* ();
  108. operator CONST FLOAT* () const;
  109. // assignment operators
  110. D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& );
  111. D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& );
  112. D3DXVECTOR2& operator *= ( FLOAT );
  113. D3DXVECTOR2& operator /= ( FLOAT );
  114. // unary operators
  115. D3DXVECTOR2 operator + () const;
  116. D3DXVECTOR2 operator - () const;
  117. // binary operators
  118. D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const;
  119. D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const;
  120. D3DXVECTOR2 operator * ( FLOAT ) const;
  121. D3DXVECTOR2 operator / ( FLOAT ) const;
  122. friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& );
  123. BOOL operator == ( CONST D3DXVECTOR2& ) const;
  124. BOOL operator != ( CONST D3DXVECTOR2& ) const;
  125. public:
  126. #endif //__cplusplus
  127. FLOAT x, y;
  128. } D3DXVECTOR2, *LPD3DXVECTOR2;
  129. //--------------------------
  130. // 2D Vector (16 bit)
  131. //--------------------------
  132. typedef struct D3DXVECTOR2_16F
  133. {
  134. #ifdef __cplusplus
  135. public:
  136. D3DXVECTOR2_16F() {};
  137. D3DXVECTOR2_16F( CONST FLOAT * );
  138. D3DXVECTOR2_16F( CONST D3DXFLOAT16 * );
  139. D3DXVECTOR2_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y );
  140. // casting
  141. operator D3DXFLOAT16* ();
  142. operator CONST D3DXFLOAT16* () const;
  143. // binary operators
  144. BOOL operator == ( CONST D3DXVECTOR2_16F& ) const;
  145. BOOL operator != ( CONST D3DXVECTOR2_16F& ) const;
  146. public:
  147. #endif //__cplusplus
  148. D3DXFLOAT16 x, y;
  149. } D3DXVECTOR2_16F, *LPD3DXVECTOR2_16F;
  150. //--------------------------
  151. // 3D Vector
  152. //--------------------------
  153. #ifdef __cplusplus
  154. typedef struct D3DXVECTOR3 : public D3DVECTOR
  155. {
  156. public:
  157. D3DXVECTOR3() {};
  158. D3DXVECTOR3( CONST FLOAT * );
  159. D3DXVECTOR3( CONST D3DVECTOR& );
  160. D3DXVECTOR3( CONST D3DXFLOAT16 * );
  161. D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );
  162. // casting
  163. operator FLOAT* ();
  164. operator CONST FLOAT* () const;
  165. // assignment operators
  166. D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
  167. D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
  168. D3DXVECTOR3& operator *= ( FLOAT );
  169. D3DXVECTOR3& operator /= ( FLOAT );
  170. // unary operators
  171. D3DXVECTOR3 operator + () const;
  172. D3DXVECTOR3 operator - () const;
  173. // binary operators
  174. D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
  175. D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
  176. D3DXVECTOR3 operator * ( FLOAT ) const;
  177. D3DXVECTOR3 operator / ( FLOAT ) const;
  178. friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );
  179. BOOL operator == ( CONST D3DXVECTOR3& ) const;
  180. BOOL operator != ( CONST D3DXVECTOR3& ) const;
  181. } D3DXVECTOR3, *LPD3DXVECTOR3;
  182. #else //!__cplusplus
  183. typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
  184. #endif //!__cplusplus
  185. //--------------------------
  186. // 3D Vector (16 bit)
  187. //--------------------------
  188. typedef struct D3DXVECTOR3_16F
  189. {
  190. #ifdef __cplusplus
  191. public:
  192. D3DXVECTOR3_16F() {};
  193. D3DXVECTOR3_16F( CONST FLOAT * );
  194. D3DXVECTOR3_16F( CONST D3DVECTOR& );
  195. D3DXVECTOR3_16F( CONST D3DXFLOAT16 * );
  196. D3DXVECTOR3_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y, CONST D3DXFLOAT16 &z );
  197. // casting
  198. operator D3DXFLOAT16* ();
  199. operator CONST D3DXFLOAT16* () const;
  200. // binary operators
  201. BOOL operator == ( CONST D3DXVECTOR3_16F& ) const;
  202. BOOL operator != ( CONST D3DXVECTOR3_16F& ) const;
  203. public:
  204. #endif //__cplusplus
  205. D3DXFLOAT16 x, y, z;
  206. } D3DXVECTOR3_16F, *LPD3DXVECTOR3_16F;
  207. //--------------------------
  208. // 4D Vector
  209. //--------------------------
  210. typedef struct D3DXVECTOR4
  211. {
  212. #ifdef __cplusplus
  213. public:
  214. D3DXVECTOR4() {};
  215. D3DXVECTOR4( CONST FLOAT* );
  216. D3DXVECTOR4( CONST D3DXFLOAT16* );
  217. D3DXVECTOR4( CONST D3DVECTOR& xyz, FLOAT w );
  218. D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  219. // casting
  220. operator FLOAT* ();
  221. operator CONST FLOAT* () const;
  222. // assignment operators
  223. D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& );
  224. D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& );
  225. D3DXVECTOR4& operator *= ( FLOAT );
  226. D3DXVECTOR4& operator /= ( FLOAT );
  227. // unary operators
  228. D3DXVECTOR4 operator + () const;
  229. D3DXVECTOR4 operator - () const;
  230. // binary operators
  231. D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const;
  232. D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const;
  233. D3DXVECTOR4 operator * ( FLOAT ) const;
  234. D3DXVECTOR4 operator / ( FLOAT ) const;
  235. friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );
  236. BOOL operator == ( CONST D3DXVECTOR4& ) const;
  237. BOOL operator != ( CONST D3DXVECTOR4& ) const;
  238. public:
  239. #endif //__cplusplus
  240. FLOAT x, y, z, w;
  241. } D3DXVECTOR4, *LPD3DXVECTOR4;
  242. //--------------------------
  243. // 4D Vector (16 bit)
  244. //--------------------------
  245. typedef struct D3DXVECTOR4_16F
  246. {
  247. #ifdef __cplusplus
  248. public:
  249. D3DXVECTOR4_16F() {};
  250. D3DXVECTOR4_16F( CONST FLOAT * );
  251. D3DXVECTOR4_16F( CONST D3DXFLOAT16* );
  252. D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& xyz, CONST D3DXFLOAT16& w );
  253. D3DXVECTOR4_16F( CONST D3DXFLOAT16& x, CONST D3DXFLOAT16& y, CONST D3DXFLOAT16& z, CONST D3DXFLOAT16& w );
  254. // casting
  255. operator D3DXFLOAT16* ();
  256. operator CONST D3DXFLOAT16* () const;
  257. // binary operators
  258. BOOL operator == ( CONST D3DXVECTOR4_16F& ) const;
  259. BOOL operator != ( CONST D3DXVECTOR4_16F& ) const;
  260. public:
  261. #endif //__cplusplus
  262. D3DXFLOAT16 x, y, z, w;
  263. } D3DXVECTOR4_16F, *LPD3DXVECTOR4_16F;
  264. //===========================================================================
  265. //
  266. // Matrices
  267. //
  268. //===========================================================================
  269. #ifdef __cplusplus
  270. typedef struct D3DXMATRIX : public D3DMATRIX
  271. {
  272. public:
  273. D3DXMATRIX() {};
  274. D3DXMATRIX( CONST FLOAT * );
  275. D3DXMATRIX( CONST D3DMATRIX& );
  276. D3DXMATRIX( CONST D3DXFLOAT16 * );
  277. D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  278. FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  279. FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  280. FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
  281. // access grants
  282. FLOAT& operator () ( UINT Row, UINT Col );
  283. FLOAT operator () ( UINT Row, UINT Col ) const;
  284. // casting operators
  285. operator FLOAT* ();
  286. operator CONST FLOAT* () const;
  287. // assignment operators
  288. D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
  289. D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
  290. D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
  291. D3DXMATRIX& operator *= ( FLOAT );
  292. D3DXMATRIX& operator /= ( FLOAT );
  293. // unary operators
  294. D3DXMATRIX operator + () const;
  295. D3DXMATRIX operator - () const;
  296. // binary operators
  297. D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
  298. D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
  299. D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
  300. D3DXMATRIX operator * ( FLOAT ) const;
  301. D3DXMATRIX operator / ( FLOAT ) const;
  302. friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
  303. BOOL operator == ( CONST D3DXMATRIX& ) const;
  304. BOOL operator != ( CONST D3DXMATRIX& ) const;
  305. } D3DXMATRIX, *LPD3DXMATRIX;
  306. #else //!__cplusplus
  307. typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
  308. #endif //!__cplusplus
  309. //---------------------------------------------------------------------------
  310. // Aligned Matrices
  311. //
  312. // This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
  313. // It aligns matrices on the stack and on the heap or in global scope.
  314. // It does this using __declspec(align(16)) which works on VC7 and on VC 6
  315. // with the processor pack. Unfortunately there is no way to detect the
  316. // latter so this is turned on only on VC7. On other compilers this is the
  317. // the same as D3DXMATRIX.
  318. //
  319. // Using this class on a compiler that does not actually do the alignment
  320. // can be dangerous since it will not expose bugs that ignore alignment.
  321. // E.g if an object of this class in inside a struct or class, and some code
  322. // memcopys data in it assuming tight packing. This could break on a compiler
  323. // that eventually start aligning the matrix.
  324. //---------------------------------------------------------------------------
  325. #ifdef __cplusplus
  326. typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
  327. {
  328. _D3DXMATRIXA16() {};
  329. _D3DXMATRIXA16( CONST FLOAT * );
  330. _D3DXMATRIXA16( CONST D3DMATRIX& );
  331. _D3DXMATRIXA16( CONST D3DXFLOAT16 * );
  332. _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  333. FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  334. FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  335. FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
  336. // new operators
  337. void* operator new ( size_t );
  338. void* operator new[] ( size_t );
  339. // delete operators
  340. void operator delete ( void* ); // These are NOT virtual; Do not
  341. void operator delete[] ( void* ); // cast to D3DXMATRIX and delete.
  342. // assignment operators
  343. _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
  344. } _D3DXMATRIXA16;
  345. #else //!__cplusplus
  346. typedef D3DXMATRIX _D3DXMATRIXA16;
  347. #endif //!__cplusplus
  348. #if _MSC_VER >= 1300 // VC7
  349. #define D3DX_ALIGN16 __declspec(align(16))
  350. #else
  351. #define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing.
  352. #endif
  353. typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;
  354. //===========================================================================
  355. //
  356. // Quaternions
  357. //
  358. //===========================================================================
  359. typedef struct D3DXQUATERNION
  360. {
  361. #ifdef __cplusplus
  362. public:
  363. D3DXQUATERNION() {};
  364. D3DXQUATERNION( CONST FLOAT * );
  365. D3DXQUATERNION( CONST D3DXFLOAT16 * );
  366. D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  367. // casting
  368. operator FLOAT* ();
  369. operator CONST FLOAT* () const;
  370. // assignment operators
  371. D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& );
  372. D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& );
  373. D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& );
  374. D3DXQUATERNION& operator *= ( FLOAT );
  375. D3DXQUATERNION& operator /= ( FLOAT );
  376. // unary operators
  377. D3DXQUATERNION operator + () const;
  378. D3DXQUATERNION operator - () const;
  379. // binary operators
  380. D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const;
  381. D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const;
  382. D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const;
  383. D3DXQUATERNION operator * ( FLOAT ) const;
  384. D3DXQUATERNION operator / ( FLOAT ) const;
  385. friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& );
  386. BOOL operator == ( CONST D3DXQUATERNION& ) const;
  387. BOOL operator != ( CONST D3DXQUATERNION& ) const;
  388. #endif //__cplusplus
  389. FLOAT x, y, z, w;
  390. } D3DXQUATERNION, *LPD3DXQUATERNION;
  391. //===========================================================================
  392. //
  393. // Planes
  394. //
  395. //===========================================================================
  396. typedef struct D3DXPLANE
  397. {
  398. #ifdef __cplusplus
  399. public:
  400. D3DXPLANE() {};
  401. D3DXPLANE( CONST FLOAT* );
  402. D3DXPLANE( CONST D3DXFLOAT16* );
  403. D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );
  404. // casting
  405. operator FLOAT* ();
  406. operator CONST FLOAT* () const;
  407. // assignment operators
  408. D3DXPLANE& operator *= ( FLOAT );
  409. D3DXPLANE& operator /= ( FLOAT );
  410. // unary operators
  411. D3DXPLANE operator + () const;
  412. D3DXPLANE operator - () const;
  413. // binary operators
  414. D3DXPLANE operator * ( FLOAT ) const;
  415. D3DXPLANE operator / ( FLOAT ) const;
  416. friend D3DXPLANE operator * ( FLOAT, CONST D3DXPLANE& );
  417. BOOL operator == ( CONST D3DXPLANE& ) const;
  418. BOOL operator != ( CONST D3DXPLANE& ) const;
  419. #endif //__cplusplus
  420. FLOAT a, b, c, d;
  421. } D3DXPLANE, *LPD3DXPLANE;
  422. //===========================================================================
  423. //
  424. // Colors
  425. //
  426. //===========================================================================
  427. typedef struct D3DXCOLOR
  428. {
  429. #ifdef __cplusplus
  430. public:
  431. D3DXCOLOR() {};
  432. D3DXCOLOR( UINT argb );
  433. D3DXCOLOR( CONST FLOAT * );
  434. D3DXCOLOR( CONST D3DXFLOAT16 * );
  435. D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
  436. // casting
  437. operator UINT () const;
  438. operator FLOAT* ();
  439. operator CONST FLOAT* () const;
  440. // assignment operators
  441. D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
  442. D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
  443. D3DXCOLOR& operator *= ( FLOAT );
  444. D3DXCOLOR& operator /= ( FLOAT );
  445. // unary operators
  446. D3DXCOLOR operator + () const;
  447. D3DXCOLOR operator - () const;
  448. // binary operators
  449. D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
  450. D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
  451. D3DXCOLOR operator * ( FLOAT ) const;
  452. D3DXCOLOR operator / ( FLOAT ) const;
  453. friend D3DXCOLOR operator * ( FLOAT, CONST D3DXCOLOR& );
  454. BOOL operator == ( CONST D3DXCOLOR& ) const;
  455. BOOL operator != ( CONST D3DXCOLOR& ) const;
  456. #endif //__cplusplus
  457. FLOAT r, g, b, a;
  458. } D3DXCOLOR, *LPD3DXCOLOR;
  459. //===========================================================================
  460. //
  461. // D3DX math functions:
  462. //
  463. // NOTE:
  464. // * All these functions can take the same object as in and out parameters.
  465. //
  466. // * Out parameters are typically also returned as return values, so that
  467. // the output of one function may be used as a parameter to another.
  468. //
  469. //===========================================================================
  470. //--------------------------
  471. // Float16
  472. //--------------------------
  473. // non-inline
  474. #ifdef __cplusplus
  475. extern "C" {
  476. #endif
  477. // Converts an array 32-bit floats to 16-bit floats
  478. D3DXFLOAT16* WINAPI D3DXFloat32To16Array
  479. ( D3DXFLOAT16 *pOut, CONST FLOAT *pIn, UINT n );
  480. // Converts an array 16-bit floats to 32-bit floats
  481. FLOAT* WINAPI D3DXFloat16To32Array
  482. ( __out_ecount(n) FLOAT *pOut, __in_ecount(n) CONST D3DXFLOAT16 *pIn, UINT n );
  483. #ifdef __cplusplus
  484. }
  485. #endif
  486. //--------------------------
  487. // 2D Vector
  488. //--------------------------
  489. // inline
  490. FLOAT D3DXVec2Length
  491. ( CONST D3DXVECTOR2 *pV );
  492. FLOAT D3DXVec2LengthSq
  493. ( CONST D3DXVECTOR2 *pV );
  494. FLOAT D3DXVec2Dot
  495. ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  496. // Z component of ((x1,y1,0) cross (x2,y2,0))
  497. FLOAT D3DXVec2CCW
  498. ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  499. D3DXVECTOR2* D3DXVec2Add
  500. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  501. D3DXVECTOR2* D3DXVec2Subtract
  502. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  503. // Minimize each component. x = min(x1, x2), y = min(y1, y2)
  504. D3DXVECTOR2* D3DXVec2Minimize
  505. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  506. // Maximize each component. x = max(x1, x2), y = max(y1, y2)
  507. D3DXVECTOR2* D3DXVec2Maximize
  508. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  509. D3DXVECTOR2* D3DXVec2Scale
  510. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s );
  511. // Linear interpolation. V1 + s(V2-V1)
  512. D3DXVECTOR2* D3DXVec2Lerp
  513. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  514. FLOAT s );
  515. // non-inline
  516. #ifdef __cplusplus
  517. extern "C" {
  518. #endif
  519. D3DXVECTOR2* WINAPI D3DXVec2Normalize
  520. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV );
  521. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  522. // and position V2, tangent T2 (when s == 1).
  523. D3DXVECTOR2* WINAPI D3DXVec2Hermite
  524. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pT1,
  525. CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pT2, FLOAT s );
  526. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  527. D3DXVECTOR2* WINAPI D3DXVec2CatmullRom
  528. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV0, CONST D3DXVECTOR2 *pV1,
  529. CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pV3, FLOAT s );
  530. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  531. D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
  532. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  533. CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g);
  534. // Transform (x, y, 0, 1) by matrix.
  535. D3DXVECTOR4* WINAPI D3DXVec2Transform
  536. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  537. // Transform (x, y, 0, 1) by matrix, project result back into w=1.
  538. D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
  539. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  540. // Transform (x, y, 0, 0) by matrix.
  541. D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
  542. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  543. // Transform Array (x, y, 0, 1) by matrix.
  544. D3DXVECTOR4* WINAPI D3DXVec2TransformArray
  545. ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n);
  546. // Transform Array (x, y, 0, 1) by matrix, project result back into w=1.
  547. D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray
  548. ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  549. // Transform Array (x, y, 0, 0) by matrix.
  550. D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray
  551. ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  552. #ifdef __cplusplus
  553. }
  554. #endif
  555. //--------------------------
  556. // 3D Vector
  557. //--------------------------
  558. // inline
  559. FLOAT D3DXVec3Length
  560. ( CONST D3DXVECTOR3 *pV );
  561. FLOAT D3DXVec3LengthSq
  562. ( CONST D3DXVECTOR3 *pV );
  563. FLOAT D3DXVec3Dot
  564. ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  565. D3DXVECTOR3* D3DXVec3Cross
  566. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  567. D3DXVECTOR3* D3DXVec3Add
  568. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  569. D3DXVECTOR3* D3DXVec3Subtract
  570. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  571. // Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
  572. D3DXVECTOR3* D3DXVec3Minimize
  573. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  574. // Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
  575. D3DXVECTOR3* D3DXVec3Maximize
  576. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  577. D3DXVECTOR3* D3DXVec3Scale
  578. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s);
  579. // Linear interpolation. V1 + s(V2-V1)
  580. D3DXVECTOR3* D3DXVec3Lerp
  581. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  582. FLOAT s );
  583. // non-inline
  584. #ifdef __cplusplus
  585. extern "C" {
  586. #endif
  587. D3DXVECTOR3* WINAPI D3DXVec3Normalize
  588. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV );
  589. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  590. // and position V2, tangent T2 (when s == 1).
  591. D3DXVECTOR3* WINAPI D3DXVec3Hermite
  592. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pT1,
  593. CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pT2, FLOAT s );
  594. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  595. D3DXVECTOR3* WINAPI D3DXVec3CatmullRom
  596. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV0, CONST D3DXVECTOR3 *pV1,
  597. CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pV3, FLOAT s );
  598. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  599. D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
  600. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  601. CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g);
  602. // Transform (x, y, z, 1) by matrix.
  603. D3DXVECTOR4* WINAPI D3DXVec3Transform
  604. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  605. // Transform (x, y, z, 1) by matrix, project result back into w=1.
  606. D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
  607. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  608. // Transform (x, y, z, 0) by matrix. If you transforming a normal by a
  609. // non-affine matrix, the matrix you pass to this function should be the
  610. // transpose of the inverse of the matrix you would use to transform a coord.
  611. D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
  612. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  613. // Transform Array (x, y, z, 1) by matrix.
  614. D3DXVECTOR4* WINAPI D3DXVec3TransformArray
  615. ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  616. // Transform Array (x, y, z, 1) by matrix, project result back into w=1.
  617. D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray
  618. ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  619. // Transform (x, y, z, 0) by matrix. If you transforming a normal by a
  620. // non-affine matrix, the matrix you pass to this function should be the
  621. // transpose of the inverse of the matrix you would use to transform a coord.
  622. D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray
  623. ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  624. // Project vector from object space into screen space
  625. D3DXVECTOR3* WINAPI D3DXVec3Project
  626. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport,
  627. CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  628. // Project vector from screen space into object space
  629. D3DXVECTOR3* WINAPI D3DXVec3Unproject
  630. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport,
  631. CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  632. // Project vector Array from object space into screen space
  633. D3DXVECTOR3* WINAPI D3DXVec3ProjectArray
  634. ( D3DXVECTOR3 *pOut, UINT OutStride,CONST D3DXVECTOR3 *pV, UINT VStride,CONST D3D10_VIEWPORT *pViewport,
  635. CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
  636. // Project vector Array from screen space into object space
  637. D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray
  638. ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3D10_VIEWPORT *pViewport,
  639. CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
  640. #ifdef __cplusplus
  641. }
  642. #endif
  643. //--------------------------
  644. // 4D Vector
  645. //--------------------------
  646. // inline
  647. FLOAT D3DXVec4Length
  648. ( CONST D3DXVECTOR4 *pV );
  649. FLOAT D3DXVec4LengthSq
  650. ( CONST D3DXVECTOR4 *pV );
  651. FLOAT D3DXVec4Dot
  652. ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 );
  653. D3DXVECTOR4* D3DXVec4Add
  654. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  655. D3DXVECTOR4* D3DXVec4Subtract
  656. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  657. // Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
  658. D3DXVECTOR4* D3DXVec4Minimize
  659. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  660. // Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
  661. D3DXVECTOR4* D3DXVec4Maximize
  662. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  663. D3DXVECTOR4* D3DXVec4Scale
  664. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s);
  665. // Linear interpolation. V1 + s(V2-V1)
  666. D3DXVECTOR4* D3DXVec4Lerp
  667. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  668. FLOAT s );
  669. // non-inline
  670. #ifdef __cplusplus
  671. extern "C" {
  672. #endif
  673. // Cross-product in 4 dimensions.
  674. D3DXVECTOR4* WINAPI D3DXVec4Cross
  675. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  676. CONST D3DXVECTOR4 *pV3);
  677. D3DXVECTOR4* WINAPI D3DXVec4Normalize
  678. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  679. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  680. // and position V2, tangent T2 (when s == 1).
  681. D3DXVECTOR4* WINAPI D3DXVec4Hermite
  682. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pT1,
  683. CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pT2, FLOAT s );
  684. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  685. D3DXVECTOR4* WINAPI D3DXVec4CatmullRom
  686. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV0, CONST D3DXVECTOR4 *pV1,
  687. CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pV3, FLOAT s );
  688. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  689. D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
  690. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  691. CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g);
  692. // Transform vector by matrix.
  693. D3DXVECTOR4* WINAPI D3DXVec4Transform
  694. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  695. // Transform vector array by matrix.
  696. D3DXVECTOR4* WINAPI D3DXVec4TransformArray
  697. ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR4 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  698. #ifdef __cplusplus
  699. }
  700. #endif
  701. //--------------------------
  702. // 4D Matrix
  703. //--------------------------
  704. // inline
  705. D3DXMATRIX* D3DXMatrixIdentity
  706. ( D3DXMATRIX *pOut );
  707. BOOL D3DXMatrixIsIdentity
  708. ( CONST D3DXMATRIX *pM );
  709. // non-inline
  710. #ifdef __cplusplus
  711. extern "C" {
  712. #endif
  713. FLOAT WINAPI D3DXMatrixDeterminant
  714. ( CONST D3DXMATRIX *pM );
  715. HRESULT WINAPI D3DXMatrixDecompose
  716. ( D3DXVECTOR3 *pOutScale, D3DXQUATERNION *pOutRotation,
  717. D3DXVECTOR3 *pOutTranslation, CONST D3DXMATRIX *pM );
  718. D3DXMATRIX* WINAPI D3DXMatrixTranspose
  719. ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  720. // Matrix multiplication. The result represents the transformation M2
  721. // followed by the transformation M1. (Out = M1 * M2)
  722. D3DXMATRIX* WINAPI D3DXMatrixMultiply
  723. ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  724. // Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
  725. D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose
  726. ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  727. // Calculate inverse of matrix. Inversion my fail, in which case NULL will
  728. // be returned. The determinant of pM is also returned it pfDeterminant
  729. // is non-NULL.
  730. D3DXMATRIX* WINAPI D3DXMatrixInverse
  731. ( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  732. // Build a matrix which scales by (sx, sy, sz)
  733. D3DXMATRIX* WINAPI D3DXMatrixScaling
  734. ( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
  735. // Build a matrix which translates by (x, y, z)
  736. D3DXMATRIX* WINAPI D3DXMatrixTranslation
  737. ( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  738. // Build a matrix which rotates around the X axis
  739. D3DXMATRIX* WINAPI D3DXMatrixRotationX
  740. ( D3DXMATRIX *pOut, FLOAT Angle );
  741. // Build a matrix which rotates around the Y axis
  742. D3DXMATRIX* WINAPI D3DXMatrixRotationY
  743. ( D3DXMATRIX *pOut, FLOAT Angle );
  744. // Build a matrix which rotates around the Z axis
  745. D3DXMATRIX* WINAPI D3DXMatrixRotationZ
  746. ( D3DXMATRIX *pOut, FLOAT Angle );
  747. // Build a matrix which rotates around an arbitrary axis
  748. D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
  749. ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  750. // Build a matrix from a quaternion
  751. D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
  752. ( D3DXMATRIX *pOut, CONST D3DXQUATERNION *pQ);
  753. // Yaw around the Y axis, a pitch around the X axis,
  754. // and a roll around the Z axis.
  755. D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
  756. ( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  757. // Build transformation matrix. NULL arguments are treated as identity.
  758. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  759. D3DXMATRIX* WINAPI D3DXMatrixTransformation
  760. ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter,
  761. CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling,
  762. CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation,
  763. CONST D3DXVECTOR3 *pTranslation);
  764. // Build 2D transformation matrix in XY plane. NULL arguments are treated as identity.
  765. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  766. D3DXMATRIX* WINAPI D3DXMatrixTransformation2D
  767. ( D3DXMATRIX *pOut, CONST D3DXVECTOR2* pScalingCenter,
  768. FLOAT ScalingRotation, CONST D3DXVECTOR2* pScaling,
  769. CONST D3DXVECTOR2* pRotationCenter, FLOAT Rotation,
  770. CONST D3DXVECTOR2* pTranslation);
  771. // Build affine transformation matrix. NULL arguments are treated as identity.
  772. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  773. D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
  774. ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR3 *pRotationCenter,
  775. CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation);
  776. // Build 2D affine transformation matrix in XY plane. NULL arguments are treated as identity.
  777. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  778. D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D
  779. ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR2* pRotationCenter,
  780. FLOAT Rotation, CONST D3DXVECTOR2* pTranslation);
  781. // Build a lookat matrix. (right-handed)
  782. D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
  783. ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  784. CONST D3DXVECTOR3 *pUp );
  785. // Build a lookat matrix. (left-handed)
  786. D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
  787. ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  788. CONST D3DXVECTOR3 *pUp );
  789. // Build a perspective projection matrix. (right-handed)
  790. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveRH
  791. ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  792. // Build a perspective projection matrix. (left-handed)
  793. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH
  794. ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  795. // Build a perspective projection matrix. (right-handed)
  796. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH
  797. ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  798. // Build a perspective projection matrix. (left-handed)
  799. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH
  800. ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  801. // Build a perspective projection matrix. (right-handed)
  802. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterRH
  803. ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  804. FLOAT zf );
  805. // Build a perspective projection matrix. (left-handed)
  806. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH
  807. ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  808. FLOAT zf );
  809. // Build an ortho projection matrix. (right-handed)
  810. D3DXMATRIX* WINAPI D3DXMatrixOrthoRH
  811. ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  812. // Build an ortho projection matrix. (left-handed)
  813. D3DXMATRIX* WINAPI D3DXMatrixOrthoLH
  814. ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  815. // Build an ortho projection matrix. (right-handed)
  816. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterRH
  817. ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  818. FLOAT zf );
  819. // Build an ortho projection matrix. (left-handed)
  820. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH
  821. ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  822. FLOAT zf );
  823. // Build a matrix which flattens geometry into a plane, as if casting
  824. // a shadow from a light.
  825. D3DXMATRIX* WINAPI D3DXMatrixShadow
  826. ( D3DXMATRIX *pOut, CONST D3DXVECTOR4 *pLight,
  827. CONST D3DXPLANE *pPlane );
  828. // Build a matrix which reflects the coordinate system about a plane
  829. D3DXMATRIX* WINAPI D3DXMatrixReflect
  830. ( D3DXMATRIX *pOut, CONST D3DXPLANE *pPlane );
  831. #ifdef __cplusplus
  832. }
  833. #endif
  834. //--------------------------
  835. // Quaternion
  836. //--------------------------
  837. // inline
  838. FLOAT D3DXQuaternionLength
  839. ( CONST D3DXQUATERNION *pQ );
  840. // Length squared, or "norm"
  841. FLOAT D3DXQuaternionLengthSq
  842. ( CONST D3DXQUATERNION *pQ );
  843. FLOAT D3DXQuaternionDot
  844. ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 );
  845. // (0, 0, 0, 1)
  846. D3DXQUATERNION* D3DXQuaternionIdentity
  847. ( D3DXQUATERNION *pOut );
  848. BOOL D3DXQuaternionIsIdentity
  849. ( CONST D3DXQUATERNION *pQ );
  850. // (-x, -y, -z, w)
  851. D3DXQUATERNION* D3DXQuaternionConjugate
  852. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  853. // non-inline
  854. #ifdef __cplusplus
  855. extern "C" {
  856. #endif
  857. // Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
  858. void WINAPI D3DXQuaternionToAxisAngle
  859. ( CONST D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, FLOAT *pAngle );
  860. // Build a quaternion from a rotation matrix.
  861. D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix
  862. ( D3DXQUATERNION *pOut, CONST D3DXMATRIX *pM);
  863. // Rotation about arbitrary axis.
  864. D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis
  865. ( D3DXQUATERNION *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  866. // Yaw around the Y axis, a pitch around the X axis,
  867. // and a roll around the Z axis.
  868. D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll
  869. ( D3DXQUATERNION *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  870. // Quaternion multiplication. The result represents the rotation Q2
  871. // followed by the rotation Q1. (Out = Q2 * Q1)
  872. D3DXQUATERNION* WINAPI D3DXQuaternionMultiply
  873. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  874. CONST D3DXQUATERNION *pQ2 );
  875. D3DXQUATERNION* WINAPI D3DXQuaternionNormalize
  876. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  877. // Conjugate and re-norm
  878. D3DXQUATERNION* WINAPI D3DXQuaternionInverse
  879. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  880. // Expects unit quaternions.
  881. // if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
  882. D3DXQUATERNION* WINAPI D3DXQuaternionLn
  883. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  884. // Expects pure quaternions. (w == 0) w is ignored in calculation.
  885. // if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
  886. D3DXQUATERNION* WINAPI D3DXQuaternionExp
  887. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  888. // Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).
  889. // Expects unit quaternions.
  890. D3DXQUATERNION* WINAPI D3DXQuaternionSlerp
  891. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  892. CONST D3DXQUATERNION *pQ2, FLOAT t );
  893. // Spherical quadrangle interpolation.
  894. // Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))
  895. D3DXQUATERNION* WINAPI D3DXQuaternionSquad
  896. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  897. CONST D3DXQUATERNION *pA, CONST D3DXQUATERNION *pB,
  898. CONST D3DXQUATERNION *pC, FLOAT t );
  899. // Setup control points for spherical quadrangle interpolation
  900. // from Q1 to Q2. The control points are chosen in such a way
  901. // to ensure the continuity of tangents with adjacent segments.
  902. void WINAPI D3DXQuaternionSquadSetup
  903. ( D3DXQUATERNION *pAOut, D3DXQUATERNION *pBOut, D3DXQUATERNION *pCOut,
  904. CONST D3DXQUATERNION *pQ0, CONST D3DXQUATERNION *pQ1,
  905. CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3 );
  906. // Barycentric interpolation.
  907. // Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
  908. D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric
  909. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  910. CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3,
  911. FLOAT f, FLOAT g );
  912. #ifdef __cplusplus
  913. }
  914. #endif
  915. //--------------------------
  916. // Plane
  917. //--------------------------
  918. // inline
  919. // ax + by + cz + dw
  920. FLOAT D3DXPlaneDot
  921. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV);
  922. // ax + by + cz + d
  923. FLOAT D3DXPlaneDotCoord
  924. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  925. // ax + by + cz
  926. FLOAT D3DXPlaneDotNormal
  927. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  928. D3DXPLANE* D3DXPlaneScale
  929. (D3DXPLANE *pOut, CONST D3DXPLANE *pP, FLOAT s);
  930. // non-inline
  931. #ifdef __cplusplus
  932. extern "C" {
  933. #endif
  934. // Normalize plane (so that |a,b,c| == 1)
  935. D3DXPLANE* WINAPI D3DXPlaneNormalize
  936. ( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  937. // Find the intersection between a plane and a line. If the line is
  938. // parallel to the plane, NULL is returned.
  939. D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine
  940. ( D3DXVECTOR3 *pOut, CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV1,
  941. CONST D3DXVECTOR3 *pV2);
  942. // Construct a plane from a point and a normal
  943. D3DXPLANE* WINAPI D3DXPlaneFromPointNormal
  944. ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pPoint, CONST D3DXVECTOR3 *pNormal);
  945. // Construct a plane from 3 points
  946. D3DXPLANE* WINAPI D3DXPlaneFromPoints
  947. ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  948. CONST D3DXVECTOR3 *pV3);
  949. // Transform a plane by a matrix. The vector (a,b,c) must be normal.
  950. // M should be the inverse transpose of the transformation desired.
  951. D3DXPLANE* WINAPI D3DXPlaneTransform
  952. ( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  953. // Transform an array of planes by a matrix. The vectors (a,b,c) must be normal.
  954. // M should be the inverse transpose of the transformation desired.
  955. D3DXPLANE* WINAPI D3DXPlaneTransformArray
  956. ( D3DXPLANE *pOut, UINT OutStride, CONST D3DXPLANE *pP, UINT PStride, CONST D3DXMATRIX *pM, UINT n );
  957. #ifdef __cplusplus
  958. }
  959. #endif
  960. //--------------------------
  961. // Color
  962. //--------------------------
  963. // inline
  964. // (1-r, 1-g, 1-b, a)
  965. D3DXCOLOR* D3DXColorNegative
  966. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC);
  967. D3DXCOLOR* D3DXColorAdd
  968. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  969. D3DXCOLOR* D3DXColorSubtract
  970. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  971. D3DXCOLOR* D3DXColorScale
  972. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  973. // (r1*r2, g1*g2, b1*b2, a1*a2)
  974. D3DXCOLOR* D3DXColorModulate
  975. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  976. // Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
  977. D3DXCOLOR* D3DXColorLerp
  978. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s);
  979. // non-inline
  980. #ifdef __cplusplus
  981. extern "C" {
  982. #endif
  983. // Interpolate r,g,b between desaturated color and color.
  984. // DesaturatedColor + s(Color - DesaturatedColor)
  985. D3DXCOLOR* WINAPI D3DXColorAdjustSaturation
  986. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  987. // Interpolate r,g,b between 50% grey and color. Grey + s(Color - Grey)
  988. D3DXCOLOR* WINAPI D3DXColorAdjustContrast
  989. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT c);
  990. #ifdef __cplusplus
  991. }
  992. #endif
  993. //--------------------------
  994. // Misc
  995. //--------------------------
  996. #ifdef __cplusplus
  997. extern "C" {
  998. #endif
  999. // Calculate Fresnel term given the cosine of theta (likely obtained by
  1000. // taking the dot of two normals), and the refraction index of the material.
  1001. FLOAT WINAPI D3DXFresnelTerm
  1002. (FLOAT CosTheta, FLOAT RefractionIndex);
  1003. #ifdef __cplusplus
  1004. }
  1005. #endif
  1006. //===========================================================================
  1007. //
  1008. // Matrix Stack
  1009. //
  1010. //===========================================================================
  1011. typedef interface ID3DXMatrixStack ID3DXMatrixStack;
  1012. typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
  1013. // {C7885BA7-F990-4fe7-922D-8515E477DD85}
  1014. DEFINE_GUID(IID_ID3DXMatrixStack,
  1015. 0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
  1016. #undef INTERFACE
  1017. #define INTERFACE ID3DXMatrixStack
  1018. DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
  1019. {
  1020. //
  1021. // IUnknown methods
  1022. //
  1023. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  1024. STDMETHOD_(ULONG,AddRef)(THIS) PURE;
  1025. STDMETHOD_(ULONG,Release)(THIS) PURE;
  1026. //
  1027. // ID3DXMatrixStack methods
  1028. //
  1029. // Pops the top of the stack, returns the current top
  1030. // *after* popping the top.
  1031. STDMETHOD(Pop)(THIS) PURE;
  1032. // Pushes the stack by one, duplicating the current matrix.
  1033. STDMETHOD(Push)(THIS) PURE;
  1034. // Loads identity in the current matrix.
  1035. STDMETHOD(LoadIdentity)(THIS) PURE;
  1036. // Loads the given matrix into the current matrix
  1037. STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1038. // Right-Multiplies the given matrix to the current matrix.
  1039. // (transformation is about the current world origin)
  1040. STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1041. // Left-Multiplies the given matrix to the current matrix
  1042. // (transformation is about the local origin of the object)
  1043. STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1044. // Right multiply the current matrix with the computed rotation
  1045. // matrix, counterclockwise about the given axis with the given angle.
  1046. // (rotation is about the current world origin)
  1047. STDMETHOD(RotateAxis)
  1048. (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1049. // Left multiply the current matrix with the computed rotation
  1050. // matrix, counterclockwise about the given axis with the given angle.
  1051. // (rotation is about the local origin of the object)
  1052. STDMETHOD(RotateAxisLocal)
  1053. (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1054. // Right multiply the current matrix with the computed rotation
  1055. // matrix. All angles are counterclockwise. (rotation is about the
  1056. // current world origin)
  1057. // The rotation is composed of a yaw around the Y axis, a pitch around
  1058. // the X axis, and a roll around the Z axis.
  1059. STDMETHOD(RotateYawPitchRoll)
  1060. (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1061. // Left multiply the current matrix with the computed rotation
  1062. // matrix. All angles are counterclockwise. (rotation is about the
  1063. // local origin of the object)
  1064. // The rotation is composed of a yaw around the Y axis, a pitch around
  1065. // the X axis, and a roll around the Z axis.
  1066. STDMETHOD(RotateYawPitchRollLocal)
  1067. (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1068. // Right multiply the current matrix with the computed scale
  1069. // matrix. (transformation is about the current world origin)
  1070. STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1071. // Left multiply the current matrix with the computed scale
  1072. // matrix. (transformation is about the local origin of the object)
  1073. STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1074. // Right multiply the current matrix with the computed translation
  1075. // matrix. (transformation is about the current world origin)
  1076. STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
  1077. // Left multiply the current matrix with the computed translation
  1078. // matrix. (transformation is about the local origin of the object)
  1079. STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1080. // Obtain the current matrix at the top of the stack
  1081. STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
  1082. };
  1083. #ifdef __cplusplus
  1084. extern "C" {
  1085. #endif
  1086. HRESULT WINAPI
  1087. D3DXCreateMatrixStack(
  1088. UINT Flags,
  1089. LPD3DXMATRIXSTACK* ppStack);
  1090. #ifdef __cplusplus
  1091. }
  1092. #endif
  1093. // non-inline
  1094. #ifdef __cplusplus
  1095. extern "C" {
  1096. #endif
  1097. //============================================================================
  1098. //
  1099. // Basic Spherical Harmonic math routines
  1100. //
  1101. //============================================================================
  1102. #define D3DXSH_MINORDER 2
  1103. #define D3DXSH_MAXORDER 6
  1104. //============================================================================
  1105. //
  1106. // D3DXSHEvalDirection:
  1107. // --------------------
  1108. // Evaluates the Spherical Harmonic basis functions
  1109. //
  1110. // Parameters:
  1111. // pOut
  1112. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1113. // This is the pointer that is returned.
  1114. // Order
  1115. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1116. // pDir
  1117. // Direction to evaluate in - assumed to be normalized
  1118. //
  1119. //============================================================================
  1120. FLOAT* WINAPI D3DXSHEvalDirection
  1121. ( FLOAT *pOut, UINT Order, CONST D3DXVECTOR3 *pDir );
  1122. //============================================================================
  1123. //
  1124. // D3DXSHRotate:
  1125. // --------------------
  1126. // Rotates SH vector by a rotation matrix
  1127. //
  1128. // Parameters:
  1129. // pOut
  1130. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1131. // This is the pointer that is returned (should not alias with pIn.)
  1132. // Order
  1133. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1134. // pMatrix
  1135. // Matrix used for rotation - rotation sub matrix should be orthogonal
  1136. // and have a unit determinant.
  1137. // pIn
  1138. // Input SH coeffs (rotated), incorect results if this is also output.
  1139. //
  1140. //============================================================================
  1141. FLOAT* WINAPI D3DXSHRotate
  1142. ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST D3DXMATRIX *pMatrix, CONST FLOAT *pIn );
  1143. //============================================================================
  1144. //
  1145. // D3DXSHRotateZ:
  1146. // --------------------
  1147. // Rotates the SH vector in the Z axis by an angle
  1148. //
  1149. // Parameters:
  1150. // pOut
  1151. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1152. // This is the pointer that is returned (should not alias with pIn.)
  1153. // Order
  1154. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1155. // Angle
  1156. // Angle in radians to rotate around the Z axis.
  1157. // pIn
  1158. // Input SH coeffs (rotated), incorect results if this is also output.
  1159. //
  1160. //============================================================================
  1161. FLOAT* WINAPI D3DXSHRotateZ
  1162. ( FLOAT *pOut, UINT Order, FLOAT Angle, CONST FLOAT *pIn );
  1163. //============================================================================
  1164. //
  1165. // D3DXSHAdd:
  1166. // --------------------
  1167. // Adds two SH vectors, pOut[i] = pA[i] + pB[i];
  1168. //
  1169. // Parameters:
  1170. // pOut
  1171. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1172. // This is the pointer that is returned.
  1173. // Order
  1174. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1175. // pA
  1176. // Input SH coeffs.
  1177. // pB
  1178. // Input SH coeffs (second vector.)
  1179. //
  1180. //============================================================================
  1181. FLOAT* WINAPI D3DXSHAdd
  1182. ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST FLOAT *pA, CONST FLOAT *pB );
  1183. //============================================================================
  1184. //
  1185. // D3DXSHScale:
  1186. // --------------------
  1187. // Adds two SH vectors, pOut[i] = pA[i]*Scale;
  1188. //
  1189. // Parameters:
  1190. // pOut
  1191. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1192. // This is the pointer that is returned.
  1193. // Order
  1194. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1195. // pIn
  1196. // Input SH coeffs.
  1197. // Scale
  1198. // Scale factor.
  1199. //
  1200. //============================================================================
  1201. FLOAT* WINAPI D3DXSHScale
  1202. ( __out_ecount(Order*Order) FLOAT *pOut, UINT Order, CONST FLOAT *pIn, CONST FLOAT Scale );
  1203. //============================================================================
  1204. //
  1205. // D3DXSHDot:
  1206. // --------------------
  1207. // Computes the dot product of two SH vectors
  1208. //
  1209. // Parameters:
  1210. // Order
  1211. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1212. // pA
  1213. // Input SH coeffs.
  1214. // pB
  1215. // Second set of input SH coeffs.
  1216. //
  1217. //============================================================================
  1218. FLOAT WINAPI D3DXSHDot
  1219. ( UINT Order, CONST FLOAT *pA, CONST FLOAT *pB );
  1220. //============================================================================
  1221. //
  1222. // D3DXSHMultiply[O]:
  1223. // --------------------
  1224. // Computes the product of two functions represented using SH (f and g), where:
  1225. // pOut[i] = int(y_i(s) * f(s) * g(s)), where y_i(s) is the ith SH basis
  1226. // function, f(s) and g(s) are SH functions (sum_i(y_i(s)*c_i)). The order O
  1227. // determines the lengths of the arrays, where there should always be O^2
  1228. // coefficients. In general the product of two SH functions of order O generates
  1229. // and SH function of order 2*O - 1, but we truncate the result. This means
  1230. // that the product commutes (f*g == g*f) but doesn't associate
  1231. // (f*(g*h) != (f*g)*h.
  1232. //
  1233. // Parameters:
  1234. // pOut
  1235. // Output SH coefficients - basis function Ylm is stored at l*l + m+l
  1236. // This is the pointer that is returned.
  1237. // pF
  1238. // Input SH coeffs for first function.
  1239. // pG
  1240. // Second set of input SH coeffs.
  1241. //
  1242. //============================================================================
  1243. __out_ecount(4) FLOAT* WINAPI D3DXSHMultiply2(__out_ecount(4) FLOAT *pOut,__in_ecount(4) CONST FLOAT *pF,__in_ecount(4) CONST FLOAT *pG);
  1244. __out_ecount(9) FLOAT* WINAPI D3DXSHMultiply3(__out_ecount(9) FLOAT *pOut,__in_ecount(9) CONST FLOAT *pF,__in_ecount(9) CONST FLOAT *pG);
  1245. __out_ecount(16) FLOAT* WINAPI D3DXSHMultiply4(__out_ecount(16) FLOAT *pOut,__in_ecount(16) CONST FLOAT *pF,__in_ecount(16) CONST FLOAT *pG);
  1246. __out_ecount(25) FLOAT* WINAPI D3DXSHMultiply5(__out_ecount(25) FLOAT *pOut,__in_ecount(25) CONST FLOAT *pF,__in_ecount(25) CONST FLOAT *pG);
  1247. __out_ecount(36) FLOAT* WINAPI D3DXSHMultiply6(__out_ecount(36) FLOAT *pOut,__in_ecount(36) CONST FLOAT *pF,__in_ecount(36) CONST FLOAT *pG);
  1248. //============================================================================
  1249. //
  1250. // Basic Spherical Harmonic lighting routines
  1251. //
  1252. //============================================================================
  1253. //============================================================================
  1254. //
  1255. // D3DXSHEvalDirectionalLight:
  1256. // --------------------
  1257. // Evaluates a directional light and returns spectral SH data. The output
  1258. // vector is computed so that if the intensity of R/G/B is unit the resulting
  1259. // exit radiance of a point directly under the light on a diffuse object with
  1260. // an albedo of 1 would be 1.0. This will compute 3 spectral samples, pROut
  1261. // has to be specified, while pGout and pBout are optional.
  1262. //
  1263. // Parameters:
  1264. // Order
  1265. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1266. // pDir
  1267. // Direction light is coming from (assumed to be normalized.)
  1268. // RIntensity
  1269. // Red intensity of light.
  1270. // GIntensity
  1271. // Green intensity of light.
  1272. // BIntensity
  1273. // Blue intensity of light.
  1274. // pROut
  1275. // Output SH vector for Red.
  1276. // pGOut
  1277. // Output SH vector for Green (optional.)
  1278. // pBOut
  1279. // Output SH vector for Blue (optional.)
  1280. //
  1281. //============================================================================
  1282. HRESULT WINAPI D3DXSHEvalDirectionalLight
  1283. ( UINT Order, CONST D3DXVECTOR3 *pDir,
  1284. FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
  1285. __out_ecount_opt(Order*Order) FLOAT *pROut,
  1286. __out_ecount_opt(Order*Order) FLOAT *pGOut,
  1287. __out_ecount_opt(Order*Order) FLOAT *pBOut );
  1288. //============================================================================
  1289. //
  1290. // D3DXSHEvalSphericalLight:
  1291. // --------------------
  1292. // Evaluates a spherical light and returns spectral SH data. There is no
  1293. // normalization of the intensity of the light like there is for directional
  1294. // lights, care has to be taken when specifiying the intensities. This will
  1295. // compute 3 spectral samples, pROut has to be specified, while pGout and
  1296. // pBout are optional.
  1297. //
  1298. // Parameters:
  1299. // Order
  1300. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1301. // pPos
  1302. // Position of light - reciever is assumed to be at the origin.
  1303. // Radius
  1304. // Radius of the spherical light source.
  1305. // RIntensity
  1306. // Red intensity of light.
  1307. // GIntensity
  1308. // Green intensity of light.
  1309. // BIntensity
  1310. // Blue intensity of light.
  1311. // pROut
  1312. // Output SH vector for Red.
  1313. // pGOut
  1314. // Output SH vector for Green (optional.)
  1315. // pBOut
  1316. // Output SH vector for Blue (optional.)
  1317. //
  1318. //============================================================================
  1319. HRESULT WINAPI D3DXSHEvalSphericalLight
  1320. ( UINT Order, CONST D3DXVECTOR3 *pPos, FLOAT Radius,
  1321. FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
  1322. __out_ecount_opt(Order*Order) FLOAT *pROut,
  1323. __out_ecount_opt(Order*Order) FLOAT *pGOut,
  1324. __out_ecount_opt(Order*Order) FLOAT *pBOut );
  1325. //============================================================================
  1326. //
  1327. // D3DXSHEvalConeLight:
  1328. // --------------------
  1329. // Evaluates a light that is a cone of constant intensity and returns spectral
  1330. // SH data. The output vector is computed so that if the intensity of R/G/B is
  1331. // unit the resulting exit radiance of a point directly under the light oriented
  1332. // in the cone direction on a diffuse object with an albedo of 1 would be 1.0.
  1333. // This will compute 3 spectral samples, pROut has to be specified, while pGout
  1334. // and pBout are optional.
  1335. //
  1336. // Parameters:
  1337. // Order
  1338. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1339. // pDir
  1340. // Direction light is coming from (assumed to be normalized.)
  1341. // Radius
  1342. // Radius of cone in radians.
  1343. // RIntensity
  1344. // Red intensity of light.
  1345. // GIntensity
  1346. // Green intensity of light.
  1347. // BIntensity
  1348. // Blue intensity of light.
  1349. // pROut
  1350. // Output SH vector for Red.
  1351. // pGOut
  1352. // Output SH vector for Green (optional.)
  1353. // pBOut
  1354. // Output SH vector for Blue (optional.)
  1355. //
  1356. //============================================================================
  1357. HRESULT WINAPI D3DXSHEvalConeLight
  1358. ( UINT Order, CONST D3DXVECTOR3 *pDir, FLOAT Radius,
  1359. FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity,
  1360. __out_ecount_opt(Order*Order) FLOAT *pROut,
  1361. __out_ecount_opt(Order*Order) FLOAT *pGOut,
  1362. __out_ecount_opt(Order*Order) FLOAT *pBOut );
  1363. //============================================================================
  1364. //
  1365. // D3DXSHEvalHemisphereLight:
  1366. // --------------------
  1367. // Evaluates a light that is a linear interpolant between two colors over the
  1368. // sphere. The interpolant is linear along the axis of the two points, not
  1369. // over the surface of the sphere (ie: if the axis was (0,0,1) it is linear in
  1370. // Z, not in the azimuthal angle.) The resulting spherical lighting function
  1371. // is normalized so that a point on a perfectly diffuse surface with no
  1372. // shadowing and a normal pointed in the direction pDir would result in exit
  1373. // radiance with a value of 1 if the top color was white and the bottom color
  1374. // was black. This is a very simple model where Top represents the intensity
  1375. // of the "sky" and Bottom represents the intensity of the "ground".
  1376. //
  1377. // Parameters:
  1378. // Order
  1379. // Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
  1380. // pDir
  1381. // Axis of the hemisphere.
  1382. // Top
  1383. // Color of the upper hemisphere.
  1384. // Bottom
  1385. // Color of the lower hemisphere.
  1386. // pROut
  1387. // Output SH vector for Red.
  1388. // pGOut
  1389. // Output SH vector for Green
  1390. // pBOut
  1391. // Output SH vector for Blue
  1392. //
  1393. //============================================================================
  1394. HRESULT WINAPI D3DXSHEvalHemisphereLight
  1395. ( UINT Order, CONST D3DXVECTOR3 *pDir, D3DXCOLOR Top, D3DXCOLOR Bottom,
  1396. __out_ecount_opt(Order*Order) FLOAT *pROut,
  1397. __out_ecount_opt(Order*Order) FLOAT *pGOut,
  1398. __out_ecount_opt(Order*Order) FLOAT *pBOut );
  1399. // Math intersection functions
  1400. BOOL WINAPI D3DXIntersectTri
  1401. (
  1402. CONST D3DXVECTOR3 *p0, // Triangle vertex 0 position
  1403. CONST D3DXVECTOR3 *p1, // Triangle vertex 1 position
  1404. CONST D3DXVECTOR3 *p2, // Triangle vertex 2 position
  1405. CONST D3DXVECTOR3 *pRayPos, // Ray origin
  1406. CONST D3DXVECTOR3 *pRayDir, // Ray direction
  1407. FLOAT *pU, // Barycentric Hit Coordinates
  1408. FLOAT *pV, // Barycentric Hit Coordinates
  1409. FLOAT *pDist); // Ray-Intersection Parameter Distance
  1410. BOOL WINAPI
  1411. D3DXSphereBoundProbe(
  1412. CONST D3DXVECTOR3 *pCenter,
  1413. FLOAT Radius,
  1414. CONST D3DXVECTOR3 *pRayPosition,
  1415. CONST D3DXVECTOR3 *pRayDirection);
  1416. BOOL WINAPI
  1417. D3DXBoxBoundProbe(
  1418. CONST D3DXVECTOR3 *pMin,
  1419. CONST D3DXVECTOR3 *pMax,
  1420. CONST D3DXVECTOR3 *pRayPosition,
  1421. CONST D3DXVECTOR3 *pRayDirection);
  1422. HRESULT WINAPI
  1423. D3DXComputeBoundingSphere(
  1424. CONST D3DXVECTOR3 *pFirstPosition, // pointer to first position
  1425. DWORD NumVertices,
  1426. DWORD dwStride, // count in bytes to subsequent position vectors
  1427. D3DXVECTOR3 *pCenter,
  1428. FLOAT *pRadius);
  1429. HRESULT WINAPI
  1430. D3DXComputeBoundingBox(
  1431. CONST D3DXVECTOR3 *pFirstPosition, // pointer to first position
  1432. DWORD NumVertices,
  1433. DWORD dwStride, // count in bytes to subsequent position vectors
  1434. D3DXVECTOR3 *pMin,
  1435. D3DXVECTOR3 *pMax);
  1436. ///////////////////////////////////////////////////////////////////////////
  1437. // CPU Optimization:
  1438. ///////////////////////////////////////////////////////////////////////////
  1439. //-------------------------------------------------------------------------
  1440. // D3DX_CPU_OPTIMIZATION flags:
  1441. // ----------------------------
  1442. // D3DX_NOT_OPTIMIZED Use Intel Pentium optimizations
  1443. // D3DX_3DNOW_OPTIMIZED Use AMD 3DNow optimizations
  1444. // D3DX_SSE_OPTIMIZED Use Intel Pentium III SSE optimizations
  1445. // D3DX_SSE2_OPTIMIZED Use Intel Pentium IV SSE2 optimizations
  1446. //-------------------------------------------------------------------------
  1447. typedef enum _D3DX_CPU_OPTIMIZATION
  1448. {
  1449. D3DX_NOT_OPTIMIZED = 0,
  1450. D3DX_3DNOW_OPTIMIZED,
  1451. D3DX_SSE2_OPTIMIZED,
  1452. D3DX_SSE_OPTIMIZED
  1453. } D3DX_CPU_OPTIMIZATION;
  1454. //-------------------------------------------------------------------------
  1455. // D3DXCpuOptimizations:
  1456. // ---------------------
  1457. // Enables or disables CPU optimizations. Returns the type of CPU, which
  1458. // was detected, and for which optimizations exist.
  1459. //
  1460. // Parameters:
  1461. // Enable
  1462. // TRUE to enable CPU optimizations. FALSE to disable.
  1463. //-------------------------------------------------------------------------
  1464. D3DX_CPU_OPTIMIZATION WINAPI
  1465. D3DXCpuOptimizations(BOOL Enable);
  1466. #ifdef __cplusplus
  1467. }
  1468. #endif
  1469. #include "D3DX10math.inl"
  1470. #if _MSC_VER >= 1200
  1471. #pragma warning(pop)
  1472. #else
  1473. #pragma warning(default:4201)
  1474. #endif
  1475. #endif // __D3DX9MATH_H__