d3dx9math.h 56 KB

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