Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreMath.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __Math_H__
00026 #define __Math_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 namespace Ogre
00031 {
00042     class _OgreExport Math 
00043     {
00044    public:
00049        enum AngleUnit
00050        {
00051            AU_DEGREE,
00052            AU_RADIAN
00053        };
00054 
00055     protected:
00056        // angle units used by the api
00057        static AngleUnit msAngleUnit;
00058 
00060         static int mTrigTableSize;
00061 
00063         static Real mTrigTableFactor;
00064         static Real* mSinTable;
00065         static Real* mTanTable;
00066 
00069         void buildTrigTables();
00070 
00071         static Real SinTable (Real fValue);
00072         static Real TanTable (Real fValue);
00073     public:
00079         Math(unsigned int trigTableSize = 4096);
00080 
00083         ~Math();
00084 
00085         static inline int IAbs (int iValue) { return ( iValue >= 0 ? iValue : -iValue ); }
00086         static inline int ICeil (float fValue) { return int(ceil(fValue)); }
00087         static inline int IFloor (float fValue) { return int(floor(fValue)); }
00088         static int ISign (int iValue);
00089 
00090         static inline Real Abs (Real fValue) { return Real(fabs(fValue)); }
00091         static Real ACos (Real fValue);
00092         static Real ASin (Real fValue);
00093         static inline Real ATan (Real fValue) { return Real(atan(fValue)); }
00094         static inline Real ATan2 (Real fY, Real fX) { return Real(atan2(fY,fX)); }
00095         static inline Real Ceil (Real fValue) { return Real(ceil(fValue)); }
00096 
00104         static inline Real Cos (Real fValue, bool useTables = false) {
00105             return (!useTables) ? Real(cos(fValue)) : SinTable(fValue + HALF_PI);
00106         }
00107 
00108         static inline Real Exp (Real fValue) { return Real(exp(fValue)); }
00109 
00110         static inline Real Floor (Real fValue) { return Real(floor(fValue)); }
00111 
00112         static inline Real Log (Real fValue) { return Real(log(fValue)); }
00113 
00114         static inline Real Pow (Real fBase, Real fExponent) { return Real(pow(fBase,fExponent)); }
00115 
00116         static Real Sign (Real fValue);
00117 
00125         static inline Real Sin (Real fValue, bool useTables = false) {
00126             return (!useTables) ? Real(sin(fValue)) : SinTable(fValue);
00127         }
00128 
00129         static inline Real Sqr (Real fValue) { return fValue*fValue; }
00130 
00131         static inline Real Sqrt (Real fValue) { return Real(sqrt(fValue)); }
00132 
00136         static Real InvSqrt(Real fValue);
00137 
00138         static Real UnitRandom ();  // in [0,1]
00139 
00140         static Real RangeRandom (Real fLow, Real fHigh);  // in [fLow,fHigh]
00141 
00142         static Real SymmetricRandom ();  // in [-1,1]
00143 
00151         static inline Real Tan (Real fValue, bool useTables = false) {
00152             return (!useTables) ? Real(tan(fValue)) : TanTable(fValue);
00153         }
00154 
00155         static inline Real DegreesToRadians(Real degrees) { return degrees * fDeg2Rad; }
00156         static inline Real RadiansToDegrees(Real radians) { return radians * fRad2Deg; }
00157 
00173        static void setAngleUnit(AngleUnit unit);
00175        static AngleUnit getAngleUnit(void);
00176 
00178        static Real AngleUnitsToRadians(Real units);
00180        static Real RadiansToAngleUnits(Real radians);
00181 
00211         static bool pointInTri2D( Real px, Real pz, Real ax, Real az, Real bx, Real bz, Real cx, Real cz );
00212 
00214         static std::pair<bool, Real> intersects(const Ray& ray, const Plane& plane);
00215 
00217         static std::pair<bool, Real> intersects(const Ray& ray, const Sphere& sphere);
00218         
00220         static std::pair<bool, Real> intersects(const Ray& ray, const AxisAlignedBox& sphere);
00221 
00223         static bool intersects(const Sphere& sphere, const AxisAlignedBox& box);
00224 
00226         static bool intersects(const Plane& plane, const AxisAlignedBox& box);
00227 
00231         static bool intersects(const Sphere& sphere, const Plane& plane);
00232 
00235         static bool RealEqual(Real a, Real b,
00236             Real tolerance = std::numeric_limits<Real>::epsilon());
00237 
00239         static Vector3 calculateTangentSpaceVector(
00240             const Vector3& position1, const Vector3& position2, const Vector3& position3,
00241             Real u1, Real v1, Real u2, Real v2, Real u3, Real v3);
00242 
00244         static Matrix4 buildReflectionMatrix(const Plane& p);
00245 
00246         static const Real POS_INFINITY;
00247         static const Real NEG_INFINITY;
00248         static const Real PI;
00249         static const Real TWO_PI;
00250         static const Real HALF_PI;
00251         static const Real fDeg2Rad;
00252         static const Real fRad2Deg;
00253 
00254     };
00255 }
00256 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:16 2004