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.

654 lines
22 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: d3dxmath.h
  6. // Content: D3DX math types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #ifndef __D3DXMATHVB_H__
  10. #define __D3DXMATHVB_H__
  11. //#include <d3d.h>
  12. #include <math.h>
  13. #include <limits.h>
  14. //#include "d3dxerr.h"
  15. #ifndef D3DXINLINE
  16. #ifdef __cplusplus
  17. #define D3DXINLINE inline
  18. #else
  19. #define D3DXINLINE _inline
  20. #endif
  21. #endif
  22. #pragma warning(disable:4201) // anonymous unions warning
  23. //===========================================================================
  24. //
  25. // General purpose utilities
  26. //
  27. //===========================================================================
  28. //#define D3DX_PI ((float) 3.141592654f)
  29. //#define D3DX_1BYPI ((float) 0.318309886f)
  30. #define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
  31. #define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
  32. //===========================================================================
  33. //
  34. // D3DX math functions:
  35. //
  36. // NOTE:
  37. // * All these functions can take the same object as in and out parameters.
  38. //
  39. // * Out parameters are typically also returned as return values, so that
  40. // the output of one function may be used as a parameter to another.
  41. //
  42. //===========================================================================
  43. //--------------------------
  44. // 2D Vector
  45. //--------------------------
  46. // inline
  47. float D3DVBCALL VB_D3DXVec2Length
  48. ( const D3DXVECTOR2 *pV );
  49. float D3DVBCALL VB_D3DXVec2LengthSq
  50. ( const D3DXVECTOR2 *pV );
  51. float D3DVBCALL VB_D3DXVec2Dot
  52. ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  53. // Z component of ((x1,y1,0) cross (x2,y2,0))
  54. float D3DVBCALL VB_D3DXVec2CCW
  55. ( const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  56. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Add
  57. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  58. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Subtract
  59. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  60. // Minimize each component. x = min(x1, x2), y = min(y1, y2)
  61. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Minimize
  62. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  63. // Maximize each component. x = max(x1, x2), y = max(y1, y2)
  64. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Maximize
  65. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2 );
  66. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Scale
  67. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, float s );
  68. // Linear interpolation. V1 + s(V2-V1)
  69. D3DXVECTOR2* D3DVBCALL VB_D3DXVec2Lerp
  70. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
  71. float s );
  72. // non-inline
  73. #ifdef __cplusplus
  74. extern "C" {
  75. #endif
  76. D3DXVECTOR2* WINAPI VB_D3DXVec2Normalize
  77. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV );
  78. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  79. // and position V2, tangent T2 (when s == 1).
  80. D3DXVECTOR2* WINAPI VB_D3DXVec2Hermite
  81. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pT1,
  82. const D3DXVECTOR2 *pV2, const D3DXVECTOR2 *pT2, float s );
  83. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  84. D3DXVECTOR2* WINAPI VB_D3DXVec2CatmullRom
  85. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV0, const D3DXVECTOR2 *pV1,
  86. const D3DXVECTOR2 *pV2, const D3DXVECTOR2 *pV3, float s );
  87. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  88. D3DXVECTOR2* WINAPI VB_D3DXVec2BaryCentric
  89. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV1, const D3DXVECTOR2 *pV2,
  90. D3DXVECTOR2 *pV3, float f, float g);
  91. // Transform (x, y, 0, 1) by matrix.
  92. D3DXVECTOR4* WINAPI VB_D3DXVec2Transform
  93. ( D3DXVECTOR4 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  94. // Transform (x, y, 0, 1) by matrix, project result back into w=1.
  95. D3DXVECTOR2* WINAPI VB_D3DXVec2TransformCoord
  96. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  97. // Transform (x, y, 0, 0) by matrix.
  98. D3DXVECTOR2* WINAPI VB_D3DXVec2TransformNormal
  99. ( D3DXVECTOR2 *pOut, const D3DXVECTOR2 *pV, const D3DXMATRIX *pM );
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. //--------------------------
  104. // 3D Vector
  105. //--------------------------
  106. // inline
  107. float D3DVBCALL VB_D3DXVec3Length
  108. ( const D3DXVECTOR3 *pV );
  109. float D3DVBCALL VB_D3DXVec3LengthSq
  110. ( const D3DXVECTOR3 *pV );
  111. float D3DVBCALL VB_D3DXVec3Dot
  112. ( const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  113. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Cross
  114. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  115. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Add
  116. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  117. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Subtract
  118. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  119. // Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
  120. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Minimize
  121. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  122. // Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
  123. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Maximize
  124. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2 );
  125. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Scale
  126. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, float s);
  127. // Linear interpolation. V1 + s(V2-V1)
  128. D3DXVECTOR3* D3DVBCALL VB_D3DXVec3Lerp
  129. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  130. float s );
  131. // non-inline
  132. #ifdef __cplusplus
  133. extern "C" {
  134. #endif
  135. D3DXVECTOR3* WINAPI VB_D3DXVec3Normalize
  136. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV );
  137. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  138. // and position V2, tangent T2 (when s == 1).
  139. D3DXVECTOR3* WINAPI VB_D3DXVec3Hermite
  140. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pT1,
  141. const D3DXVECTOR3 *pV2, const D3DXVECTOR3 *pT2, float s );
  142. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  143. D3DXVECTOR3* WINAPI VB_D3DXVec3CatmullRom
  144. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV0, const D3DXVECTOR3 *pV1,
  145. const D3DXVECTOR3 *pV2, const D3DXVECTOR3 *pV3, float s );
  146. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  147. D3DXVECTOR3* WINAPI VB_D3DXVec3BaryCentric
  148. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  149. const D3DXVECTOR3 *pV3, float f, float g);
  150. // Transform (x, y, z, 1) by matrix.
  151. D3DXVECTOR4* WINAPI VB_D3DXVec3Transform
  152. ( D3DXVECTOR4 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  153. // Transform (x, y, z, 1) by matrix, project result back into w=1.
  154. D3DXVECTOR3* WINAPI VB_D3DXVec3TransformCoord
  155. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  156. // Transform (x, y, z, 0) by matrix.
  157. D3DXVECTOR3* WINAPI VB_D3DXVec3TransformNormal
  158. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DXMATRIX *pM );
  159. // Project vector from object space into screen space
  160. D3DXVECTOR3* WINAPI VB_D3DXVec3Project
  161. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DVIEWPORT8 *pViewport,
  162. const D3DXMATRIX *pProjection, const D3DXMATRIX *pView, const D3DXMATRIX *pWorld);
  163. // Project vector from screen space into object space
  164. D3DXVECTOR3* WINAPI VB_D3DXVec3Unproject
  165. ( D3DXVECTOR3 *pOut, const D3DXVECTOR3 *pV, const D3DVIEWPORT8 *pViewport,
  166. const D3DXMATRIX *pProjection, const D3DXMATRIX *pView, const D3DXMATRIX *pWorld);
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. //--------------------------
  171. // 4D Vector
  172. //--------------------------
  173. // inline
  174. float D3DVBCALL VB_D3DXVec4Length
  175. ( const D3DXVECTOR4 *pV );
  176. float D3DVBCALL VB_D3DXVec4LengthSq
  177. ( const D3DXVECTOR4 *pV );
  178. float D3DVBCALL VB_D3DXVec4Dot
  179. ( const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2 );
  180. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Add
  181. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  182. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Subtract
  183. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  184. // Minimize each component. x = min(x1, x2), y = min(y1, y2), ...
  185. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Minimize
  186. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  187. // Maximize each component. x = max(x1, x2), y = max(y1, y2), ...
  188. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Maximize
  189. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2);
  190. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Scale
  191. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, float s);
  192. // Linear interpolation. V1 + s(V2-V1)
  193. D3DXVECTOR4* D3DVBCALL VB_D3DXVec4Lerp
  194. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  195. float s );
  196. // non-inline
  197. #ifdef __cplusplus
  198. extern "C" {
  199. #endif
  200. // Cross-product in 4 dimensions.
  201. D3DXVECTOR4* WINAPI VB_D3DXVec4Cross
  202. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  203. const D3DXVECTOR4 *pV3);
  204. D3DXVECTOR4* WINAPI VB_D3DXVec4Normalize
  205. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV );
  206. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  207. // and position V2, tangent T2 (when s == 1).
  208. D3DXVECTOR4* WINAPI VB_D3DXVec4Hermite
  209. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pT1,
  210. const D3DXVECTOR4 *pV2, const D3DXVECTOR4 *pT2, float s );
  211. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  212. D3DXVECTOR4* WINAPI VB_D3DXVec4CatmullRom
  213. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV0, const D3DXVECTOR4 *pV1,
  214. const D3DXVECTOR4 *pV2, const D3DXVECTOR4 *pV3, float s );
  215. // Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
  216. D3DXVECTOR4* WINAPI VB_D3DXVec4BaryCentric
  217. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV1, const D3DXVECTOR4 *pV2,
  218. const D3DXVECTOR4 *pV3, float f, float g);
  219. // Transform vector by matrix.
  220. D3DXVECTOR4* WINAPI VB_D3DXVec4Transform
  221. ( D3DXVECTOR4 *pOut, const D3DXVECTOR4 *pV, const D3DXMATRIX *pM );
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225. //--------------------------
  226. // 4D Matrix
  227. //--------------------------
  228. // inline
  229. D3DXMATRIX* D3DVBCALL VB_D3DXMatrixIdentity
  230. ( D3DXMATRIX *pOut );
  231. BOOL D3DVBCALL VB_D3DXMatrixIsIdentity
  232. ( const D3DXMATRIX *pM );
  233. // non-inline
  234. #ifdef __cplusplus
  235. extern "C" {
  236. #endif
  237. float WINAPI D3DXMatrixfDeterminant
  238. ( const D3DXMATRIX *pM );
  239. // Matrix multiplication. The result represents the transformation M2
  240. // followed by the transformation M1. (Out = M1 * M2)
  241. D3DXMATRIX* WINAPI VB_D3DXMatrixMultiply
  242. ( D3DXMATRIX *pOut, const D3DXMATRIX *pM1, const D3DXMATRIX *pM2 );
  243. D3DXMATRIX* WINAPI VB_D3DXMatrixTranspose
  244. ( D3DXMATRIX *pOut, const D3DXMATRIX *pM );
  245. // Calculate inverse of matrix. Inversion my fail, in which case NULL will
  246. // be returned. The determinant of pM is also returned it pfDeterminant
  247. // is non-NULL.
  248. D3DXMATRIX* WINAPI VB_D3DXMatrixInverse
  249. ( D3DXMATRIX *pOut, float *pfDeterminant, const D3DXMATRIX *pM );
  250. // Build a matrix which scales by (sx, sy, sz)
  251. D3DXMATRIX* WINAPI VB_D3DXMatrixScaling
  252. ( D3DXMATRIX *pOut, float sx, float sy, float sz );
  253. // Build a matrix which translates by (x, y, z)
  254. D3DXMATRIX* WINAPI VB_D3DXMatrixTranslation
  255. ( D3DXMATRIX *pOut, float x, float y, float z );
  256. // Build a matrix which rotates around the X axis
  257. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationX
  258. ( D3DXMATRIX *pOut, float angle );
  259. // Build a matrix which rotates around the Y axis
  260. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationY
  261. ( D3DXMATRIX *pOut, float angle );
  262. // Build a matrix which rotates around the Z axis
  263. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationZ
  264. ( D3DXMATRIX *pOut, float angle );
  265. // Build a matrix which rotates around an arbitrary axis
  266. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationAxis
  267. ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pV, float angle );
  268. // Build a matrix from a quaternion
  269. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationQuaternion
  270. ( D3DXMATRIX *pOut, const D3DXQUATERNION *pQ);
  271. // Yaw around the Y axis, a pitch around the X axis,
  272. // and a roll around the Z axis.
  273. D3DXMATRIX* WINAPI VB_D3DXMatrixRotationYawPitchRoll
  274. ( D3DXMATRIX *pOut, float yaw, float pitch, float roll );
  275. // Build transformation matrix. NULL arguments are treated as identity.
  276. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  277. D3DXMATRIX* WINAPI VB_D3DXMatrixTransformation
  278. ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pScalingCenter,
  279. const D3DXQUATERNION *pScalingRotation, const D3DXVECTOR3 *pScaling,
  280. const D3DXVECTOR3 *pRotationCenter, const D3DXQUATERNION *pRotation,
  281. const D3DXVECTOR3 *pTranslation);
  282. // Build affine transformation matrix. NULL arguments are treated as identity.
  283. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  284. D3DXMATRIX* WINAPI VB_D3DXMatrixAffineTransformation
  285. ( D3DXMATRIX *pOut, float Scaling, const D3DXVECTOR3 *pRotationCenter,
  286. const D3DXQUATERNION *pRotation, const D3DXVECTOR3 *pTranslation);
  287. // Build a lookat matrix. (right-handed)
  288. D3DXMATRIX* WINAPI VB_D3DXMatrixLookAtRH
  289. ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
  290. const D3DXVECTOR3 *pUp );
  291. // Build a lookat matrix. (left-handed)
  292. D3DXMATRIX* WINAPI VB_D3DXMatrixLookAtLH
  293. ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
  294. const D3DXVECTOR3 *pUp );
  295. // Build a perspective projection matrix. (right-handed)
  296. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveRH
  297. ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  298. // Build a perspective projection matrix. (left-handed)
  299. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveLH
  300. ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  301. // Build a perspective projection matrix. (right-handed)
  302. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveFovRH
  303. ( D3DXMATRIX *pOut, float fovy, float aspect, float zn, float zf );
  304. // Build a perspective projection matrix. (left-handed)
  305. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveFovLH
  306. ( D3DXMATRIX *pOut, float fovy, float aspect, float zn, float zf );
  307. // Build a perspective projection matrix. (right-handed)
  308. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveOffCenterRH
  309. ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  310. float zf );
  311. // Build a perspective projection matrix. (left-handed)
  312. D3DXMATRIX* WINAPI VB_D3DXMatrixPerspectiveOffCenterLH
  313. ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  314. float zf );
  315. // Build an ortho projection matrix. (right-handed)
  316. D3DXMATRIX* WINAPI VB_D3DXMatrixOrthoRH
  317. ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  318. // Build an ortho projection matrix. (left-handed)
  319. D3DXMATRIX* WINAPI VB_D3DXMatrixOrthoLH
  320. ( D3DXMATRIX *pOut, float w, float h, float zn, float zf );
  321. // Build an ortho projection matrix. (right-handed)
  322. D3DXMATRIX* WINAPI VB_D3DXMatrixOrthoOffCenterRH
  323. ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  324. float zf );
  325. // Build an ortho projection matrix. (left-handed)
  326. D3DXMATRIX* WINAPI VB_D3DXMatrixOrthoOffCenterLH
  327. ( D3DXMATRIX *pOut, float l, float r, float b, float t, float zn,
  328. float zf );
  329. // Build a matrix which flattens geometry into a plane, as if casting
  330. // a shadow from a light.
  331. D3DXMATRIX* WINAPI VB_D3DXMatrixShadow
  332. ( D3DXMATRIX *pOut, const D3DXVECTOR4 *pLight,
  333. const D3DXPLANE *pPlane );
  334. // Build a matrix which reflects the coordinate system about a plane
  335. D3DXMATRIX* WINAPI VB_D3DXMatrixReflect
  336. ( D3DXMATRIX *pOut, const D3DXPLANE *pPlane );
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340. //--------------------------
  341. // Quaternion
  342. //--------------------------
  343. // inline
  344. float D3DVBCALL VB_D3DXQuaternionLength
  345. ( const D3DXQUATERNION *pQ );
  346. // Length squared, or "norm"
  347. float D3DVBCALL VB_D3DXQuaternionLengthSq
  348. ( const D3DXQUATERNION *pQ );
  349. float D3DVBCALL VB_D3DXQuaternionDot
  350. ( const D3DXQUATERNION *pQ1, const D3DXQUATERNION *pQ2 );
  351. // (0, 0, 0, 1)
  352. D3DXQUATERNION* D3DVBCALL VB_D3DXQuaternionIdentity
  353. ( D3DXQUATERNION *pOut );
  354. BOOL D3DVBCALL VB_D3DXQuaternionIsIdentity
  355. ( const D3DXQUATERNION *pQ );
  356. // (-x, -y, -z, w)
  357. D3DXQUATERNION* D3DVBCALL VB_D3DXQuaternionConjugate
  358. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  359. // non-inline
  360. #ifdef __cplusplus
  361. extern "C" {
  362. #endif
  363. // Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
  364. void WINAPI VB_D3DXQuaternionToAxisAngle
  365. ( const D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, float *pAngle );
  366. // Build a quaternion from a rotation matrix.
  367. D3DXQUATERNION* WINAPI VB_D3DXQuaternionRotationMatrix
  368. ( D3DXQUATERNION *pOut, const D3DXMATRIX *pM);
  369. // Rotation about arbitrary axis.
  370. D3DXQUATERNION* WINAPI VB_D3DXQuaternionRotationAxis
  371. ( D3DXQUATERNION *pOut, const D3DXVECTOR3 *pV, float angle );
  372. // Yaw around the Y axis, a pitch around the X axis,
  373. // and a roll around the Z axis.
  374. D3DXQUATERNION* WINAPI VB_D3DXQuaternionRotationYawPitchRoll
  375. ( D3DXQUATERNION *pOut, float yaw, float pitch, float roll );
  376. // Quaternion multiplication. The result represents the rotation Q2
  377. // followed by the rotation Q1. (Out = Q2 * Q1)
  378. D3DXQUATERNION* WINAPI VB_D3DXQuaternionMultiply
  379. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  380. const D3DXQUATERNION *pQ2 );
  381. D3DXQUATERNION* WINAPI VB_D3DXQuaternionNormalize
  382. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  383. // Conjugate and re-norm
  384. D3DXQUATERNION* WINAPI VB_D3DXQuaternionInverse
  385. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  386. // Expects unit quaternions.
  387. // if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
  388. D3DXQUATERNION* WINAPI VB_D3DXQuaternionLn
  389. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  390. // Expects pure quaternions. (w == 0) w is ignored in calculation.
  391. // if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
  392. D3DXQUATERNION* WINAPI VB_D3DXQuaternionExp
  393. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ );
  394. // Spherical linear interpolation between Q1 (s == 0) and Q2 (s == 1).
  395. // Expects unit quaternions.
  396. D3DXQUATERNION* WINAPI VB_D3DXQuaternionSlerp
  397. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  398. const D3DXQUATERNION *pQ2, float t );
  399. // Spherical quadrangle interpolation.
  400. // Slerp(Slerp(Q1, Q4, t), Slerp(Q2, Q3, t), 2t(1-t))
  401. D3DXQUATERNION* WINAPI VB_D3DXQuaternionSquad
  402. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  403. const D3DXQUATERNION *pQ2, const D3DXQUATERNION *pQ3,
  404. const D3DXQUATERNION *pQ4, float t );
  405. // Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
  406. D3DXQUATERNION* WINAPI VB_D3DXQuaternionBaryCentric
  407. ( D3DXQUATERNION *pOut, const D3DXQUATERNION *pQ1,
  408. const D3DXQUATERNION *pQ2, const D3DXQUATERNION *pQ3,
  409. float f, float g );
  410. #ifdef __cplusplus
  411. }
  412. #endif
  413. //--------------------------
  414. // Plane
  415. //--------------------------
  416. // inline
  417. // ax + by + cz + dw
  418. float D3DVBCALL VB_D3DXPlaneDot
  419. ( const D3DXPLANE *pP, const D3DXVECTOR4 *pV);
  420. // ax + by + cz + d
  421. float D3DVBCALL VB_D3DXPlaneDotCoord
  422. ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV);
  423. // ax + by + cz
  424. float D3DVBCALL VB_D3DXPlaneDotNormal
  425. ( const D3DXPLANE *pP, const D3DXVECTOR3 *pV);
  426. // non-inline
  427. #ifdef __cplusplus
  428. extern "C" {
  429. #endif
  430. // Normalize plane (so that |a,b,c| == 1)
  431. D3DXPLANE* WINAPI VB_D3DXPlaneNormalize
  432. ( D3DXPLANE *pOut, const D3DXPLANE *pP);
  433. // Find the intersection between a plane and a line. If the line is
  434. // parallel to the plane, NULL is returned.
  435. D3DXVECTOR3* WINAPI VB_D3DXPlaneIntersectLine
  436. ( D3DXVECTOR3 *pOut, const D3DXPLANE *pP, const D3DXVECTOR3 *pV1,
  437. const D3DXVECTOR3 *pV2);
  438. // Construct a plane from a point and a normal
  439. D3DXPLANE* WINAPI VB_D3DXPlaneFromPointNormal
  440. ( D3DXPLANE *pOut, const D3DXVECTOR3 *pPoint, const D3DXVECTOR3 *pNormal);
  441. // Construct a plane from 3 points
  442. D3DXPLANE* WINAPI VB_D3DXPlaneFromPoints
  443. ( D3DXPLANE *pOut, const D3DXVECTOR3 *pV1, const D3DXVECTOR3 *pV2,
  444. const D3DXVECTOR3 *pV3);
  445. // Transform a plane by a matrix. The vector (a,b,c) must be normal.
  446. // M must be an affine transform.
  447. D3DXPLANE* WINAPI VB_D3DXPlaneTransform
  448. ( D3DXPLANE *pOut, const D3DXPLANE *pP, const D3DXMATRIX *pM );
  449. #ifdef __cplusplus
  450. }
  451. #endif
  452. //--------------------------
  453. // Color
  454. //--------------------------
  455. // inline
  456. // (1-r, 1-g, 1-b, a)
  457. D3DXCOLOR* D3DVBCALL VB_D3DXColorNegative
  458. (D3DXCOLOR *pOut, const D3DXCOLOR *pC);
  459. D3DXCOLOR* D3DVBCALL VB_D3DXColorAdd
  460. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  461. D3DXCOLOR* D3DVBCALL VB_D3DXColorSubtract
  462. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  463. D3DXCOLOR* D3DVBCALL VB_D3DXColorScale
  464. (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s);
  465. // (r1*r2, g1*g2, b1*b2, a1*a2)
  466. D3DXCOLOR* D3DVBCALL VB_D3DXColorModulate
  467. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2);
  468. // Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
  469. D3DXCOLOR* D3DVBCALL VB_D3DXColorLerp
  470. (D3DXCOLOR *pOut, const D3DXCOLOR *pC1, const D3DXCOLOR *pC2, float s);
  471. // non-inline
  472. #ifdef __cplusplus
  473. extern "C" {
  474. #endif
  475. // Interpolate r,g,b between desaturated color and color.
  476. // DesaturatedColor + s(Color - DesaturatedColor)
  477. D3DXCOLOR* WINAPI VB_D3DXColorAdjustSaturation
  478. (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float s);
  479. // Interpolate r,g,b between 50% grey and color. Grey + s(Color - Grey)
  480. D3DXCOLOR* WINAPI VB_D3DXColorAdjustContrast
  481. (D3DXCOLOR *pOut, const D3DXCOLOR *pC, float c);
  482. #ifdef __cplusplus
  483. }
  484. #endif
  485. #pragma warning(default:4201)
  486. #endif // __D3DXMATHVB_H__