Leaked source code of windows server 2003
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.

687 lines
16 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: d3dxmath.inl
  6. // Content: D3DX math inline functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #ifndef __D3DXMATHVB_INL__
  10. #define __D3DXMATHVB_INL__
  11. //===========================================================================
  12. //
  13. // Inline functions
  14. //
  15. //===========================================================================
  16. //--------------------------
  17. // 2D Vector
  18. //--------------------------
  19. float D3DVBCALL VB_D3DXVec2Length
  20. ( const D3DXVECTOR2 *pV )
  21. {
  22. #ifdef D3DX_DEBUG
  23. if(!pV)
  24. return 0.0f;
  25. #endif
  26. #ifdef __cplusplus
  27. return sqrtf(pV->x * pV->x + pV->y * pV->y);
  28. #else
  29. return (float) sqrt(pV->x * pV->x + pV->y * pV->y);
  30. #endif
  31. }
  32. float D3DVBCALL VB_D3DXVec2LengthSq
  33. ( const D3DXVECTOR2 *pV )
  34. {
  35. #ifdef D3DX_DEBUG
  36. if(!pV)
  37. return 0.0f;
  38. #endif
  39. return pV->x * pV->x + pV->y * pV->y;
  40. }
  41. float D3DVBCALL VB_D3DXVec2Dot
  42. ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  43. {
  44. #ifdef D3DX_DEBUG
  45. if(!pV1 || !pV2)
  46. return 0.0f;
  47. #endif
  48. return pV1->x * pV2->x + pV1->y * pV2->y;
  49. }
  50. float D3DVBCALL D3DVBINLINE VB_D3DXVec2CCW
  51. ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  52. {
  53. #ifdef D3DX_DEBUG
  54. if(!pV1 || !pV2)
  55. return 0.0f;
  56. #endif
  57. return pV1->x * pV2->y - pV1->y * pV2->x;
  58. }
  59. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Add
  60. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  61. {
  62. #ifdef D3DX_DEBUG
  63. if(!pOut || !pV1 || !pV2)
  64. return NULL;
  65. #endif
  66. pOut->x = pV1->x + pV2->x;
  67. pOut->y = pV1->y + pV2->y;
  68. return pOut;
  69. }
  70. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Subtract
  71. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  72. {
  73. #ifdef D3DX_DEBUG
  74. if(!pOut || !pV1 || !pV2)
  75. return NULL;
  76. #endif
  77. pOut->x = pV1->x - pV2->x;
  78. pOut->y = pV1->y - pV2->y;
  79. return pOut;
  80. }
  81. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Minimize
  82. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  83. {
  84. #ifdef D3DX_DEBUG
  85. if(!pOut || !pV1 || !pV2)
  86. return NULL;
  87. #endif
  88. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  89. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  90. return pOut;
  91. }
  92. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Maximize
  93. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 )
  94. {
  95. #ifdef D3DX_DEBUG
  96. if(!pOut || !pV1 || !pV2)
  97. return NULL;
  98. #endif
  99. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  100. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  101. return pOut;
  102. }
  103. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Scale
  104. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, float s )
  105. {
  106. #ifdef D3DX_DEBUG
  107. if(!pOut || !pV)
  108. return NULL;
  109. #endif
  110. pOut->x = pV->x * s;
  111. pOut->y = pV->y * s;
  112. return pOut;
  113. }
  114. D3DVBINLINE D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Lerp
  115. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
  116. float s )
  117. {
  118. #ifdef D3DX_DEBUG
  119. if(!pOut || !pV1 || !pV2)
  120. return NULL;
  121. #endif
  122. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  123. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  124. return pOut;
  125. }
  126. //--------------------------
  127. // 3D Vector
  128. //--------------------------
  129. D3DVBINLINE float D3DVBCALL VB_D3DXVec3Length
  130. ( const D3DXVECTOR3 *pV )
  131. {
  132. #ifdef D3DX_DEBUG
  133. if(!pV)
  134. return 0.0f;
  135. #endif
  136. #ifdef __cplusplus
  137. return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
  138. #else
  139. return (float) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z);
  140. #endif
  141. }
  142. D3DVBINLINE float D3DVBCALL VB_D3DXVec3LengthSq
  143. ( const D3DXVECTOR3 *pV )
  144. {
  145. #ifdef D3DX_DEBUG
  146. if(!pV)
  147. return 0.0f;
  148. #endif
  149. return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z;
  150. }
  151. D3DVBINLINE float D3DVBCALL VB_D3DXVec3Dot
  152. ( const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  153. {
  154. #ifdef D3DX_DEBUG
  155. if(!pV1 || !pV2)
  156. return 0.0f;
  157. #endif
  158. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
  159. }
  160. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Cross
  161. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  162. {
  163. D3DXVECTOR3 v;
  164. #ifdef D3DX_DEBUG
  165. if(!pOut || !pV1 || !pV2)
  166. return NULL;
  167. #endif
  168. v.x = pV1->y * pV2->z - pV1->z * pV2->y;
  169. v.y = pV1->z * pV2->x - pV1->x * pV2->z;
  170. v.z = pV1->x * pV2->y - pV1->y * pV2->x;
  171. *pOut = v;
  172. return pOut;
  173. }
  174. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Add
  175. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  176. {
  177. #ifdef D3DX_DEBUG
  178. if(!pOut || !pV1 || !pV2)
  179. return NULL;
  180. #endif
  181. pOut->x = pV1->x + pV2->x;
  182. pOut->y = pV1->y + pV2->y;
  183. pOut->z = pV1->z + pV2->z;
  184. return pOut;
  185. }
  186. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Subtract
  187. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  188. {
  189. #ifdef D3DX_DEBUG
  190. if(!pOut || !pV1 || !pV2)
  191. return NULL;
  192. #endif
  193. pOut->x = pV1->x - pV2->x;
  194. pOut->y = pV1->y - pV2->y;
  195. pOut->z = pV1->z - pV2->z;
  196. return pOut;
  197. }
  198. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Minimize
  199. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  200. {
  201. #ifdef D3DX_DEBUG
  202. if(!pOut || !pV1 || !pV2)
  203. return NULL;
  204. #endif
  205. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  206. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  207. pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
  208. return pOut;
  209. }
  210. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Maximize
  211. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 )
  212. {
  213. #ifdef D3DX_DEBUG
  214. if(!pOut || !pV1 || !pV2)
  215. return NULL;
  216. #endif
  217. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  218. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  219. pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
  220. return pOut;
  221. }
  222. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Scale
  223. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, float s)
  224. {
  225. #ifdef D3DX_DEBUG
  226. if(!pOut || !pV)
  227. return NULL;
  228. #endif
  229. pOut->x = pV->x * s;
  230. pOut->y = pV->y * s;
  231. pOut->z = pV->z * s;
  232. return pOut;
  233. }
  234. D3DVBINLINE D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Lerp
  235. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  236. float s )
  237. {
  238. #ifdef D3DX_DEBUG
  239. if(!pOut || !pV1 || !pV2)
  240. return NULL;
  241. #endif
  242. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  243. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  244. pOut->z = pV1->z + s * (pV2->z - pV1->z);
  245. return pOut;
  246. }
  247. //--------------------------
  248. // 4D Vector
  249. //--------------------------
  250. D3DVBINLINE float D3DVBCALL VB_D3DXVec4Length
  251. ( const D3DXVECTOR4 *pV )
  252. {
  253. #ifdef D3DX_DEBUG
  254. if(!pV)
  255. return 0.0f;
  256. #endif
  257. #ifdef __cplusplus
  258. return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
  259. #else
  260. return (float) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w);
  261. #endif
  262. }
  263. D3DVBINLINE float D3DVBCALL VB_D3DXVec4LengthSq
  264. ( const D3DXVECTOR4 *pV )
  265. {
  266. #ifdef D3DX_DEBUG
  267. if(!pV)
  268. return 0.0f;
  269. #endif
  270. return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w;
  271. }
  272. D3DVBINLINE float D3DVBCALL VB_D3DXVec4Dot
  273. ( const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2 )
  274. {
  275. #ifdef D3DX_DEBUG
  276. if(!pV1 || !pV2)
  277. return 0.0f;
  278. #endif
  279. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w;
  280. }
  281. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Add
  282. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
  283. {
  284. #ifdef D3DX_DEBUG
  285. if(!pOut || !pV1 || !pV2)
  286. return NULL;
  287. #endif
  288. pOut->x = pV1->x + pV2->x;
  289. pOut->y = pV1->y + pV2->y;
  290. pOut->z = pV1->z + pV2->z;
  291. pOut->w = pV1->w + pV2->w;
  292. return pOut;
  293. }
  294. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Subtract
  295. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
  296. {
  297. #ifdef D3DX_DEBUG
  298. if(!pOut || !pV1 || !pV2)
  299. return NULL;
  300. #endif
  301. pOut->x = pV1->x - pV2->x;
  302. pOut->y = pV1->y - pV2->y;
  303. pOut->z = pV1->z - pV2->z;
  304. pOut->w = pV1->w - pV2->w;
  305. return pOut;
  306. }
  307. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Minimize
  308. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
  309. {
  310. #ifdef D3DX_DEBUG
  311. if(!pOut || !pV1 || !pV2)
  312. return NULL;
  313. #endif
  314. pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x;
  315. pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y;
  316. pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z;
  317. pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w;
  318. return pOut;
  319. }
  320. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Maximize
  321. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2)
  322. {
  323. #ifdef D3DX_DEBUG
  324. if(!pOut || !pV1 || !pV2)
  325. return NULL;
  326. #endif
  327. pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x;
  328. pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y;
  329. pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z;
  330. pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w;
  331. return pOut;
  332. }
  333. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Scale
  334. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, float s)
  335. {
  336. #ifdef D3DX_DEBUG
  337. if(!pOut || !pV)
  338. return NULL;
  339. #endif
  340. pOut->x = pV->x * s;
  341. pOut->y = pV->y * s;
  342. pOut->z = pV->z * s;
  343. pOut->w = pV->w * s;
  344. return pOut;
  345. }
  346. D3DVBINLINE D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Lerp
  347. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  348. float s )
  349. {
  350. #ifdef D3DX_DEBUG
  351. if(!pOut || !pV1 || !pV2)
  352. return NULL;
  353. #endif
  354. pOut->x = pV1->x + s * (pV2->x - pV1->x);
  355. pOut->y = pV1->y + s * (pV2->y - pV1->y);
  356. pOut->z = pV1->z + s * (pV2->z - pV1->z);
  357. pOut->w = pV1->w + s * (pV2->w - pV1->w);
  358. return pOut;
  359. }
  360. //--------------------------
  361. // 4D Matrix
  362. //--------------------------
  363. D3DVBINLINE D3DXMATRIX* D3DVBCALL VB_D3DXMatrixIdentity
  364. ( D3DXMATRIX *pOut )
  365. {
  366. #ifdef D3DX_DEBUG
  367. if(!pOut)
  368. return NULL;
  369. #endif
  370. pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] =
  371. pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] =
  372. pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
  373. pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
  374. pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f;
  375. return pOut;
  376. }
  377. D3DVBINLINE BOOL D3DVBCALL VB_D3DXMatrixIsIdentity
  378. ( const D3DXMATRIX *pM )
  379. {
  380. #ifdef D3DX_DEBUG
  381. if(!pM)
  382. return FALSE;
  383. #endif
  384. 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 &&
  385. pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f &&
  386. pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f &&
  387. pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f;
  388. }
  389. //--------------------------
  390. // Quaternion
  391. //--------------------------
  392. D3DVBINLINE float D3DVBCALL VB_D3DXQuaternionLength
  393. ( const D3DXQUATERNION *pQ )
  394. {
  395. #ifdef D3DX_DEBUG
  396. if(!pQ)
  397. return 0.0f;
  398. #endif
  399. #ifdef __cplusplus
  400. return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
  401. #else
  402. return (float) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w);
  403. #endif
  404. }
  405. D3DVBINLINE float D3DVBCALL VB_D3DXQuaternionLengthSq
  406. ( const D3DXQUATERNION *pQ )
  407. {
  408. #ifdef D3DX_DEBUG
  409. if(!pQ)
  410. return 0.0f;
  411. #endif
  412. return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w;
  413. }
  414. D3DVBINLINE float D3DVBCALL VB_D3DXQuaternionDot
  415. ( const D3DXQUATERNION *pQ1, const D3DXQUATERNION *pQ2 )
  416. {
  417. #ifdef D3DX_DEBUG
  418. if(!pQ1 || !pQ2)
  419. return 0.0f;
  420. #endif
  421. return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w;
  422. }
  423. D3DVBINLINE D3DXQUATERNION* D3DVBCALL VB_D3DXQuaternionIdentity
  424. ( D3DXQUATERNION *pOut )
  425. {
  426. #ifdef D3DX_DEBUG
  427. if(!pOut)
  428. return NULL;
  429. #endif
  430. pOut->x = pOut->y = pOut->z = 0.0f;
  431. pOut->w = 1.0f;
  432. return pOut;
  433. }
  434. D3DVBINLINE BOOL D3DVBCALL VB_D3DXQuaternionIsIdentity
  435. ( const D3DXQUATERNION *pQ )
  436. {
  437. #ifdef D3DX_DEBUG
  438. if(!pQ)
  439. return FALSE;
  440. #endif
  441. return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f;
  442. }
  443. D3DVBINLINE D3DXQUATERNION* D3DVBCALL VB_D3DXQuaternionConjugate
  444. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ )
  445. {
  446. #ifdef D3DX_DEBUG
  447. if(!pOut || !pQ)
  448. return NULL;
  449. #endif
  450. pOut->x = -pQ->x;
  451. pOut->y = -pQ->y;
  452. pOut->z = -pQ->z;
  453. pOut->w = pQ->w;
  454. return pOut;
  455. }
  456. //--------------------------
  457. // Plane
  458. //--------------------------
  459. D3DVBINLINE float D3DVBCALL VB_D3DXPlaneDot
  460. ( const D3DXPLANE *pP, const D3DXVECTOR4 *pV)
  461. {
  462. #ifdef D3DX_DEBUG
  463. if(!pP || !pV)
  464. return 0.0f;
  465. #endif
  466. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w;
  467. }
  468. D3DVBINLINE float D3DVBCALL VB_D3DXPlaneDotCoord
  469. ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV)
  470. {
  471. #ifdef D3DX_DEBUG
  472. if(!pP || !pV)
  473. return 0.0f;
  474. #endif
  475. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
  476. }
  477. D3DVBINLINE float D3DVBCALL VB_D3DXPlaneDotNormal
  478. ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV)
  479. {
  480. #ifdef D3DX_DEBUG
  481. if(!pP || !pV)
  482. return 0.0f;
  483. #endif
  484. return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z;
  485. }
  486. //--------------------------
  487. // Color
  488. //--------------------------
  489. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorNegative
  490. (D3DXCOLOR *pOut, const D3DXCOLOR *pC)
  491. {
  492. #ifdef D3DX_DEBUG
  493. if(!pOut || !pC)
  494. return NULL;
  495. #endif
  496. pOut->r = 1.0f - pC->r;
  497. pOut->g = 1.0f - pC->g;
  498. pOut->b = 1.0f - pC->b;
  499. pOut->a = pC->a;
  500. return pOut;
  501. }
  502. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorAdd
  503. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
  504. {
  505. #ifdef D3DX_DEBUG
  506. if(!pOut || !pC1 || !pC2)
  507. return NULL;
  508. #endif
  509. pOut->r = pC1->r + pC2->r;
  510. pOut->g = pC1->g + pC2->g;
  511. pOut->b = pC1->b + pC2->b;
  512. pOut->a = pC1->a + pC2->a;
  513. return pOut;
  514. }
  515. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorSubtract
  516. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
  517. {
  518. #ifdef D3DX_DEBUG
  519. if(!pOut || !pC1 || !pC2)
  520. return NULL;
  521. #endif
  522. pOut->r = pC1->r - pC2->r;
  523. pOut->g = pC1->g - pC2->g;
  524. pOut->b = pC1->b - pC2->b;
  525. pOut->a = pC1->a - pC2->a;
  526. return pOut;
  527. }
  528. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorScale
  529. (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s)
  530. {
  531. #ifdef D3DX_DEBUG
  532. if(!pOut || !pC)
  533. return NULL;
  534. #endif
  535. pOut->r = pC->r * s;
  536. pOut->g = pC->g * s;
  537. pOut->b = pC->b * s;
  538. pOut->a = pC->a * s;
  539. return pOut;
  540. }
  541. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorModulate
  542. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2)
  543. {
  544. #ifdef D3DX_DEBUG
  545. if(!pOut || !pC1 || !pC2)
  546. return NULL;
  547. #endif
  548. pOut->r = pC1->r * pC2->r;
  549. pOut->g = pC1->g * pC2->g;
  550. pOut->b = pC1->b * pC2->b;
  551. pOut->a = pC1->a * pC2->a;
  552. return pOut;
  553. }
  554. D3DVBINLINE D3DXCOLOR* D3DVBCALL VB_D3DXColorLerp
  555. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2, float s)
  556. {
  557. #ifdef D3DX_DEBUG
  558. if(!pOut || !pC1 || !pC2)
  559. return NULL;
  560. #endif
  561. pOut->r = pC1->r + s * (pC2->r - pC1->r);
  562. pOut->g = pC1->g + s * (pC2->g - pC1->g);
  563. pOut->b = pC1->b + s * (pC2->b - pC1->b);
  564. pOut->a = pC1->a + s * (pC2->a - pC1->a);
  565. return pOut;
  566. }
  567. #endif // __D3DXMATHVB_INL__