Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2228 lines
43 KiB

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