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