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

Ogre::Math Class Reference

Class to provide access to common mathematical functions. More...

#include <OgreMath.h>

Inheritance diagram for Ogre::Math:

Ogre::Singleton< Math > List of all members.

Public Types

enum  AngleUnit { AU_DEGREE, AU_RADIAN }
 The angular units used by the API. More...


Public Methods

 Math (unsigned int trigTableSize=4096)
 Default constructor. More...

 ~Math ()
 Default destructor. More...


Static Public Methods

int IAbs (int iValue)
int ICeil (float fValue)
int IFloor (float fValue)
int ISign (int iValue)
Real Abs (Real fValue)
Real ACos (Real fValue)
Real ASin (Real fValue)
Real ATan (Real fValue)
Real ATan2 (Real fY, Real fX)
Real Ceil (Real fValue)
Real Cos (Real fValue, bool useTables=false)
 Cosine function. More...

Real Exp (Real fValue)
Real Floor (Real fValue)
Real Log (Real fValue)
Real Pow (Real kBase, Real kExponent)
Real Sign (Real fValue)
Real Sin (Real fValue, bool useTables=false)
 Sine function. More...

Real Sqr (Real fValue)
Real Sqrt (Real fValue)
Real InvSqrt (Real fValue)
 Inverse square root i.e. More...

Real UnitRandom ()
Real RangeRandom (Real fLow, Real fHigh)
Real SymmetricRandom ()
Real Tan (Real fValue, bool useTables=false)
 Tangent function. More...

Real DegreesToRadians (Real degrees)
Real RadiansToDegrees (Real radians)
void setAngleUnit (AngleUnit unit)
 Sets the native angle units (radians or degrees) expected by and returned by the Ogre API. More...

AngleUnit getAngleUnit (void)
 Get the unit being used for angles. More...

Real AngleUnitsToRadians (Real units)
 Convert from the units the engine is currently using to radians. More...

Real RadiansToAngleUnits (Real radians)
 Convert from radians to the units the engine is currently using . More...

bool pointInTri2D (Real px, Real pz, Real ax, Real az, Real bx, Real bz, Real cx, Real cz)
 Checks wether a given point is inside a triangle, in a 2-dimensional (Cartesian) space. More...

