/////////////////////////////////////////////////////////////////////////////// // // ## ###### // ###### ### Based on: // ## ############### // ########## # # # Shark 3D Engine (www.shark3d.com) // ######## // ######### # # # Copyright (c) 1996-2001 Spinor GmbH. // ## ########## // ## // /////////////////////////////////////////////////////////////////////////////// // // G A M E.O.N.E - LOW LEVEL LIB V1.0 // Copyright (C) 2001 LEVEL ONE ENTERTAINMENT, // Licensed under the terms of LGPL. //:--------------------------------------------------------------------------- //:Description // // LOW LEVEL 3D MATH HEADERFILE // //:--------------------------------------------------------------------------- #ifndef _LL3D_MATH_H #define _LL3D_MATH_H namespace ll3d { #include #include #ifndef PI #define PI 3.14159265358979323846f #endif #ifndef PI2 #define PI2 (PI*2) #endif #ifndef PI180 #define PI180 180.0f / (float)PI #endif #ifndef RADIANS #define RADIANS (float)(PI/180.0f) #endif #ifndef GRAVITY #define GRAVITY 9.81f #endif /* * Radians Degree Functions */ inline float checkRadians( float radians ) { if( radians < 0 ) { if( radians < -PI2 ) { radians = (float)fmod( radians, PI2); } radians += PI2; } else if( radians >= PI2 ) radians = (float)fmod(radians,PI2); return radians; } /* * Grad im Bereich 0 - 360 halten * return radians 0-2*PI */ inline float checkDegree( float degree ) { if( degree < 0 ) { if( degree < - 360 ) { degree = (float)fmod(degree,360); } degree += 360; } else if( degree >= 360 ) degree = (float)fmod(degree,360); return degree; } /* * Liefert Radians */ inline float getRadians( float degree ) { return checkDegree(degree) * RADIANS; } /* * Liefert Radians */ inline float getDegree( float radians ) { return checkRadians(radians) * PI180; } /* * Int/float/double Util Functions * */ int IntFloor(double x); int IntFloor(float x); int IntCeil(double x); int IntCeil(float x); int IntNearest(double x); int IntNearest(float x); bool IsFinite(double x); bool IsFinite(float x); double Abs(double x); float Abs(float x); int Abs(int x); double Sign(double x); float Sign(float x); double Round(double x); float Round(float x); double Floor(double x); float Floor(float x); double Ceil(double x); float Ceil(float x); double Mod(double x, double y); float Mod(float x, float y); inline int IntFloor(double x) { return int(floor(x)); } inline int IntFloor(float x) { return int(floor(x)); } inline int IntCeil(double x) { return int(ceil(x)); } inline int IntCeil(float x) { return int(ceil(x)); } inline int IntNearest(double x) { return int(floor(x + 0.5)); } inline int IntNearest(float x) { return int(floor(x + 0.5)); } inline bool IsFinite(double x) { return __finite(x) != 0; } inline bool IsFinite(float x) { return __finite(x) != 0; } inline double Abs(double x) { return fabs(x); } inline float Abs(float x) { return float(fabs(x)); } inline int Abs(int x) { return (x < 0 ) ? - x : x; } inline double Sign(double x) { return (x < 0) ? -1.0 : (x > 0) ? 1.0 : 0.0; } inline float Sign(float x) { return (x < 0) ? -1.0f : (x > 0) ? 1.0f : 0.0f; } inline double Round(double x) { return floor(x+0.5); } inline float Round(float x) { return float(floor(x+0.5f)); } inline double Floor(double x) { return floor(x); } inline float Floor(float x) { return float(floor(x)); } inline double Ceil(double x) { return ceil(x); } inline float Ceil(float x) { return float(ceil(x)); } inline double Mod(double x, double y) { double r = fmod(x, y); if(r < 0) r += fabs(y); return r; } inline float Mod(float x, float y) { double r = fmod(x, y); if(r < 0) r += fabs(y); return float(r); } /* * Min Max */ template inline T Min(T x, T y) { return x < y ? x : y; } template inline T Max(T x, T y) { return x > y ? x : y; } template inline T Min(T x, T y, T z) { return Min(x, Min(y, z));} template inline T Max(T x, T y, T z) { return Max(x, Max(y, z));} /* * Math functions * -------------- */ /* * double Acos(double x); * float Acos(float x); */ inline double Acos(double x) { return acos(x); } inline float Acos(float x) { return float(acos(x)); } /* * double Asin(double x); * float Asin(float x); */ inline double Asin(double x) { return asin(x); } inline float Asin(float x) { return float(asin(x)); } /* * double Atan(double x); * float Atan(float x); */ inline double Atan(double x) { return atan(x); } inline float Atan(float x) { return float(atan(x)); } /* * double Atan2(double x, double y); * float Atan2(float x, float y); */ inline double Atan2(double x, double y) { return atan2(x, y); } inline float Atan2(float x, float y) { return float(atan2(x, y)); } /* * double Cos(double x); * float Cos(float x); */ inline double Cos(double x) { return cos(x); } inline float Cos(float x) { return float(cos(x)); } /* * double Exp(double x); * float Exp(float x); */ inline double Exp(double x) { return exp(x); } inline float Exp(float x) { return float(exp(x));} /* * double Sin(double x); * float Sin(float x); */ inline double Sin(double x) { return sin(x); } inline float Sin(float x) { return float(sin(x)); } /* * double Sqrt(double x); * float Sqrt(float x); */ inline double Sqrt(double x) { return sqrt(x); } inline float Sqrt(float x) { return float(sqrt(x)); } /* * double Log(double x); * float Log(float x); */ inline double Log(double x) { return log(x); } inline float Log(float x) { return float(log(x)); } /* * double Tan(double x); * float Tan(float x); */ inline double Tan(double x) { return tan(x); } inline float Tan(float x) { return float(tan(x)); } }//namespace ll3d #endif //_LL3D_MATH_H