d3dx9math.inl 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: d3dx9math.inl
  6. // Content: D3DX math inline functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #ifndef __D3DX9MATH_INL__
  10. #define __D3DX9MATH_INL__
  11. //===========================================================================
  12. //
  13. // Inline Class Methods
  14. //
  15. //===========================================================================
  16. #ifdef __cplusplus
  17. //--------------------------
  18. // Float16
  19. //--------------------------
  20. D3DXINLINE
  21. D3DXFLOAT16::D3DXFLOAT16( FLOAT f )
  22. {
  23. D3DXFloat32To16Array(this, &f, 1);
  24. }
  25. D3DXINLINE
  26. D3DXFLOAT16::D3DXFLOAT16( CONST D3DXFLOAT16& f )
  27. {
  28. value = f.value;
  29. }
  30. // casting
  31. D3DXINLINE
  32. D3DXFLOAT16::operator FLOAT ()
  33. {
  34. FLOAT f;
  35. D3DXFloat16To32Array(&f, this, 1);
  36. return f;
  37. }
  38. // binary operators
  39. D3DXINLINE BOOL
  40. D3DXFLOAT16::operator == ( CONST D3DXFLOAT16& f ) const
  41. {
  42. return value == f.value;
  43. }
  44. D3DXINLINE BOOL
  45. D3DXFLOAT16::operator != ( CONST D3DXFLOAT16& f ) const
  46. {
  47. return value != f.value;
  48. }
  49. //--------------------------
  50. // 2D Vector
  51. //--------------------------
  52. D3DXINLINE
  53. D3DXVECTOR2::D3DXVECTOR2( CONST FLOAT *pf )
  54. {
  55. #ifdef D3DX_DEBUG
  56. if(!pf)
  57. return;
  58. #endif
  59. x = pf[0];
  60. y = pf[1];
  61. }
  62. D3DXINLINE
  63. D3DXVECTOR2::D3DXVECTOR2( CONST D3DXFLOAT16 *pf )
  64. {
  65. #ifdef D3DX_DEBUG
  66. if(!pf)
  67. return;
  68. #endif
  69. D3DXFloat16To32Array(&x, pf, 2);
  70. }
  71. D3DXINLINE
  72. D3DXVECTOR2::D3DXVECTOR2( FLOAT fx, FLOAT fy )
  73. {
  74. x = fx;
  75. y = fy;
  76. }
  77. // casting
  78. D3DXINLINE
  79. D3DXVECTOR2::operator FLOAT* ()
  80. {
  81. return (FLOAT *) &x;
  82. }
  83. D3DXINLINE
  84. D3DXVECTOR2::operator CONST FLOAT* () const
  85. {
  86. return (CONST FLOAT *) &x;
  87. }
  88. // assignment operators
  89. D3DXINLINE D3DXVECTOR2&
  90. D3DXVECTOR2::operator += ( CONST D3DXVECTOR2& v )
  91. {
  92. x += v.x;
  93. y += v.y;
  94. return *this;
  95. }
  96. D3DXINLINE D3DXVECTOR2&
  97. D3DXVECTOR2::operator -= ( CONST D3DXVECTOR2& v )
  98. {
  99. x -= v.x;
  100. y -= v.y;
  101. return *this;
  102. }
  103. D3DXINLINE D3DXVECTOR2&
  104. D3DXVECTOR2::operator *= ( FLOAT f )
  105. {
  106. x *= f;
  107. y *= f;
  108. return *this;
  109. }
  110. D3DXINLINE D3DXVECTOR2&
  111. D3DXVECTOR2::operator /= ( FLOAT f )
  112. {
  113. FLOAT fInv = 1.0f / f;
  114. x *= fInv;
  115. y *= fInv;
  116. return *this;
  117. }
  118. // unary operators
  119. D3DXINLINE D3DXVECTOR2
  120. D3DXVECTOR2::operator + () const
  121. {
  122. return *this;
  123. }
  124. D3DXINLINE D3DXVECTOR2
  125. D3DXVECTOR2::operator - () const
  126. {
  127. return D3DXVECTOR2(-x, -y);
  128. }
  129. // binary operators
  130. D3DXINLINE D3DXVECTOR2
  131. D3DXVECTOR2::operator + ( CONST D3DXVECTOR2& v ) const
  132. {
  133. return D3DXVECTOR2(x + v.x, y + v.y);
  134. }
  135. D3DXINLINE D3DXVECTOR2
  136. D3DXVECTOR2::operator - ( CONST D3DXVECTOR2& v ) const
  137. {
  138. return D3DXVECTOR2(x - v.x, y - v.y);
  139. }
  140. D3DXINLINE D3DXVECTOR2
  141. D3DXVECTOR2::operator * ( FLOAT f ) const
  142. {
  143. return D3DXVECTOR2(x * f, y * f);
  144. }
  145. D3DXINLINE D3DXVECTOR2
  146. D3DXVECTOR2::operator / ( FLOAT f ) const
  147. {
  148. FLOAT fInv = 1.0f / f;
  149. return D3DXVECTOR2(x * fInv, y * fInv);
  150. }
  151. D3DXINLINE D3DXVECTOR2
  152. operator * ( FLOAT f, CONST D3DXVECTOR2& v )
  153. {
  154. return D3DXVECTOR2(f * v.x, f * v.y);
  155. }
  156. D3DXINLINE BOOL
  157. D3DXVECTOR2::operator == ( CONST D3DXVECTOR2& v ) const
  158. {
  159. return x == v.x && y == v.y;
  160. }
  161. D3DXINLINE BOOL
  162. D3DXVECTOR2::operator != ( CONST D3DXVECTOR2& v ) const
  163. {
  164. return x != v.x || y != v.y;
  165. }
  166. //--------------------------
  167. // 2D Vector (16 bit)
  168. //--------------------------
  169. D3DXINLINE
  170. D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST FLOAT *pf )
  171. {
  172. #ifdef D3DX_DEBUG
  173. if(!pf)
  174. return;
  175. #endif
  176. D3DXFloat32To16Array(&x, pf, 2);
  177. }
  178. D3DXINLINE
  179. D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 *pf )
  180. {
  181. #ifdef D3DX_DEBUG
  182. if(!pf)
  183. return;
  184. #endif
  185. *((DWORD *) &x) = *((DWORD *) &pf[0]);
  186. }
  187. D3DXINLINE
  188. D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy )
  189. {
  190. x = fx;
  191. y = fy;
  192. }
  193. // casting
  194. D3DXINLINE
  195. D3DXVECTOR2_16F::operator D3DXFLOAT16* ()
  196. {
  197. return (D3DXFLOAT16*) &x;
  198. }
  199. D3DXINLINE
  200. D3DXVECTOR2_16F::operator CONST D3DXFLOAT16* () const
  201. {
  202. return (CONST D3DXFLOAT16*) &x;
  203. }
  204. // binary operators
  205. D3DXINLINE BOOL
  206. D3DXVECTOR2_16F::operator == ( CONST D3DXVECTOR2_16F &v ) const
  207. {
  208. return *((DWORD *) &x) == *((DWORD *) &v.x);
  209. }
  210. D3DXINLINE BOOL
  211. D3DXVECTOR2_16F::operator != ( CONST D3DXVECTOR2_16F &v ) const
  212. {
  213. return *((DWORD *) &x) != *((DWORD *) &v.x);
  214. }
  215. //--------------------------
  216. // 3D Vector
  217. //--------------------------
  218. D3DXINLINE
  219. D3DXVECTOR3::D3DXVECTOR3( CONST FLOAT *pf )
  220. {
  221. #ifdef D3DX_DEBUG
  222. if(!pf)
  223. return;
  224. #endif
  225. x = pf[0];
  226. y = pf[1];
  227. z = pf[2];
  228. }
  229. D3DXINLINE
  230. D3DXVECTOR3::D3DXVECTOR3( CONST D3DVECTOR& v )
  231. {
  232. x = v.x;
  233. y = v.y;
  234. z = v.z;
  235. }
  236. D3DXINLINE
  237. D3DXVECTOR3::D3DXVECTOR3( CONST D3DXFLOAT16 *pf )
  238. {
  239. #ifdef D3DX_DEBUG
  240. if(!pf)
  241. return;
  242. #endif
  243. D3DXFloat16To32Array(&x, pf, 3);
  244. }
  245. D3DXINLINE
  246. D3DXVECTOR3::D3DXVECTOR3( FLOAT fx, FLOAT fy, FLOAT fz )
  247. {
  248. x = fx;
  249. y = fy;
  250. z = fz;
  251. }
  252. // casting
  253. D3DXINLINE
  254. D3DXVECTOR3::operator FLOAT* ()
  255. {
  256. return (FLOAT *) &x;
  257. }
  258. D3DXINLINE
  259. D3DXVECTOR3::operator CONST FLOAT* () const
  260. {
  261. return (CONST FLOAT *) &x;
  262. }
  263. // assignment operators
  264. D3DXINLINE D3DXVECTOR3&
  265. D3DXVECTOR3::operator += ( CONST D3DXVECTOR3& v )
  266. {
  267. x += v.x;
  268. y += v.y;
  269. z += v.z;
  270. return *this;
  271. }
  272. D3DXINLINE D3DXVECTOR3&
  273. D3DXVECTOR3::operator -= ( CONST D3DXVECTOR3& v )
  274. {
  275. x -= v.x;
  276. y -= v.y;
  277. z -= v.z;
  278. return *this;
  279. }
  280. D3DXINLINE D3DXVECTOR3&
  281. D3DXVECTOR3::operator *= ( FLOAT f )
  282. {
  283. x *= f;
  284. y *= f;
  285. z *= f;
  286. return *this;
  287. }
  288. D3DXINLINE D3DXVECTOR3&
  289. D3DXVECTOR3::operator /= ( FLOAT f )
  290. {
  291. FLOAT fInv = 1.0f / f;
  292. x *= fInv;
  293. y *= fInv;
  294. z *= fInv;
  295. return *this;
  296. }
  297. // unary operators
  298. D3DXINLINE D3DXVECTOR3
  299. D3DXVECTOR3::operator + () const
  300. {
  301. return *this;
  302. }
  303. D3DXINLINE D3DXVECTOR3
  304. D3DXVECTOR3::operator - () const
  305. {
  306. return D3DXVECTOR3(-x, -y, -z);
  307. }
  308. // binary operators
  309. D3DXINLINE D3DXVECTOR3
  310. D3DXVECTOR3::operator + ( CONST D3DXVECTOR3& v ) const
  311. {
  312. return D3DXVECTOR3(x + v.x, y + v.y, z + v.z);
  313. }
  314. D3DXINLINE D3DXVECTOR3
  315. D3DXVECTOR3::operator - ( CONST D3DXVECTOR3& v ) const
  316. {
  317. return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
  318. }
  319. D3DXINLINE D3DXVECTOR3
  320. D3DXVECTOR3::operator * ( FLOAT f ) const
  321. {
  322. return D3DXVECTOR3(x * f, y * f, z * f);
  323. }
  324. D3DXINLINE D3DXVECTOR3
  325. D3DXVECTOR3::operator / ( FLOAT f ) const
  326. {
  327. FLOAT fInv = 1.0f / f;
  328. return D3DXVECTOR3(x * fInv, y * fInv, z * fInv);
  329. }
  330. D3DXINLINE D3DXVECTOR3
  331. operator * ( FLOAT f, CONST struct D3DXVECTOR3& v )
  332. {
  333. return D3DXVECTOR3(f * v.x, f * v.y, f * v.z);
  334. }
  335. D3DXINLINE BOOL
  336. D3DXVECTOR3::operator == ( CONST D3DXVECTOR3& v ) const
  337. {
  338. return x == v.x && y == v.y && z == v.z;
  339. }
  340. D3DXINLINE BOOL
  341. D3DXVECTOR3::operator != ( CONST D3DXVECTOR3& v ) const
  342. {
  343. return x != v.x || y != v.y || z != v.z;
  344. }
  345. //--------------------------
  346. // 3D Vector (16 bit)
  347. //--------------------------
  348. D3DXINLINE
  349. D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST FLOAT *pf )
  350. {
  351. #ifdef D3DX_DEBUG
  352. if(!pf)
  353. return;
  354. #endif
  355. D3DXFloat32To16Array(&x, pf, 3);
  356. }
  357. D3DXINLINE
  358. D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DVECTOR& v )
  359. {
  360. D3DXFloat32To16Array(&x, &v.x, 1);
  361. D3DXFloat32To16Array(&y, &v.y, 1);
  362. D3DXFloat32To16Array(&z, &v.z, 1);
  363. }
  364. D3DXINLINE
  365. D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 *pf )
  366. {
  367. #ifdef D3DX_DEBUG
  368. if(!pf)
  369. return;
  370. #endif
  371. *((DWORD *) &x) = *((DWORD *) &pf[0]);
  372. *((WORD *) &z) = *((WORD *) &pf[2]);
  373. }
  374. D3DXINLINE
  375. D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz )
  376. {
  377. x = fx;
  378. y = fy;
  379. z = fz;
  380. }
  381. // casting
  382. D3DXINLINE
  383. D3DXVECTOR3_16F::operator D3DXFLOAT16* ()
  384. {
  385. return (D3DXFLOAT16*) &x;
  386. }
  387. D3DXINLINE
  388. D3DXVECTOR3_16F::operator CONST D3DXFLOAT16* () const
  389. {
  390. return (CONST D3DXFLOAT16*) &x;
  391. }
  392. // binary operators
  393. D3DXINLINE BOOL
  394. D3DXVECTOR3_16F::operator == ( CONST D3DXVECTOR3_16F &v ) const
  395. {
  396. return *((DWORD *) &x) == *((DWORD *) &v.x) &&
  397. *((WORD *) &z) == *((WORD *) &v.z);
  398. }
  399. D3DXINLINE BOOL
  400. D3DXVECTOR3_16F::operator != ( CONST D3DXVECTOR3_16F &v ) const
  401. {
  402. return *((DWORD *) &x) != *((DWORD *) &v.x) ||
  403. *((WORD *) &z) != *((WORD *) &v.z);
  404. }
  405. //--------------------------
  406. // 4D Vector
  407. //--------------------------
  408. D3DXINLINE
  409. D3DXVECTOR4::D3DXVECTOR4( CONST FLOAT *pf )
  410. {
  411. #ifdef D3DX_DEBUG
  412. if(!pf)
  413. return;
  414. #endif
  415. x = pf[0];
  416. y = pf[1];
  417. z = pf[2];
  418. w = pf[3];
  419. }
  420. D3DXINLINE
  421. D3DXVECTOR4::D3DXVECTOR4( CONST D3DXFLOAT16 *pf )
  422. {
  423. #ifdef D3DX_DEBUG
  424. if(!pf)
  425. return;
  426. #endif
  427. D3DXFloat16To32Array(&x, pf, 4);
  428. }
  429. D3DXINLINE
  430. D3DXVECTOR4::D3DXVECTOR4( CONST D3DVECTOR& v, FLOAT f )
  431. {
  432. x = v.x;
  433. y = v.y;
  434. z = v.z;
  435. w = f;
  436. }
  437. D3DXINLINE
  438. D3DXVECTOR4::D3DXVECTOR4( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
  439. {
  440. x = fx;
  441. y = fy;
  442. z = fz;
  443. w = fw;
  444. }
  445. // casting
  446. D3DXINLINE
  447. D3DXVECTOR4::operator FLOAT* ()
  448. {
  449. return (FLOAT *) &x;
  450. }
  451. D3DXINLINE
  452. D3DXVECTOR4::operator CONST FLOAT* () const
  453. {
  454. return (CONST FLOAT *) &x;
  455. }
  456. // assignment operators
  457. D3DXINLINE D3DXVECTOR4&
  458. D3DXVECTOR4::operator += ( CONST D3DXVECTOR4& v )
  459. {
  460. x += v.x;
  461. y += v.y;
  462. z += v.z;
  463. w += v.w;
  464. return *this;
  465. }
  466. D3DXINLINE D3DXVECTOR4&
  467. D3DXVECTOR4::operator -= ( CONST D3DXVECTOR4& v )
  468. {
  469. x -= v.x;
  470. y -= v.y;
  471. z -= v.z;
  472. w -= v.w;
  473. return *this;
  474. }
  475. D3DXINLINE D3DXVECTOR4&
  476. D3DXVECTOR4::operator *= ( FLOAT f )
  477. {
  478. x *= f;
  479. y *= f;
  480. z *= f;
  481. w *= f;
  482. return *this;
  483. }
  484. D3DXINLINE D3DXVECTOR4&
  485. D3DXVECTOR4::operator /= ( FLOAT f )
  486. {
  487. FLOAT fInv = 1.0f / f;
  488. x *= fInv;
  489. y *= fInv;
  490. z *= fInv;
  491. w *= fInv;
  492. return *this;
  493. }
  494. // unary operators
  495. D3DXINLINE D3DXVECTOR4
  496. D3DXVECTOR4::operator + () const
  497. {
  498. return *this;
  499. }
  500. D3DXINLINE D3DXVECTOR4
  501. D3DXVECTOR4::operator - () const
  502. {
  503. return D3DXVECTOR4(-x, -y, -z, -w);
  504. }
  505. // binary operators
  506. D3DXINLINE D3DXVECTOR4
  507. D3DXVECTOR4::operator + ( CONST D3DXVECTOR4& v ) const
  508. {
  509. return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w);
  510. }
  511. D3DXINLINE D3DXVECTOR4
  512. D3DXVECTOR4::operator - ( CONST D3DXVECTOR4& v ) const
  513. {
  514. return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w);
  515. }
  516. D3DXINLINE D3DXVECTOR4
  517. D3DXVECTOR4::operator * ( FLOAT f ) const
  518. {
  519. return D3DXVECTOR4(x * f, y * f, z * f, w * f);
  520. }
  521. D3DXINLINE D3DXVECTOR4
  522. D3DXVECTOR4::operator / ( FLOAT f ) const
  523. {
  524. FLOAT fInv = 1.0f / f;
  525. return D3DXVECTOR4(x * fInv, y * fInv, z * fInv, w * fInv);
  526. }
  527. D3DXINLINE D3DXVECTOR4
  528. operator * ( FLOAT f, CONST D3DXVECTOR4& v )
  529. {
  530. return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w);
  531. }
  532. D3DXINLINE BOOL
  533. D3DXVECTOR4::operator == ( CONST D3DXVECTOR4& v ) const
  534. {
  535. return x == v.x && y == v.y && z == v.z && w == v.w;
  536. }
  537. D3DXINLINE BOOL
  538. D3DXVECTOR4::operator != ( CONST D3DXVECTOR4& v ) const
  539. {
  540. return x != v.x || y != v.y || z != v.z || w != v.w;
  541. }
  542. //--------------------------
  543. // 4D Vector (16 bit)
  544. //--------------------------
  545. D3DXINLINE
  546. D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST FLOAT *pf )
  547. {
  548. #ifdef D3DX_DEBUG
  549. if(!pf)
  550. return;
  551. #endif
  552. D3DXFloat32To16Array(&x, pf, 4);
  553. }
  554. D3DXINLINE
  555. D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 *pf )
  556. {
  557. #ifdef D3DX_DEBUG
  558. if(!pf)
  559. return;
  560. #endif
  561. *((DWORD *) &x) = *((DWORD *) &pf[0]);
  562. *((DWORD *) &z) = *((DWORD *) &pf[2]);
  563. }
  564. D3DXINLINE
  565. D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXVECTOR3_16F& v, CONST D3DXFLOAT16& f )
  566. {
  567. x = v.x;
  568. y = v.y;
  569. z = v.z;
  570. w = f;
  571. }
  572. D3DXINLINE
  573. D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz, CONST D3DXFLOAT16 &fw )
  574. {
  575. x = fx;
  576. y = fy;
  577. z = fz;
  578. w = fw;
  579. }
  580. // casting
  581. D3DXINLINE
  582. D3DXVECTOR4_16F::operator D3DXFLOAT16* ()
  583. {
  584. return (D3DXFLOAT16*) &x;
  585. }
  586. D3DXINLINE
  587. D3DXVECTOR4_16F::operator CONST D3DXFLOAT16* () const
  588. {
  589. return (CONST D3DXFLOAT16*) &x;
  590. }
  591. // binary operators
  592. D3DXINLINE BOOL
  593. D3DXVECTOR4_16F::operator == ( CONST D3DXVECTOR4_16F &v ) const
  594. {
  595. return *((DWORD *) &x) == *((DWORD *) &v.x) &&
  596. *((DWORD *) &z) == *((DWORD *) &v.z);
  597. }
  598. D3DXINLINE BOOL
  599. D3DXVECTOR4_16F::operator != ( CONST D3DXVECTOR4_16F &v ) const
  600. {
  601. return *((DWORD *) &x) != *((DWORD *) &v.x) ||
  602. *((DWORD *) &z) != *((DWORD *) &v.z);
  603. }
  604. //--------------------------
  605. // Matrix
  606. //--------------------------
  607. D3DXINLINE
  608. D3DXMATRIX::D3DXMATRIX( CONST FLOAT* pf )
  609. {
  610. #ifdef D3DX_DEBUG
  611. if(!pf)
  612. return;
  613. #endif
  614. memcpy(&_11, pf, sizeof(D3DXMATRIX));
  615. }
  616. D3DXINLINE
  617. D3DXMATRIX::D3DXMATRIX( CONST D3DMATRIX& mat )
  618. {
  619. memcpy(&_11, &mat, sizeof(D3DXMATRIX));
  620. }
  621. D3DXINLINE
  622. D3DXMATRIX::D3DXMATRIX( CONST D3DXFLOAT16* pf )
  623. {
  624. #ifdef D3DX_DEBUG
  625. if(!pf)
  626. return;
  627. #endif
  628. D3DXFloat16To32Array(&_11, pf, 16);
  629. }
  630. D3DXINLINE
  631. D3DXMATRIX::D3DXMATRIX( FLOAT f11, FLOAT f12, FLOAT f13, FLOAT f14,
  632. FLOAT f21, FLOAT f22, FLOAT f23, FLOAT f24,
  633. FLOAT f31, FLOAT f32, FLOAT f33, FLOAT f34,
  634. FLOAT f41, FLOAT f42, FLOAT f43, FLOAT f44 )
  635. {
  636. _11 = f11; _12 = f12; _13 = f13; _14 = f14;
  637. _21 = f21; _22 = f22; _23 = f23; _24 = f24;
  638. _31 = f31; _32 = f32; _33 = f33; _34 = f34;
  639. _41 = f41; _42 = f42; _43 = f43; _44 = f44;
  640. }
  641. // access grants
  642. D3DXINLINE FLOAT&
  643. D3DXMATRIX::operator () ( UINT iRow, UINT iCol )
  644. {
  645. return m[iRow][iCol];
  646. }
  647. D3DXINLINE FLOAT
  648. D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) const
  649. {
  650. return m[iRow][iCol];
  651. }
  652. // casting operators
  653. D3DXINLINE
  654. D3DXMATRIX::operator FLOAT* ()
  655. {
  656. return (FLOAT *) &_11;
  657. }
  658. D3DXINLINE
  659. D3DXMATRIX::operator CONST FLOAT* () const
  660. {
  661. return (CONST FLOAT *) &_11;
  662. }
  663. // assignment operators
  664. D3DXINLINE D3DXMATRIX&
  665. D3DXMATRIX::operator *= ( CONST D3DXMATRIX& mat )
  666. {
  667. D3DXMatrixMultiply(this, this, &mat);
  668. return *this;
  669. }
  670. D3DXINLINE D3DXMATRIX&
  671. D3DXMATRIX::operator += ( CONST D3DXMATRIX& mat )
  672. {
  673. _11 += mat._11; _12 += mat._12; _13 += mat._13; _14 += mat._14;
  674. _21 += mat._21; _22 += mat._22; _23 += mat._23; _24 += mat._24;
  675. _31 += mat._31; _32 += mat._32; _33 += mat._33; _34 += mat._34;
  676. _41 += mat._41; _42 += mat._42; _43 += mat._43; _44 += mat._44;
  677. return *this;
  678. }
  679. D3DXINLINE D3DXMATRIX&
  680. D3DXMATRIX::operator -= ( CONST D3DXMATRIX& mat )
  681. {
  682. _11 -= mat._11; _12 -= mat._12; _13 -= mat._13; _14 -= mat._14;
  683. _21 -= mat._21; _22 -= mat._22; _23 -= mat._23; _24 -= mat._24;
  684. _31 -= mat._31; _32 -= mat._32; _33 -= mat._33; _34 -= mat._34;
  685. _41 -= mat._41; _42 -= mat._42; _43 -= mat._43; _44 -= mat._44;
  686. return *this;
  687. }
  688. D3DXINLINE D3DXMATRIX&
  689. D3DXMATRIX::operator *= ( FLOAT f )
  690. {
  691. _11 *= f; _12 *= f; _13 *= f; _14 *= f;
  692. _21 *= f; _22 *= f; _23 *= f; _24 *= f;
  693. _31 *= f; _32 *= f; _33 *= f; _34 *= f;
  694. _41 *= f; _42 *= f; _43 *= f; _44 *= f;
  695. return *this;
  696. }
  697. D3DXINLINE D3DXMATRIX&
  698. D3DXMATRIX::operator /= ( FLOAT f )
  699. {
  700. FLOAT fInv = 1.0f / f;
  701. _11 *= fInv; _12 *= fInv; _13 *= fInv; _14 *= fInv;
  702. _21 *= fInv; _22 *= fInv; _23 *= fInv; _24 *= fInv;
  703. _31 *= fInv; _32 *= fInv; _33 *= fInv; _34 *= fInv;
  704. _41 *= fInv; _42 *= fInv; _43 *= fInv; _44 *= fInv;
  705. return *this;
  706. }
  707. // unary operators
  708. D3DXINLINE D3DXMATRIX
  709. D3DXMATRIX::operator + () const
  710. {
  711. return *this;
  712. }
  713. D3DXINLINE D3DXMATRIX
  714. D3DXMATRIX::operator - () const
  715. {
  716. return D3DXMATRIX(-_11, -_12, -_13, -_14,
  717. -_21, -_22, -_23, -_24,
  718. -_31, -_32, -_33, -_34,
  719. -_41, -_42, -_43, -_44);
  720. }
  721. // binary operators
  722. D3DXINLINE D3DXMATRIX
  723. D3DXMATRIX::operator * ( CONST D3DXMATRIX& mat ) const
  724. {
  725. D3DXMATRIX matT;
  726. D3DXMatrixMultiply(&matT, this, &mat);
  727. return matT;
  728. }
  729. D3DXINLINE D3DXMATRIX
  730. D3DXMATRIX::operator + ( CONST D3DXMATRIX& mat ) const
  731. {
  732. return D3DXMATRIX(_11 + mat._11, _12 + mat._12, _13 + mat._13, _14 + mat._14,
  733. _21 + mat._21, _22 + mat._22, _23 + mat._23, _24 + mat._24,
  734. _31 + mat._31, _32 + mat._32, _33 + mat._33, _34 + mat._34,
  735. _41 + mat._41, _42 + mat._42, _43 + mat._43, _44 + mat._44);
  736. }
  737. D3DXINLINE D3DXMATRIX
  738. D3DXMATRIX::operator - ( CONST D3DXMATRIX& mat ) const
  739. {
  740. return D3DXMATRIX(_11 - mat._11, _12 - mat._12, _13 - mat._13, _14 - mat._14,
  741. _21 - mat._21, _22 - mat._22, _23 - mat._23, _24 - mat._24,
  742. _31 - mat._31, _32 - mat._32, _33 - mat._33, _34 - mat._34,
  743. _41 - mat._41, _42 - mat._42, _43 - mat._43, _44 - mat._44);
  744. }
  745. D3DXINLINE D3DXMATRIX
  746. D3DXMATRIX::operator * ( FLOAT f ) const
  747. {
  748. return D3DXMATRIX(_11 * f, _12 * f, _13 * f, _14 * f,
  749. _21 * f, _22 * f, _23 * f, _24 * f,
  750. _31 * f, _32 * f, _33 * f, _34 * f,
  751. _41 * f, _42 * f, _43 * f, _44 * f);
  752. }
  753. D3DXINLINE D3DXMATRIX
  754. D3DXMATRIX::operator / ( FLOAT f ) const
  755. {
  756. FLOAT fInv = 1.0f / f;
  757. return D3DXMATRIX(_11 * fInv, _12 * fInv, _13 * fInv, _14 * fInv,
  758. _21 * fInv, _22 * fInv, _23 * fInv, _24 * fInv,
  759. _31 * fInv, _32 * fInv, _33 * fInv, _34 * fInv,
  760. _41 * fInv, _42 * fInv, _43 * fInv, _44 * fInv);
  761. }
  762. D3DXINLINE D3DXMATRIX
  763. operator * ( FLOAT f, CONST D3DXMATRIX& mat )
  764. {
  765. return D3DXMATRIX(f * mat._11, f * mat._12, f * mat._13, f * mat._14,
  766. f * mat._21, f * mat._22, f * mat._23, f * mat._24,
  767. f * mat._31, f * mat._32, f * mat._33, f * mat._34,
  768. f * mat._41, f * mat._42, f * mat._43, f * mat._44);
  769. }
  770. D3DXINLINE BOOL
  771. D3DXMATRIX::operator == ( CONST D3DXMATRIX& mat ) const
  772. {
  773. return 0 == memcmp(this, &mat, sizeof(D3DXMATRIX));
  774. }
  775. D3DXINLINE BOOL
  776. D3DXMATRIX::operator != ( CONST D3DXMATRIX& mat ) const
  777. {
  778. return 0 != memcmp(this, &mat, sizeof(D3DXMATRIX));
  779. }
  780. //--------------------------
  781. // Aligned Matrices
  782. //--------------------------
  783. D3DXINLINE
  784. _D3DXMATRIXA16::_D3DXMATRIXA16( CONST FLOAT* f ) :
  785. D3DXMATRIX( f )
  786. {
  787. }
  788. D3DXINLINE
  789. _D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DMATRIX& m ) :
  790. D3DXMATRIX( m )
  791. {
  792. }
  793. D3DXINLINE
  794. _D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DXFLOAT16* f ) :
  795. D3DXMATRIX( f )
  796. {
  797. }
  798. D3DXINLINE
  799. _D3DXMATRIXA16::_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  800. FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  801. FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  802. FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ) :
  803. D3DXMATRIX(_11, _12, _13, _14,
  804. _21, _22, _23, _24,
  805. _31, _32, _33, _34,
  806. _41, _42, _43, _44)
  807. {
  808. }
  809. #ifndef SIZE_MAX
  810. #define SIZE_MAX ((SIZE_T)-1)
  811. #endif
  812. D3DXINLINE void*
  813. _D3DXMATRIXA16::operator new( size_t s )
  814. {
  815. if (s > (SIZE_MAX-16))
  816. return NULL;
  817. LPBYTE p = ::new BYTE[s + 16];
  818. if (p)
  819. {
  820. BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
  821. p += offset;
  822. p[-1] = offset;
  823. }
  824. return p;
  825. }
  826. D3DXINLINE void*
  827. _D3DXMATRIXA16::operator new[]( size_t s )
  828. {
  829. if (s > (SIZE_MAX-16))
  830. return NULL;
  831. LPBYTE p = ::new BYTE[s + 16];
  832. if (p)
  833. {
  834. BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15));
  835. p += offset;
  836. p[-1] = offset;
  837. }
  838. return p;
  839. }
  840. D3DXINLINE void
  841. _D3DXMATRIXA16::operator delete(void* p)
  842. {
  843. if(p)
  844. {
  845. BYTE* pb = static_cast<BYTE*>(p);
  846. pb -= pb[-1];
  847. ::delete [] pb;
  848. }
  849. }
  850. D3DXINLINE void
  851. _D3DXMATRIXA16::operator delete[](void* p)
  852. {
  853. if(p)
  854. {
  855. BYTE* pb = static_cast<BYTE*>(p);
  856. pb -= pb[-1];
  857. ::delete [] pb;
  858. }
  859. }
  860. D3DXINLINE _D3DXMATRIXA16&
  861. _D3DXMATRIXA16::operator=(CONST D3DXMATRIX& rhs)
  862. {
  863. memcpy(&_11, &rhs, sizeof(D3DXMATRIX));
  864. return *this;
  865. }
  866. //--------------------------
  867. // Quaternion
  868. //--------------------------
  869. D3DXINLINE
  870. D3DXQUATERNION::D3DXQUATERNION( CONST FLOAT* pf )
  871. {
  872. #ifdef D3DX_DEBUG
  873. if(!pf)
  874. return;
  875. #endif
  876. x = pf[0];
  877. y = pf[1];
  878. z = pf[2];
  879. w = pf[3];
  880. }
  881. D3DXINLINE
  882. D3DXQUATERNION::D3DXQUATERNION( CONST D3DXFLOAT16* pf )
  883. {
  884. #ifdef D3DX_DEBUG
  885. if(!pf)
  886. return;
  887. #endif
  888. D3DXFloat16To32Array(&x, pf, 4);
  889. }
  890. D3DXINLINE
  891. D3DXQUATERNION::D3DXQUATERNION( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw )
  892. {
  893. x = fx;
  894. y = fy;
  895. z = fz;
  896. w = fw;
  897. }
  898. // casting
  899. D3DXINLINE
  900. D3DXQUATERNION::operator FLOAT* ()
  901. {
  902. return (FLOAT *) &x;
  903. }
  904. D3DXINLINE
  905. D3DXQUATERNION::operator CONST FLOAT* () const
  906. {
  907. return (CONST FLOAT *) &x;
  908. }
  909. // assignment operators
  910. D3DXINLINE D3DXQUATERNION&
  911. D3DXQUATERNION::operator += ( CONST D3DXQUATERNION& q )
  912. {
  913. x += q.x;
  914. y += q.y;
  915. z += q.z;
  916. w += q.w;
  917. return *this;
  918. }
  919. D3DXINLINE D3DXQUATERNION&
  920. D3DXQUATERNION::operator -= ( CONST D3DXQUATERNION& q )
  921. {
  922. x -= q.x;
  923. y -= q.y;
  924. z -= q.z;
  925. w -= q.w;
  926. return *this;
  927. }
  928. D3DXINLINE D3DXQUATERNION&
  929. D3DXQUATERNION::operator *= ( CONST D3DXQUATERNION& q )
  930. {
  931. D3DXQuaternionMultiply(this, this, &q);
  932. return *this;
  933. }
  934. D3DXINLINE D3DXQUATERNION&
  935. D3DXQUATERNION::operator *= ( FLOAT f )
  936. {
  937. x *= f;
  938. y *= f;
  939. z *= f;
  940. w *= f;
  941. return *this;
  942. }
  943. D3DXINLINE D3DXQUATERNION&
  944. D3DXQUATERNION::operator /= ( FLOAT f )
  945. {
  946. FLOAT fInv = 1.0f / f;
  947. x *= fInv;
  948. y *= fInv;
  949. z *= fInv;
  950. w *= fInv;
  951. return *this;
  952. }
  953. // unary operators
  954. D3DXINLINE D3DXQUATERNION
  955. D3DXQUATERNION::operator + () const
  956. {
  957. return *this;
  958. }
  959. D3DXINLINE D3DXQUATERNION
  960. D3DXQUATERNION::operator - () const
  961. {
  962. return D3DXQUATERNION(-x, -y, -z, -w);
  963. }
  964. // binary operators
  965. D3DXINLINE D3DXQUATERNION
  966. D3DXQUATERNION::operator + ( CONST D3DXQUATERNION& q ) const
  967. {
  968. return D3DXQUATERNION(x + q.x, y + q.y, z + q.z, w + q.w);
  969. }
  970. D3DXINLINE D3DXQUATERNION
  971. D3DXQUATERNION::operator - ( CONST D3DXQUATERNION& q ) const
  972. {
  973. return D3DXQUATERNION(x - q.x, y - q.y, z - q.z, w - q.w);
  974. }
  975. D3DXINLINE D3DXQUATERNION
  976. D3DXQUATERNION::operator * ( CONST D3DXQUATERNION& q ) const
  977. {
  978. D3DXQUATERNION qT;
  979. D3DXQuaternionMultiply(&qT, this, &q);
  980. return qT;
  981. }
  982. D3DXINLINE D3DXQUATERNION
  983. D3DXQUATERNION::operator * ( FLOAT f ) const
  984. {
  985. return D3DXQUATERNION(x * f, y * f, z * f, w * f);
  986. }
  987. D3DXINLINE D3DXQUATERNION
  988. D3DXQUATERNION::operator / ( FLOAT f ) const
  989. {
  990. FLOAT fInv = 1.0f / f;
  991. return D3DXQUATERNION(x * fInv, y * fInv, z * fInv, w * fInv);
  992. }
  993. D3DXINLINE D3DXQUATERNION
  994. operator * (FLOAT f, CONST D3DXQUATERNION& q )
  995. {
  996. return D3DXQUATERNION(f * q.x, f * q.y, f * q.z, f * q.w);
  997. }
  998. D3DXINLINE BOOL
  999. D3DXQUATERNION::operator == ( CONST D3DXQUATERNION& q ) const
  1000. {
  1001. return x == q.x && y == q.y && z == q.z && w == q.w;
  1002. }
  1003. D3DXINLINE BOOL
  1004. D3DXQUATERNION::operator != ( CONST D3DXQUATERNION& q ) const
  1005. {
  1006. return x != q.x || y != q.y || z != q.z || w != q.w;
  1007. }
  1008. //--------------------------
  1009. // Plane
  1010. //--------------------------
  1011. D3DXINLINE
  1012. D3DXPLANE::D3DXPLANE( CONST FLOAT* pf )
  1013. {
  1014. #ifdef D3DX_DEBUG
  1015. if(!pf)
  1016. return;
  1017. #endif
  1018. a = pf[0];
  1019. b = pf[1];
  1020. c = pf[2];
  1021. d = pf[3];
  1022. }
  1023. D3DXINLINE
  1024. D3DXPLANE::D3DXPLANE( CONST D3DXFLOAT16* pf )
  1025. {
  1026. #ifdef D3DX_DEBUG
  1027. if(!pf)
  1028. return;
  1029. #endif
  1030. D3DXFloat16To32Array(&a, pf, 4);
  1031. }
  1032. D3DXINLINE
  1033. D3DXPLANE::D3DXPLANE( FLOAT fa, FLOAT fb, FLOAT fc, FLOAT fd )
  1034. {
  1035. a = fa;
  1036. b = fb;
  1037. c = fc;
  1038. d = fd;
  1039. }
  1040. // casting
  1041. D3DXINLINE
  1042. D3DXPLANE::operator FLOAT* ()
  1043. {
  1044. return (FLOAT *) &a;
  1045. }
  1046. D3DXINLINE
  1047. D3DXPLANE::operator CONST FLOAT* () const
  1048. {
  1049. return (CONST FLOAT *) &a;
  1050. }
  1051. // assignment operators
  1052. D3DXINLINE D3DXPLANE&
  1053. D3DXPLANE::operator *= ( FLOAT f )
  1054. {
  1055. a *= f;
  1056. b *= f;
  1057. c *= f;
  1058. d *= f;
  1059. return *this;
  1060. }
  1061. D3DXINLINE D3DXPLANE&
  1062. D3DXPLANE::operator /= ( FLOAT f )
  1063. {
  1064. FLOAT fInv = 1.0f / f;
  1065. a *= fInv;
  1066. b *= fInv;
  1067. c *= fInv;
  1068. d *= fInv;
  1069. return *this;
  1070. }
  1071. // unary operators
  1072. D3DXINLINE D3DXPLANE
  1073. D3DXPLANE::operator + () const
  1074. {
  1075. return *this;
  1076. }
  1077. D3DXINLINE D3DXPLANE
  1078. D3DXPLANE::operator - () const
  1079. {
  1080. return D3DXPLANE(-a, -b, -c, -d);
  1081. }
  1082. // binary operators
  1083. D3DXINLINE D3DXPLANE
  1084. D3DXPLANE::operator * ( FLOAT f ) const
  1085. {
  1086. return D3DXPLANE(a * f, b * f, c * f, d * f);
  1087. }
  1088. D3DXINLINE D3DXPLANE
  1089. D3DXPLANE::operator / ( FLOAT f ) const
  1090. {
  1091. FLOAT fInv = 1.0f / f;
  1092. return D3DXPLANE(a * fInv, b * fInv, c * fInv, d * fInv);
  1093. }
  1094. D3DXINLINE D3DXPLANE
  1095. operator * (FLOAT f, CONST D3DXPLANE& p )
  1096. {
  1097. return D3DXPLANE(f * p.a, f * p.b, f * p.c, f * p.d);
  1098. }
  1099. D3DXINLINE BOOL
  1100. D3DXPLANE::operator == ( CONST D3DXPLANE& p ) const
  1101. {
  1102. return a == p.a && b == p.b && c == p.c && d == p.d;
  1103. }
  1104. D3DXINLINE BOOL
  1105. D3DXPLANE::operator != ( CONST D3DXPLANE& p ) const
  1106. {
  1107. return a != p.a || b != p.b || c != p.c || d != p.d;
  1108. }
  1109. //--------------------------
  1110. // Color
  1111. //--------------------------
  1112. D3DXINLINE
  1113. D3DXCOLOR::D3DXCOLOR( DWORD dw )
  1114. {
  1115. CONST FLOAT f = 1.0f / 255.0f;
  1116. r = f * (FLOAT) (unsigned char) (dw >> 16);
  1117. g = f * (FLOAT) (unsigned char) (dw >> 8);
  1118. b = f * (FLOAT) (unsigned char) (dw >> 0);
  1119. a = f * (FLOAT) (unsigned char) (dw >> 24);
  1120. }
  1121. D3DXINLINE
  1122. D3DXCOLOR::D3DXCOLOR( CONST FLOAT* pf )
  1123. {
  1124. #ifdef D3DX_DEBUG
  1125. if(!pf)
  1126. return;
  1127. #endif
  1128. r = pf[0];
  1129. g = pf[1];
  1130. b = pf[2];
  1131. a = pf[3];
  1132. }
  1133. D3DXINLINE
  1134. D3DXCOLOR::D3DXCOLOR( CONST D3DXFLOAT16* pf )
  1135. {
  1136. #ifdef D3DX_DEBUG
  1137. if(!pf)
  1138. return;
  1139. #endif
  1140. D3DXFloat16To32Array(&r, pf, 4);
  1141. }
  1142. D3DXINLINE
  1143. D3DXCOLOR::D3DXCOLOR( CONST D3DCOLORVALUE& c )
  1144. {
  1145. r = c.r;
  1146. g = c.g;
  1147. b = c.b;
  1148. a = c.a;
  1149. }
  1150. D3DXINLINE
  1151. D3DXCOLOR::D3DXCOLOR( FLOAT fr, FLOAT fg, FLOAT fb, FLOAT fa )
  1152. {
  1153. r = fr;
  1154. g = fg;
  1155. b = fb;
  1156. a = fa;
  1157. }
  1158. // casting
  1159. D3DXINLINE
  1160. D3DXCOLOR::operator DWORD () const
  1161. {
  1162. DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
  1163. DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
  1164. DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
  1165. DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
  1166. return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
  1167. }
  1168. D3DXINLINE
  1169. D3DXCOLOR::operator FLOAT * ()
  1170. {
  1171. return (FLOAT *) &r;
  1172. }
  1173. D3DXINLINE
  1174. D3DXCOLOR::operator CONST FLOAT * () const
  1175. {
  1176. return (CONST FLOAT *) &r;
  1177. }
  1178. D3DXINLINE
  1179. D3DXCOLOR::operator D3DCOLORVALUE * ()
  1180. {
  1181. return (D3DCOLORVALUE *) &r;
  1182. }
  1183. D3DXINLINE
  1184. D3DXCOLOR::operator CONST D3DCOLORVALUE * () const
  1185. {
  1186. return (CONST D3DCOLORVALUE *) &r;
  1187. }
  1188. D3DXINLINE
  1189. D3DXCOLOR::operator D3DCOLORVALUE& ()
  1190. {
  1191. return *((D3DCOLORVALUE *) &r);
  1192. }
  1193. D3DXINLINE
  1194. D3DXCOLOR::operator CONST D3DCOLORVALUE& () const
  1195. {
  1196. return *((CONST D3DCOLORVALUE *) &r);
  1197. }
  1198. // assignment operators
  1199. D3DXINLINE D3DXCOLOR&
  1200. D3DXCOLOR::operator += ( CONST D3DXCOLOR& c )
  1201. {
  1202. r += c.r;
  1203. g += c.g;
  1204. b += c.b;
  1205. a += c.a;
  1206. return *this;
  1207. }
  1208. D3DXINLINE D3DXCOLOR&
  1209. D3DXCOLOR::operator -= ( CONST D3DXCOLOR& c )
  1210. {
  1211. r -= c.r;
  1212. g -= c.g;
  1213. b -= c.b;
  1214. a -= c.a;
  1215. return *this;
  1216. }
  1217. D3DXINLINE D3DXCOLOR&
  1218. D3DXCOLOR::operator *= ( FLOAT f )
  1219. {
  1220. r *= f;
  1221. g *= f;
  1222. b *= f;
  1223. a *= f;
  1224. return *this;
  1225. }
  1226. D3DXINLINE D3DXCOLOR&
  1227. D3DXCOLOR::operator /= ( FLOAT f )
  1228. {
  1229. FLOAT fInv = 1.0f / f;
  1230. r *= fInv;
  1231. g *= fInv;
  1232. b *= fInv;
  1233. a *= fInv;
  1234. return *this;
  1235. }
  1236. // unary operators
  1237. D3DXINLINE D3DXCOLOR
  1238. D3DXCOLOR::operator + () const
  1239. {
  1240. return *this;
  1241. }
  1242. D3DXINLINE D3DXCOLOR
  1243. D3DXCOLOR::operator - () const
  1244. {
  1245. return D3DXCOLOR(-r, -g, -b, -a);
  1246. }
  1247. // binary operators
  1248. D3DXINLINE D3DXCOLOR
  1249. D3DXCOLOR::operator + ( CONST D3DXCOLOR& c ) const
  1250. {
  1251. return D3DXCOLOR(r + c.r, g + c.g, b + c.b, a + c.a);
  1252. }
  1253. D3DXINLINE D3DXCOLOR
  1254. D3DXCOLOR::operator - ( CONST D3DXCOLOR& c ) const
  1255. {
  1256. return D3DXCOLOR(r - c.r, g - c.g, b - c.b, a - c.a);
  1257. }
  1258. D3DXINLINE D3DXCOLOR
  1259. D3DXCOLOR::operator * ( FLOAT f ) const
  1260. {
  1261. return D3DXCOLOR(r * f, g * f, b * f, a * f);
  1262. }
  1263. D3DXINLINE D3DXCOLOR
  1264. D3DXCOLOR::operator / ( FLOAT f ) const
  1265. {
  1266. FLOAT fInv = 1.0f / f;
  1267. return D3DXCOLOR(r * fInv, g * fInv, b * fInv, a * fInv);
  1268. }
  1269. D3DXINLINE D3DXCOLOR
  1270. operator * (FLOAT f, CONST D3DXCOLOR& c )
  1271. {
  1272. return D3DXCOLOR(f * c.r, f * c.g, f * c.b, f * c.a);
  1273. }
  1274. D3DXINLINE BOOL
  1275. D3DXCOLOR::operator == ( CONST D3DXCOLOR& c ) const
  1276. {
  1277. return r == c.r && g == c.g && b == c.b && a == c.a;
  1278. }
  1279. D3DXINLINE BOOL
  1280. D3DXCOLOR::operator != ( CONST D3DXCOLOR& c ) const
  1281. {
  1282. return r != c.r || g != c.g || b != c.b || a != c.a;
  1283. }
  1284. #endif //__cplusplus
  1285. //===========================================================================
  1286. //
  1287. // Inline functions
  1288. //
  1289. //===========================================================================
  1290. //--------------------------
  1291. // 2D Vector
  1292. //--------------------------
  1293. D3DXINLINE FLOAT D3DXVec2Length
  1294. ( CONST D3DXVECTOR2 *pV )
  1295. {
  1296. #ifdef D3DX_DEBUG
  1297. if(!pV)
  1298. return 0.0f;
  1299. #endif
  1300. #ifdef __cplusplus
  1301. return sqrtf(pV->x * pV->x + pV->y * pV->y);
  1302. #else
  1303. return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y);
  1304. #endif
  1305. }
  1306. D3DXINLINE FLOAT D3DXVec2LengthSq
  1307. ( CONST D3DXVECTOR2 *pV )
  1308. {
  1309. #ifdef D3DX_DEBUG
  1310. if(!pV)
  1311. return 0.0f;
  1312. #endif
  1313. return pV->x * pV->x + pV->y * pV->y;
  1314. }
  1315. D3DXINLINE FLOAT D3DXVec2Dot
  1316. ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1317. {
  1318. #ifdef D3DX_DEBUG
  1319. if(!pV1 || !pV2)
  1320. return 0.0f;
  1321. #endif
  1322. return pV1->x * pV2->x + pV1->y * pV2->y;
  1323. }
  1324. D3DXINLINE FLOAT D3DXVec2CCW
  1325. ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1326. {
  1327. #ifdef D3DX_DEBUG
  1328. if(!pV1 || !pV2)
  1329. return 0.0f;
  1330. #endif
  1331. return pV1->x * pV2->y - pV1->y * pV2->x;
  1332. }
  1333. D3DXINLINE D3DXVECTOR2* D3DXVec2Add
  1334. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1335. {
  1336. #ifdef D3DX_DEBUG
  1337. if(!pOut || !pV1 || !pV2)
  1338. return NULL;
  1339. #endif
  1340. pOut->x = pV1->x + pV2->x;
  1341. pOut->y = pV1->y + pV2->y;
  1342. return pOut;
  1343. }
  1344. D3DXINLINE D3DXVECTOR2* D3DXVec2Subtract
  1345. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1346. {
  1347. #ifdef D3DX_DEBUG
  1348. if(!pOut || !pV1 || !pV2)
  1349. return NULL;
  1350. #endif
  1351. pOut->x = pV1->x - pV2->x;
  1352. pOut->y = pV1->y - pV2->y;
  1353. return pOut;
  1354. }
  1355. D3DXINLINE D3DXVECTOR2* D3DXVec2Minimize
  1356. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1357. {
  1358. #ifdef D3DX_DEBUG
  1359. if(!pOut || !pV1 || !pV2)
  1360. return NULL;
  1361. #endif
  1362. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  1363. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  1364. return pOut;
  1365. }
  1366. D3DXINLINE D3DXVECTOR2* D3DXVec2Maximize
  1367. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 )
  1368. {
  1369. #ifdef D3DX_DEBUG
  1370. if(!pOut || !pV1 || !pV2)
  1371. return NULL;
  1372. #endif
  1373. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  1374. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  1375. return pOut;
  1376. }
  1377. D3DXINLINE D3DXVECTOR2* D3DXVec2Scale
  1378. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s )
  1379. {
  1380. #ifdef D3DX_DEBUG
  1381. if(!pOut || !pV)
  1382. return NULL;
  1383. #endif
  1384. pOut->x = pV->x * s;
  1385. pOut->y = pV->y * s;
  1386. return pOut;
  1387. }
  1388. D3DXINLINE D3DXVECTOR2* D3DXVec2Lerp
  1389. ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  1390. FLOAT s )
  1391. {
  1392. #ifdef D3DX_DEBUG
  1393. if(!pOut || !pV1 || !pV2)
  1394. return NULL;
  1395. #endif
  1396. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  1397. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  1398. return pOut;
  1399. }
  1400. //--------------------------
  1401. // 3D Vector
  1402. //--------------------------
  1403. D3DXINLINE FLOAT D3DXVec3Length
  1404. ( CONST D3DXVECTOR3 *pV )
  1405. {
  1406. #ifdef D3DX_DEBUG
  1407. if(!pV)
  1408. return 0.0f;
  1409. #endif
  1410. #ifdef __cplusplus
  1411. return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
  1412. #else
  1413. return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
  1414. #endif
  1415. }
  1416. D3DXINLINE FLOAT D3DXVec3LengthSq
  1417. ( CONST D3DXVECTOR3 *pV )
  1418. {
  1419. #ifdef D3DX_DEBUG
  1420. if(!pV)
  1421. return 0.0f;
  1422. #endif
  1423. return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z;
  1424. }
  1425. D3DXINLINE FLOAT D3DXVec3Dot
  1426. ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1427. {
  1428. #ifdef D3DX_DEBUG
  1429. if(!pV1 || !pV2)
  1430. return 0.0f;
  1431. #endif
  1432. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
  1433. }
  1434. D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
  1435. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1436. {
  1437. D3DXVECTOR3 v;
  1438. #ifdef D3DX_DEBUG
  1439. if(!pOut || !pV1 || !pV2)
  1440. return NULL;
  1441. #endif
  1442. v.x = pV1->y * pV2->z - pV1->z * pV2->y;
  1443. v.y = pV1->z * pV2->x - pV1->x * pV2->z;
  1444. v.z = pV1->x * pV2->y - pV1->y * pV2->x;
  1445. *pOut = v;
  1446. return pOut;
  1447. }
  1448. D3DXINLINE D3DXVECTOR3* D3DXVec3Add
  1449. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1450. {
  1451. #ifdef D3DX_DEBUG
  1452. if(!pOut || !pV1 || !pV2)
  1453. return NULL;
  1454. #endif
  1455. pOut->x = pV1->x + pV2->x;
  1456. pOut->y = pV1->y + pV2->y;
  1457. pOut->z = pV1->z + pV2->z;
  1458. return pOut;
  1459. }
  1460. D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract
  1461. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1462. {
  1463. #ifdef D3DX_DEBUG
  1464. if(!pOut || !pV1 || !pV2)
  1465. return NULL;
  1466. #endif
  1467. pOut->x = pV1->x - pV2->x;
  1468. pOut->y = pV1->y - pV2->y;
  1469. pOut->z = pV1->z - pV2->z;
  1470. return pOut;
  1471. }
  1472. D3DXINLINE D3DXVECTOR3* D3DXVec3Minimize
  1473. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1474. {
  1475. #ifdef D3DX_DEBUG
  1476. if(!pOut || !pV1 || !pV2)
  1477. return NULL;
  1478. #endif
  1479. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  1480. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  1481. pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
  1482. return pOut;
  1483. }
  1484. D3DXINLINE D3DXVECTOR3* D3DXVec3Maximize
  1485. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1486. {
  1487. #ifdef D3DX_DEBUG
  1488. if(!pOut || !pV1 || !pV2)
  1489. return NULL;
  1490. #endif
  1491. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  1492. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  1493. pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
  1494. return pOut;
  1495. }
  1496. D3DXINLINE D3DXVECTOR3* D3DXVec3Scale
  1497. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s)
  1498. {
  1499. #ifdef D3DX_DEBUG
  1500. if(!pOut || !pV)
  1501. return NULL;
  1502. #endif
  1503. pOut->x = pV->x * s;
  1504. pOut->y = pV->y * s;
  1505. pOut->z = pV->z * s;
  1506. return pOut;
  1507. }
  1508. D3DXINLINE D3DXVECTOR3* D3DXVec3Lerp
  1509. ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  1510. FLOAT s )
  1511. {
  1512. #ifdef D3DX_DEBUG
  1513. if(!pOut || !pV1 || !pV2)
  1514. return NULL;
  1515. #endif
  1516. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  1517. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  1518. pOut->z = pV1->z + s * (pV2->z - pV1->z);
  1519. return pOut;
  1520. }
  1521. //--------------------------
  1522. // 4D Vector
  1523. //--------------------------
  1524. D3DXINLINE FLOAT D3DXVec4Length
  1525. ( CONST D3DXVECTOR4 *pV )
  1526. {
  1527. #ifdef D3DX_DEBUG
  1528. if(!pV)
  1529. return 0.0f;
  1530. #endif
  1531. #ifdef __cplusplus
  1532. return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
  1533. #else
  1534. return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
  1535. #endif
  1536. }
  1537. D3DXINLINE FLOAT D3DXVec4LengthSq
  1538. ( CONST D3DXVECTOR4 *pV )
  1539. {
  1540. #ifdef D3DX_DEBUG
  1541. if(!pV)
  1542. return 0.0f;
  1543. #endif
  1544. return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w;
  1545. }
  1546. D3DXINLINE FLOAT D3DXVec4Dot
  1547. ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 )
  1548. {
  1549. #ifdef D3DX_DEBUG
  1550. if(!pV1 || !pV2)
  1551. return 0.0f;
  1552. #endif
  1553. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w;
  1554. }
  1555. D3DXINLINE D3DXVECTOR4* D3DXVec4Add
  1556. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
  1557. {
  1558. #ifdef D3DX_DEBUG
  1559. if(!pOut || !pV1 || !pV2)
  1560. return NULL;
  1561. #endif
  1562. pOut->x = pV1->x + pV2->x;
  1563. pOut->y = pV1->y + pV2->y;
  1564. pOut->z = pV1->z + pV2->z;
  1565. pOut->w = pV1->w + pV2->w;
  1566. return pOut;
  1567. }
  1568. D3DXINLINE D3DXVECTOR4* D3DXVec4Subtract
  1569. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
  1570. {
  1571. #ifdef D3DX_DEBUG
  1572. if(!pOut || !pV1 || !pV2)
  1573. return NULL;
  1574. #endif
  1575. pOut->x = pV1->x - pV2->x;
  1576. pOut->y = pV1->y - pV2->y;
  1577. pOut->z = pV1->z - pV2->z;
  1578. pOut->w = pV1->w - pV2->w;
  1579. return pOut;
  1580. }
  1581. D3DXINLINE D3DXVECTOR4* D3DXVec4Minimize
  1582. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
  1583. {
  1584. #ifdef D3DX_DEBUG
  1585. if(!pOut || !pV1 || !pV2)
  1586. return NULL;
  1587. #endif
  1588. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  1589. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  1590. pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
  1591. pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w;
  1592. return pOut;
  1593. }
  1594. D3DXINLINE D3DXVECTOR4* D3DXVec4Maximize
  1595. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2)
  1596. {
  1597. #ifdef D3DX_DEBUG
  1598. if(!pOut || !pV1 || !pV2)
  1599. return NULL;
  1600. #endif
  1601. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  1602. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  1603. pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
  1604. pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w;
  1605. return pOut;
  1606. }
  1607. D3DXINLINE D3DXVECTOR4* D3DXVec4Scale
  1608. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s)
  1609. {
  1610. #ifdef D3DX_DEBUG
  1611. if(!pOut || !pV)
  1612. return NULL;
  1613. #endif
  1614. pOut->x = pV->x * s;
  1615. pOut->y = pV->y * s;
  1616. pOut->z = pV->z * s;
  1617. pOut->w = pV->w * s;
  1618. return pOut;
  1619. }
  1620. D3DXINLINE D3DXVECTOR4* D3DXVec4Lerp
  1621. ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  1622. FLOAT s )
  1623. {
  1624. #ifdef D3DX_DEBUG
  1625. if(!pOut || !pV1 || !pV2)
  1626. return NULL;
  1627. #endif
  1628. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  1629. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  1630. pOut->z = pV1->z + s * (pV2->z - pV1->z);
  1631. pOut->w = pV1->w + s * (pV2->w - pV1->w);
  1632. return pOut;
  1633. }
  1634. //--------------------------
  1635. // 4D Matrix
  1636. //--------------------------
  1637. D3DXINLINE D3DXMATRIX* D3DXMatrixIdentity
  1638. ( D3DXMATRIX *pOut )
  1639. {
  1640. #ifdef D3DX_DEBUG
  1641. if(!pOut)
  1642. return NULL;
  1643. #endif
  1644. pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] =
  1645. pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] =
  1646. pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
  1647. pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
  1648. pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f;
  1649. return pOut;
  1650. }
  1651. D3DXINLINE BOOL D3DXMatrixIsIdentity
  1652. ( CONST D3DXMATRIX *pM )
  1653. {
  1654. #ifdef D3DX_DEBUG
  1655. if(!pM)
  1656. return FALSE;
  1657. #endif
  1658. return pM->m[0][0] == 1.0f && pM->m[0][1] == 0.0f && pM->m[0][2] == 0.0f && pM->m[0][3] == 0.0f &&
  1659. pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f &&
  1660. pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f &&
  1661. pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f;
  1662. }
  1663. //--------------------------
  1664. // Quaternion
  1665. //--------------------------
  1666. D3DXINLINE FLOAT D3DXQuaternionLength
  1667. ( CONST D3DXQUATERNION *pQ )
  1668. {
  1669. #ifdef D3DX_DEBUG
  1670. if(!pQ)
  1671. return 0.0f;
  1672. #endif
  1673. #ifdef __cplusplus
  1674. return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
  1675. #else
  1676. return (FLOAT) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
  1677. #endif
  1678. }
  1679. D3DXINLINE FLOAT D3DXQuaternionLengthSq
  1680. ( CONST D3DXQUATERNION *pQ )
  1681. {
  1682. #ifdef D3DX_DEBUG
  1683. if(!pQ)
  1684. return 0.0f;
  1685. #endif
  1686. return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w;
  1687. }
  1688. D3DXINLINE FLOAT D3DXQuaternionDot
  1689. ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 )
  1690. {
  1691. #ifdef D3DX_DEBUG
  1692. if(!pQ1 || !pQ2)
  1693. return 0.0f;
  1694. #endif
  1695. return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w;
  1696. }
  1697. D3DXINLINE D3DXQUATERNION* D3DXQuaternionIdentity
  1698. ( D3DXQUATERNION *pOut )
  1699. {
  1700. #ifdef D3DX_DEBUG
  1701. if(!pOut)
  1702. return NULL;
  1703. #endif
  1704. pOut->x = pOut->y = pOut->z = 0.0f;
  1705. pOut->w = 1.0f;
  1706. return pOut;
  1707. }
  1708. D3DXINLINE BOOL D3DXQuaternionIsIdentity
  1709. ( CONST D3DXQUATERNION *pQ )
  1710. {
  1711. #ifdef D3DX_DEBUG
  1712. if(!pQ)
  1713. return FALSE;
  1714. #endif
  1715. return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f;
  1716. }
  1717. D3DXINLINE D3DXQUATERNION* D3DXQuaternionConjugate
  1718. ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ )
  1719. {
  1720. #ifdef D3DX_DEBUG
  1721. if(!pOut || !pQ)
  1722. return NULL;
  1723. #endif
  1724. pOut->x = -pQ->x;
  1725. pOut->y = -pQ->y;
  1726. pOut->z = -pQ->z;
  1727. pOut->w = pQ->w;
  1728. return pOut;
  1729. }
  1730. //--------------------------
  1731. // Plane
  1732. //--------------------------
  1733. D3DXINLINE FLOAT D3DXPlaneDot
  1734. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV)
  1735. {
  1736. #ifdef D3DX_DEBUG
  1737. if(!pP || !pV)
  1738. return 0.0f;
  1739. #endif
  1740. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w;
  1741. }
  1742. D3DXINLINE FLOAT D3DXPlaneDotCoord
  1743. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
  1744. {
  1745. #ifdef D3DX_DEBUG
  1746. if(!pP || !pV)
  1747. return 0.0f;
  1748. #endif
  1749. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
  1750. }
  1751. D3DXINLINE FLOAT D3DXPlaneDotNormal
  1752. ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV)
  1753. {
  1754. #ifdef D3DX_DEBUG
  1755. if(!pP || !pV)
  1756. return 0.0f;
  1757. #endif
  1758. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z;
  1759. }
  1760. D3DXINLINE D3DXPLANE* D3DXPlaneScale
  1761. (D3DXPLANE *pOut, CONST D3DXPLANE *pP, FLOAT s)
  1762. {
  1763. #ifdef D3DX_DEBUG
  1764. if(!pOut || !pP)
  1765. return NULL;
  1766. #endif
  1767. pOut->a = pP->a * s;
  1768. pOut->b = pP->b * s;
  1769. pOut->c = pP->c * s;
  1770. pOut->d = pP->d * s;
  1771. return pOut;
  1772. }
  1773. //--------------------------
  1774. // Color
  1775. //--------------------------
  1776. D3DXINLINE D3DXCOLOR* D3DXColorNegative
  1777. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC)
  1778. {
  1779. #ifdef D3DX_DEBUG
  1780. if(!pOut || !pC)
  1781. return NULL;
  1782. #endif
  1783. pOut->r = 1.0f - pC->r;
  1784. pOut->g = 1.0f - pC->g;
  1785. pOut->b = 1.0f - pC->b;
  1786. pOut->a = pC->a;
  1787. return pOut;
  1788. }
  1789. D3DXINLINE D3DXCOLOR* D3DXColorAdd
  1790. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
  1791. {
  1792. #ifdef D3DX_DEBUG
  1793. if(!pOut || !pC1 || !pC2)
  1794. return NULL;
  1795. #endif
  1796. pOut->r = pC1->r + pC2->r;
  1797. pOut->g = pC1->g + pC2->g;
  1798. pOut->b = pC1->b + pC2->b;
  1799. pOut->a = pC1->a + pC2->a;
  1800. return pOut;
  1801. }
  1802. D3DXINLINE D3DXCOLOR* D3DXColorSubtract
  1803. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
  1804. {
  1805. #ifdef D3DX_DEBUG
  1806. if(!pOut || !pC1 || !pC2)
  1807. return NULL;
  1808. #endif
  1809. pOut->r = pC1->r - pC2->r;
  1810. pOut->g = pC1->g - pC2->g;
  1811. pOut->b = pC1->b - pC2->b;
  1812. pOut->a = pC1->a - pC2->a;
  1813. return pOut;
  1814. }
  1815. D3DXINLINE D3DXCOLOR* D3DXColorScale
  1816. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s)
  1817. {
  1818. #ifdef D3DX_DEBUG
  1819. if(!pOut || !pC)
  1820. return NULL;
  1821. #endif
  1822. pOut->r = pC->r * s;
  1823. pOut->g = pC->g * s;
  1824. pOut->b = pC->b * s;
  1825. pOut->a = pC->a * s;
  1826. return pOut;
  1827. }
  1828. D3DXINLINE D3DXCOLOR* D3DXColorModulate
  1829. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2)
  1830. {
  1831. #ifdef D3DX_DEBUG
  1832. if(!pOut || !pC1 || !pC2)
  1833. return NULL;
  1834. #endif
  1835. pOut->r = pC1->r * pC2->r;
  1836. pOut->g = pC1->g * pC2->g;
  1837. pOut->b = pC1->b * pC2->b;
  1838. pOut->a = pC1->a * pC2->a;
  1839. return pOut;
  1840. }
  1841. D3DXINLINE D3DXCOLOR* D3DXColorLerp
  1842. (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s)
  1843. {
  1844. #ifdef D3DX_DEBUG
  1845. if(!pOut || !pC1 || !pC2)
  1846. return NULL;
  1847. #endif
  1848. pOut->r = pC1->r + s * (pC2->r - pC1->r);
  1849. pOut->g = pC1->g + s * (pC2->g - pC1->g);
  1850. pOut->b = pC1->b + s * (pC2->b - pC1->b);
  1851. pOut->a = pC1->a + s * (pC2->a - pC1->a);
  1852. return pOut;
  1853. }
  1854. #endif // __D3DX9MATH_INL__