Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / ConvexDecomposition / float_math.h
1 #ifndef FLOAT_MATH_H
2
3 #define FLOAT_MATH_H
4
5 #ifdef _WIN32
6         #pragma warning(disable : 4324) // disable padding warning
7         #pragma warning(disable : 4244) // disable padding warning
8         #pragma warning(disable : 4267) //  possible loss of data
9         #pragma warning(disable:4530) // Disable the exception disable but used in MSCV Stl warning.
10         #pragma warning(disable:4996) //Turn off warnings about deprecated C routines
11         #pragma warning(disable:4786) // Disable the "debug name too long" warning
12 #endif
13
14 /*----------------------------------------------------------------------
15                 Copyright (c) 2004 Open Dynamics Framework Group
16                                         www.physicstools.org
17                 All rights reserved.
18
19                 Redistribution and use in source and binary forms, with or without modification, are permitted provided
20                 that the following conditions are met:
21
22                 Redistributions of source code must retain the above copyright notice, this list of conditions
23                 and the following disclaimer.
24
25                 Redistributions in binary form must reproduce the above copyright notice,
26                 this list of conditions and the following disclaimer in the documentation
27                 and/or other materials provided with the distribution.
28
29                 Neither the name of the Open Dynamics Framework Group nor the names of its contributors may
30                 be used to endorse or promote products derived from this software without specific prior written permission.
31
32                 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
33                 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34                 DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35                 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36                 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
37                 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38                 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 -----------------------------------------------------------------------*/
40
41 // http://codesuppository.blogspot.com
42 //
43 // mailto: jratcliff@infiniplex.net
44 //
45 // http://www.amillionpixels.us
46 //
47
48
49 // a set of routines that last you do common 3d math
50 // operations without any vector, matrix, or quaternion
51 // classes or templates.
52 //
53 // a vector (or point) is a 'float *' to 3 floating point numbers.
54 // a matrix is a 'float *' to an array of 16 floating point numbers representing a 4x4 transformation matrix compatible with D3D or OGL
55 // a quaternion is a 'float *' to 4 floats representing a quaternion x,y,z,w
56
57 const float FM_PI = 3.141592654f;
58 const float FM_DEG_TO_RAD = ((2.0f * FM_PI) / 360.0f);
59 const float FM_RAD_TO_DEG = (360.0f / (2.0f * FM_PI));
60
61 void  fm_identity(float *matrix); // set 4x4 matrix to identity.
62 void  fm_inverseRT(const float *matrix,const float *pos,float *t); // inverse rotate translate the point.
63 void  fm_eulerMatrix(float ax,float ay,float az,float *matrix); // convert euler (in radians) to a dest 4x4 matrix (translation set to zero)
64 void  fm_getAABB(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax);
65 void  fm_eulerToQuat(float roll,float pitch,float yaw,float *quat); // convert euler angles to quaternion.
66 void  fm_quatToMatrix(const float *quat,float *matrix); // convert quaterinion rotation to matrix, translation set to zero.
67 void  fm_quatRotate(const float *quat,const float *v,float *r); // rotate a vector directly by a quaternion.
68 void  fm_getTranslation(const float *matrix,float *t);
69 void  fm_matrixToQuat(const float *matrix,float *quat); // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w
70 float fm_sphereVolume(float radius); // return's the volume of a sphere of this radius (4/3 PI * R cubed )
71
72 #endif