summaryrefslogtreecommitdiffstats
path: root/src/math/d3dmath.h
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-04-28 17:53:17 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-04-28 17:53:17 +0200
commit449cc186d5b8117d74ba22d6173497d00939f5f1 (patch)
tree39f38530dab2c9c8b33f5d8e42a81242bd48704b /src/math/d3dmath.h
parenteeb69b34d2467e51ff84b3235f94506ce6bb9283 (diff)
downloadcolobot-449cc186d5b8117d74ba22d6173497d00939f5f1.tar.gz
colobot-449cc186d5b8117d74ba22d6173497d00939f5f1.tar.bz2
colobot-449cc186d5b8117d74ba22d6173497d00939f5f1.zip
Source files split into modules
Diffstat (limited to 'src/math/d3dmath.h')
-rw-r--r--src/math/d3dmath.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/math/d3dmath.h b/src/math/d3dmath.h
new file mode 100644
index 0000000..d28707d
--- /dev/null
+++ b/src/math/d3dmath.h
@@ -0,0 +1,97 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+//-----------------------------------------------------------------------------
+// File: D3DMath.h
+//
+// Desc: Math functions and shortcuts for Direct3D programming.
+//
+// Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved
+//-----------------------------------------------------------------------------
+#ifndef D3DMATH_H
+#define D3DMATH_H
+#include <ddraw.h>
+#include <d3d.h>
+
+
+//-----------------------------------------------------------------------------
+// Useful Math constants
+//-----------------------------------------------------------------------------
+const FLOAT g_PI = 3.14159265358979323846f; // Pi
+const FLOAT g_2_PI = 6.28318530717958623200f; // 2 * Pi
+const FLOAT g_PI_DIV_2 = 1.57079632679489655800f; // Pi / 2
+const FLOAT g_PI_DIV_4 = 0.78539816339744827900f; // Pi / 4
+const FLOAT g_INV_PI = 0.31830988618379069122f; // 1 / Pi
+const FLOAT g_DEGTORAD = 0.01745329251994329547f; // Degrees to Radians
+const FLOAT g_RADTODEG = 57.29577951308232286465f; // Radians to Degrees
+const FLOAT g_HUGE = 1.0e+38f; // Huge number for FLOAT
+const FLOAT g_EPSILON = 1.0e-5f; // Tolerance for FLOATs
+
+
+
+
+//-----------------------------------------------------------------------------
+// Fuzzy compares (within tolerance)
+//-----------------------------------------------------------------------------
+inline BOOL D3DMath_IsZero( FLOAT a, FLOAT fTol = g_EPSILON )
+{ return ( a <= 0.0f ) ? ( a >= -fTol ) : ( a <= fTol ); }
+
+
+
+
+//-----------------------------------------------------------------------------
+// Matrix functions
+//-----------------------------------------------------------------------------
+VOID D3DMath_MatrixMultiply( D3DMATRIX& q, D3DMATRIX& a, D3DMATRIX& b );
+HRESULT D3DMath_MatrixInvert( D3DMATRIX& q, D3DMATRIX& a );
+
+
+
+
+//-----------------------------------------------------------------------------
+// Vector functions
+//-----------------------------------------------------------------------------
+HRESULT D3DMath_VectorMatrixMultiply( D3DVECTOR& vDest, D3DVECTOR& vSrc,
+ D3DMATRIX& mat);
+HRESULT D3DMath_VertexMatrixMultiply( D3DVERTEX& vDest, D3DVERTEX& vSrc,
+ D3DMATRIX& mat );
+
+
+
+
+//-----------------------------------------------------------------------------
+// Quaternion functions
+//-----------------------------------------------------------------------------
+VOID D3DMath_QuaternionFromRotation( FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
+ D3DVECTOR& v, FLOAT fTheta );
+VOID D3DMath_RotationFromQuaternion( D3DVECTOR& v, FLOAT& fTheta,
+ FLOAT x, FLOAT y, FLOAT z, FLOAT w );
+VOID D3DMath_QuaternionFromAngles( FLOAT& x, FLOAT& y, FLOAT& z, FLOAT& w,
+ FLOAT fYaw, FLOAT fPitch, FLOAT fRoll );
+VOID D3DMath_MatrixFromQuaternion( D3DMATRIX& mat, FLOAT x, FLOAT y, FLOAT z,
+ FLOAT w );
+VOID D3DMath_QuaternionFromMatrix( FLOAT &x, FLOAT &y, FLOAT &z, FLOAT &w,
+ D3DMATRIX& mat );
+VOID D3DMath_QuaternionMultiply( FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
+ FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
+ FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw );
+VOID D3DMath_QuaternionSlerp( FLOAT& Qx, FLOAT& Qy, FLOAT& Qz, FLOAT& Qw,
+ FLOAT Ax, FLOAT Ay, FLOAT Az, FLOAT Aw,
+ FLOAT Bx, FLOAT By, FLOAT Bz, FLOAT Bw,
+ FLOAT fAlpha );
+
+
+#endif // D3DMATH_H