bool RealEqual (Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
 Compare 2 reals, using tolerance for inaccuracies. More...

Math & getSingleton (void)
 Override standard Singleton retrieval. More...

Math * getSingletonPtr (void)

Static Public Attributes

const Real POS_INFINITY = std::numeric_limits<Real>::infinity()
const Real NEG_INFINITY = -std::numeric_limits<Real>::infinity()
const Real PI = Real( 4.0 * atan( 1.0 ) )
const Real TWO_PI = Real( 2.0 * PI )
const Real HALF_PI = Real( 0.5 * PI )

Protected Methods

void buildTrigTables ()
 Private function to build trig tables. More...


Static Protected Attributes

AngleUnit msAngleUnit
int mTrigTableSize
 Size of the trig tables as determined by constructor. More...

Real mTrigTableFactor
 Radian -> index factor value ( mTrigTableSize / 2 * PI ). More...

RealmSinTable = NULL
RealmTanTable = NULL
Math * ms_Singleton = 0

Detailed Description

Class to provide access to common mathematical functions.

Remarks:
Most of the maths functions are aliased versions of the C runtime library functions. They are aliased here to provide future optimisation opportunities, either from faster RTLs or custom math approximations.
Note:

This is based on MgcMath.h from Wild Magic.


Member Enumeration Documentation

enum Ogre::Math::AngleUnit
 

The angular units used by the API.

Remarks:
By default, OGRE uses degrees in all it's external APIs.
Enumeration values:
AU_DEGREE 
AU_RADIAN 


Constructor & Destructor Documentation

Ogre::Math::Math unsigned int    trigTableSize = 4096
 

Default constructor.

Parameters:
trigTableSize  Optional parameter to set the size of the tables used to implement Sin, Cos, Tan

Ogre::Math::~Math  
 

Default destructor.


Member Function Documentation

Real Ogre::Math::Abs Real    fValue [static]
 

Real Ogre::Math::ACos Real    fValue [static]
 

Real Ogre::Math::AngleUnitsToRadians Real    units [static]
 

Convert from the units the engine is currently using to radians.

Real Ogre::Math::ASin Real    fValue [static]
 

Real Ogre::Math::ATan Real    fValue [static]
 

Real Ogre::Math::ATan2 Real    fY,
Real    fX
[static]
 

void Ogre::Math::buildTrigTables   [protected]
 

Private function to build trig tables.

Real Ogre::Math::Ceil Real    fValue [static]
 

Real Ogre::Math::Cos Real    fValue,
bool    useTables = false
[static]
 

Cosine function.

Parameters:
fValue  Angle in radians
useTables  If true, uses lookup tables rather than calculation - faster but less accurate.

Real Ogre::Math::DegreesToRadians Real    degrees [static]
 

Real Ogre::Math::Exp Real    fValue [static]
 

Real Ogre::Math::Floor Real    fValue [static]
 

Math::AngleUnit Ogre::Math::getAngleUnit void    [static]
 

Get the unit being used for angles.

Math & Ogre::Math::getSingleton void    [static]
 

Override standard Singleton retrieval.

Remarks:
Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.

This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< Math >.

Math* Ogre::Singleton< Math >::getSingletonPtr void    [inline, static, inherited]
 

int Ogre::Math::IAbs int    iValue [static]
 

int Ogre::Math::ICeil float    fValue [static]
 

int Ogre::Math::IFloor float    fValue [static]
 

Real Ogre::Math::InvSqrt Real    fValue [static]
 

Inverse square root i.e.

1 / Sqrt(x), good for vector normalisation.

int Ogre::Math::ISign int    iValue [static]
 

Real Ogre::Math::Log Real    fValue [static]
 

bool Ogre::Math::pointInTri2D Real    px,
Real    pz,
Real    ax,
Real    az,
Real    bx,
Real    bz,
Real    cx,
Real    cz
[static]
 

Checks wether a given point is inside a triangle, in a 2-dimensional (Cartesian) space.

Remarks:
The vertices of the triangle must be given in either trigonometrical (anticlockwise) or inverse trigonometrical (clockwise) order.
Parameters:
px  The X-coordinate of the point.
py  The Y-coordinate of the point.
ax  The X-coordinate of the triangle's first vertex.
ay  The Y-coordinate of the triangle's first vertex.
bx  The X-coordinate of the triangle's second vertex.
by  The Y-coordinate of the triangle's second vertex.
cx  The X-coordinate of the triangle's third vertex.
cy  The Y-coordinate of the triangle's third vertex.
Returns:
If the point resides in the triangle, true is returned.

If the point is outside the triangle, false is returned.

Real Ogre::Math::Pow Real    kBase,
Real    kExponent
[static]
 

Real Ogre::Math::RadiansToAngleUnits Real    radians [static]
 

Convert from radians to the units the engine is currently using .

Real Ogre::Math::RadiansToDegrees Real    radians [static]
 

Real Ogre::Math::RangeRandom Real    fLow,
Real    fHigh
[static]
 

bool Ogre::Math::RealEqual Real    a,
Real    b,
Real    tolerance = std::numeric_limits< Real >::epsilon()
[static]
 

Compare 2 reals, using tolerance for inaccuracies.

void Ogre::Math::setAngleUnit AngleUnit    unit [static]
 

Sets the native angle units (radians or degrees) expected by and returned by the Ogre API.

Remarks:
By default, OGRE's main API uses degrees (this Math class uses radians because that is the underlying unit used by the library routines. This may be changed by the user of the engine so that every instance of degrees actually accepts radians instead.

You can set this directly after creating a new Root, and also before/after resource creation, depending on whether you want the change to affect resource files.

Warning: don't set this during the middle of an app run - some classes store degrees internally as degrees, and perform the conversion for internal usage. Changing the AngleUnits between set and get will result in screwed up values. This affects some file loading too - notably particle system angle attributes. These values must also be changed in the particle files to use radians.

Real Ogre::Math::Sign Real    fValue [static]
 

Real Ogre::Math::Sin Real    fValue,
bool    useTables = false
[static]
 

Sine function.

Parameters:
fValue  Angle in radians
useTables  If true, uses lookup tables rather than calculation - faster but less accurate.

Real Ogre::Math::Sqr Real    fValue [static]
 

Real Ogre::Math::Sqrt Real    fValue [static]
 

Real Ogre::Math::SymmetricRandom   [static]
 

Real Ogre::Math::Tan Real    fValue,
bool    useTables = false
[static]
 

Tangent function.

Parameters:
fValue  Angle in radians
useTables  If true, uses lookup tables rather than calculation - faster but less accurate.

Real Ogre::Math::UnitRandom   [static]
 


Member Data Documentation

const Real Ogre::Math::HALF_PI = Real( 0.5 * PI ) [static]
 

Math * Ogre::Singleton< Math >::ms_Singleton = 0 [static, protected, inherited]
 

Math::AngleUnit Ogre::Math::msAngleUnit [static, protected]
 

Real * Ogre::Math::mSinTable = NULL [static, protected]
 

Real * Ogre::Math::mTanTable = NULL [static, protected]
 

Real Ogre::Math::mTrigTableFactor [static, protected]
 

Radian -> index factor value ( mTrigTableSize / 2 * PI ).

int Ogre::Math::mTrigTableSize [static, protected]
 

Size of the trig tables as determined by constructor.

const Real Ogre::Math::NEG_INFINITY = -std::numeric_limits<Real>::infinity() [static]
 

const Real Ogre::Math::PI = Real( 4.0 * atan( 1.0 ) ) [static]
 

const Real Ogre::Math::POS_INFINITY = std::numeric_limits<Real>::infinity() [static]
 

const Real Ogre::Math::TWO_PI = Real( 2.0 * PI ) [static]
 

Copyright © 2002 by The OGRE Team