Source code of Windows XP (NT5)
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.

81 lines
3.5 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: D3DMath.h
  3. //
  4. // Desc: Math functions and shortcuts for Direct3D programming.
  5. //
  6. // Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DMATH_H
  9. #define D3DMATH_H
  10. #include <ddraw.h>
  11. #include <d3d.h>
  12. //-----------------------------------------------------------------------------
  13. // Useful Math constants
  14. //-----------------------------------------------------------------------------
  15. const FLOAT g_PI = 3.14159265358979323846f; // Pi
  16. const FLOAT g_2_PI = 6.28318530717958623200f; // 2 * Pi
  17. const FLOAT g_PI_DIV_2 = 1.57079632679489655800f; // Pi / 2
  18. const FLOAT g_PI_DIV_4 = 0.78539816339744827900f; // Pi / 4
  19. const FLOAT g_INV_PI = 0.31830988618379069122f; // 1 / Pi
  20. const FLOAT g_DEGTORAD = 0.01745329251994329547f; // Degrees to Radians
  21. const FLOAT g_RADTODEG = 57.29577951308232286465f; // Radians to Degrees
  22. const FLOAT g_HUGE = 1.0e+38f; // Huge number for FLOAT
  23. const FLOAT g_EPSILON = 1.0e-5f; // Tolerance for FLOATs
  24. //-----------------------------------------------------------------------------
  25. // Fuzzy compares (within tolerance)
  26. //-----------------------------------------------------------------------------
  27. inline BOOL D3DMath_IsZero(FLOAT a, FLOAT fTol = g_EPSILON)
  28. { return (a <= 0.0f) ? (a >= -fTol) : (a <= fTol); }
  29. //-----------------------------------------------------------------------------
  30. // Matrix functions
  31. //-----------------------------------------------------------------------------
  32. VOID D3DMath_MatrixMultiply(D3DMATRIX& q, D3DMATRIX& a, D3DMATRIX& b);
  33. HRESULT D3DMath_MatrixInvert(D3DMATRIX& q, D3DMATRIX& a);
  34. //-----------------------------------------------------------------------------
  35. // Vector functions
  36. //-----------------------------------------------------------------------------
  37. HRESULT D3DMath_VectorMatrixMultiply(D3DVECTOR& vDest, D3DVECTOR& vSrc,
  38. D3DMATRIX& mat);
  39. HRESULT D3DMath_VertexMatrixMultiply(D3DVERTEX& vDest, D3DVERTEX& vSrc,
  40. D3DMATRIX& mat);
  41. //-----------------------------------------------------------------------------
  42. // Quaternion functions
  43. //-----------------------------------------------------------------------------
  44. VOID D3DMath_QuaternionFromRotation(FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
  45. D3DVECTOR& v, FLOAT fTheta);
  46. VOID D3DMath_RotationFromQuaternion(D3DVECTOR& v, FLOAT& fTheta,
  47. FLOAT x, FLOAT y, FLOAT z, FLOAT w);
  48. VOID D3DMath_QuaternionFromAngles(FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
  49. FLOAT fYaw, FLOAT fPitch, FLOAT fRoll);
  50. VOID D3DMath_MatrixFromQuaternion(D3DMATRIX& mat, FLOAT x, FLOAT y, FLOAT z,
  51. FLOAT w);
  52. VOID D3DMath_QuaternionFromMatrix(FLOAT &x, FLOAT &y, FLOAT &z, FLOAT &w,
  53. D3DMATRIX& mat);
  54. VOID D3DMath_QuaternionMultiply(FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
  55. FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
  56. FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw);
  57. VOID D3DMath_QuaternionSlerp(FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
  58. FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
  59. FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw,
  60. FLOAT fAlpha);
  61. #endif // D3DMATH_H