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>

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.

 ~Math ()
 Default destructor.


Static Public Methods

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

Real Cos (Real fValue, bool useTables=false)
 Cosine function.

Real Exp (Real fValue)
Real Floor (Real fValue)
Real Log (Real fValue)
Real Pow (Real fBase, Real fExponent)
Real Sign (Real fValue)
Radian Sign (const Radian &rValue)
Degree Sign (const Degree &dValue)
Real Sin (const Radian &fValue, bool useTables=false)
 Sine function.

Real Sin (Real fValue, bool useTables=false)
 Sine function.

Real Sqr (Real fValue)
Real Sqrt (Real fValue)
Radian Sqrt (const Radian &fValue)
Degree Sqrt (const Degree &fValue)
Real InvSqrt (Real fValue)
 Inverse square root i.e.

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

Real Tan (Real fValue, bool useTables=false)
 Tangent function.

Real DegreesToRadians (Real degrees)
Real RadiansToDegrees (Real radians)
void setAngleUnit (AngleUnit unit)
 These functions used to set the assumed angle units (radians or degrees) expected when using the Angle type.

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

Real AngleUnitsToRadians (Real units)
 Convert from the current AngleUnit to radians.

Real RadiansToAngleUnits (Real radians)
 Convert from radians to the current AngleUnit .

Real AngleUnitsToDegrees (Real units)
 Convert from the current AngleUnit to degrees.

Real DegreesToAngleUnits (Real degrees)
 Convert from degrees to the current AngleUnit.

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.

std::pair< bool, Realintersects (const Ray &ray, const Plane &plane)
 Ray / plane intersection, returns boolean result and distance.

std::pair< bool, Realintersects (const Ray &ray, const Sphere &sphere, bool discardInside=true)
 Ray / sphere intersection, returns boolean result and distance.

std::pair< bool, Realintersects (const Ray &ray, const AxisAlignedBox &sphere)
 Ray / box intersection, returns boolean result and distance.

bool intersects (const Sphere &sphere, const AxisAlignedBox &box)
 Sphere / box intersection test.

bool intersects (const Plane &plane, const AxisAlignedBox &box)
 Plane / box intersection test.

bool intersects (const Sphere &sphere, const Plane &plane)
 Sphere / plane intersection test.

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

Vector3 calculateTangentSpaceVector (const Vector3 &position1, const Vector3 &position2, const Vector3 &position3, Real u1, Real v1, Real u2, Real v2, Real u3, Real v3)
 Calculates the tangent space vector for a given set of positions / texture coords.

Matrix4 buildReflectionMatrix (const Plane &p)
 Build a reflection matrix for the passed in plane.

Vector4 calculateFaceNormal (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal, including the w component which is the offset from the origin.

Vector3 calculateBasicFaceNormal (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal, no w-information.


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 )
const Real fDeg2Rad = PI / Real(180.0)
const Real fRad2Deg = Real(180.0) / PI

Protected Methods

void buildTrigTables ()
 Private function to build trig tables.


Static Protected Methods

Real SinTable (Real fValue)
Real TanTable (Real fValue)

Static Protected Attributes

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

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

RealmSinTable = NULL
RealmTanTable = NULL


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.

Definition at line 165 of file OgreMath.h.


Member Enumeration Documentation

enum Ogre::Math::AngleUnit
 

The angular units used by the API.

This functionality is now deprecated in favor of discreet angular unit types ( see Degree and Radian above ). The only place this functionality is actually still used is when parsing files. Search for usage of the Angle class for those instances

Enumeration values:
AU_DEGREE 
AU_RADIAN 

Definition at line 173 of file OgreMath.h.


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

Definition at line 56 of file OgreMath.cpp.

References AU_DEGREE, buildTrigTables(), msAngleUnit, mSinTable, mTanTable, mTrigTableFactor, mTrigTableSize, and Ogre::Real.

Ogre::Math::~Math  
 

Default destructor.

Definition at line 73 of file OgreMath.cpp.

References mSinTable, and mTanTable.


Member Function Documentation

Radian Ogre::Math::Abs const Radian   rValue [static]
 

Definition at line 216 of file OgreMath.h.

References Ogre::Radian::valueRadians().

Degree Ogre::Math::Abs const Degree   dValue [static]
 

Definition at line 215 of file OgreMath.h.

References Ogre::Degree::valueDegrees().

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

Definition at line 214 of file OgreMath.h.

References Ogre::Real.

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

Definition at line 123 of file OgreMath.cpp.

References PI, and Ogre::Real.

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

Convert from the current AngleUnit to degrees.

Definition at line 215 of file OgreMath.cpp.

References AU_RADIAN, fRad2Deg, msAngleUnit, and Ogre::Real.

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

Convert from the current AngleUnit to radians.

Definition at line 197 of file OgreMath.cpp.

References AU_DEGREE, fDeg2Rad, msAngleUnit, and Ogre::Real.

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

Definition at line 138 of file OgreMath.cpp.

References HALF_PI, and Ogre::Real.

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

Definition at line 219 of file OgreMath.h.

References Ogre::Real.

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

Definition at line 220 of file OgreMath.h.

References Ogre::Real.

Matrix4 Ogre::Math::buildReflectionMatrix const Plane   p [static]
 

Build a reflection matrix for the passed in plane.

Definition at line 587 of file OgreMath.cpp.

References Ogre::Plane::d, Ogre::Plane::normal, Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

void Ogre::Math::buildTrigTables   [protected]
 

Private function to build trig tables.

Definition at line 80 of file OgreMath.cpp.

References mSinTable, mTanTable, mTrigTableSize, and Ogre::Real.

Referenced by Math().

Vector3 Ogre::Math::calculateBasicFaceNormal const Vector3   v1,
const Vector3   v2,
const Vector3   v3
[static]
 

Calculate a face normal, no w-information.

Definition at line 603 of file OgreMath.cpp.

References Ogre::Vector3::normalise().

Referenced by calculateFaceNormal().

Vector4 Ogre::Math::calculateFaceNormal const Vector3   v1,
const Vector3   v2,
const Vector3   v3
[static]
 

Calculate a face normal, including the w component which is the offset from the origin.

Definition at line 596 of file OgreMath.cpp.

References calculateBasicFaceNormal(), Ogre::Vector3::dotProduct(), Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

Vector3 Ogre::Math::calculateTangentSpaceVector const Vector3   position1,
const Vector3   position2,
const Vector3   position3,
Real    u1,
Real    v1,
Real    u2,
Real    v2,
Real    u3,
Real    v3
[static]
 

Calculates the tangent space vector for a given set of positions / texture coords.

Definition at line 549 of file OgreMath.cpp.

References Ogre::Vector3::crossProduct(), Ogre::Vector3::dotProduct(), Ogre::Vector3::normalise(), and Ogre::Real.

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

Definition at line 221 of file OgreMath.h.

References Ogre::Real.

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.

Definition at line 240 of file OgreMath.h.

References Ogre::Real.

Real Ogre::Math::Cos const Radian   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.

Definition at line 230 of file OgreMath.h.

References Ogre::Real, and Ogre::Radian::valueRadians().

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

Convert from degrees to the current AngleUnit.

Definition at line 224 of file OgreMath.cpp.

References AU_RADIAN, fDeg2Rad, msAngleUnit, and Ogre::Real.

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

Definition at line 323 of file OgreMath.h.

References Ogre::Real.

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

Definition at line 244 of file OgreMath.h.

References Ogre::Real.

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

Definition at line 246 of file OgreMath.h.

References Ogre::Real.

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

Get the unit being used for angles.

Definition at line 192 of file OgreMath.cpp.

References msAngleUnit.

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

Definition at line 209 of file OgreMath.h.

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

Definition at line 210 of file OgreMath.h.

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

Definition at line 211 of file OgreMath.h.

bool Ogre::Math::intersects const Sphere   sphere,
const Plane   plane
[static]
 

Sphere / plane intersection test.

Remarks:
NB just do a plane.getDistance(sphere.getCenter()) for more detail!

Definition at line 542 of file OgreMath.cpp.

References Ogre::Vector3::dotProduct(), Ogre::Sphere::getCenter(), Ogre::Sphere::getRadius(), and Ogre::Plane::normal.

bool Ogre::Math::intersects const Plane   plane,
const AxisAlignedBox   box
[static]
 

Plane / box intersection test.

Definition at line 519 of file OgreMath.cpp.

References Ogre::AxisAlignedBox::getAllCorners(), Ogre::Plane::getSide(), and Ogre::AxisAlignedBox::isNull().

bool Ogre::Math::intersects const Sphere   sphere,
const AxisAlignedBox   box
[static]
 

Sphere / box intersection test.

Definition at line 470 of file OgreMath.cpp.

References Ogre::Sphere::getCenter(), Ogre::AxisAlignedBox::getMaximum(), Ogre::AxisAlignedBox::getMinimum(), Ogre::Sphere::getRadius(), Ogre::AxisAlignedBox::isNull(), Ogre::Real, Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

std::pair< bool, Real > Ogre::Math::intersects const Ray   ray,
const AxisAlignedBox   sphere
[static]
 

Ray / box intersection, returns boolean result and distance.

Definition at line 343 of file OgreMath.cpp.

References Ogre::Ray::getDirection(), Ogre::AxisAlignedBox::getMaximum(), Ogre::AxisAlignedBox::getMinimum(), Ogre::Ray::getOrigin(), Ogre::AxisAlignedBox::isNull(), Ogre::Real, Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

std::pair< bool, Real > Ogre::Math::intersects const Ray   ray,
const Sphere   sphere,
bool    discardInside = true
[static]
 

Ray / sphere intersection, returns boolean result and distance.

Definition at line 301 of file OgreMath.cpp.

References Ogre::Vector3::dotProduct(), Ogre::Sphere::getCenter(), Ogre::Ray::getDirection(), Ogre::Ray::getOrigin(), Ogre::Sphere::getRadius(), Ogre::Real, and Ogre::Vector3::squaredLength().

std::pair< bool, Real > Ogre::Math::intersects const Ray   ray,
const Plane   plane
[static]
 

Ray / plane intersection, returns boolean result and distance.

Definition at line 283 of file OgreMath.cpp.

References Ogre::Plane::d, Ogre::Vector3::dotProduct(), Ogre::Ray::getDirection(), Ogre::Ray::getOrigin(), Ogre::Plane::normal, and Ogre::Real.

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

Inverse square root i.e.

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

Definition at line 164 of file OgreMath.cpp.

References Ogre::Real.

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

Definition at line 118 of file OgreMath.cpp.

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

Definition at line 248 of file OgreMath.h.

References Ogre::Real.

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.

Definition at line 233 of file OgreMath.cpp.

References Ogre::Real.

Real Ogre::Math::Pow Real    fBase,
Real    fExponent
[static]
 

Definition at line 250 of file OgreMath.h.

References Ogre::Real.

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

Convert from radians to the current AngleUnit .

Definition at line 206 of file OgreMath.cpp.

References AU_DEGREE, fRad2Deg, msAngleUnit, and Ogre::Real.

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

Definition at line 324 of file OgreMath.h.

References Ogre::Real.

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

Definition at line 175 of file OgreMath.cpp.

References Ogre::Real, and UnitRandom().

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

Compare 2 reals, using tolerance for inaccuracies.

Definition at line 274 of file OgreMath.cpp.

References Ogre::Real.

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

These functions used to set the assumed angle units (radians or degrees) expected when using the Angle type.

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.

Definition at line 187 of file OgreMath.cpp.

References msAngleUnit.

Degree Ogre::Math::Sign const Degree   dValue [static]
 

Definition at line 257 of file OgreMath.h.

References Ogre::Degree::valueDegrees().

Radian Ogre::Math::Sign const Radian   rValue [static]
 

Definition at line 253 of file OgreMath.h.

References Ogre::Radian::valueRadians().

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

Definition at line 153 of file OgreMath.cpp.

References Ogre::Real.

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.

Definition at line 279 of file OgreMath.h.

References Ogre::Real.

Real Ogre::Math::Sin const Radian   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.

Definition at line 269 of file OgreMath.h.

References Ogre::Real, and Ogre::Radian::valueRadians().

Real Ogre::Math::SinTable Real    fValue [static, protected]
 

Definition at line 95 of file OgreMath.cpp.

References mSinTable, mTrigTableFactor, mTrigTableSize, and Ogre::Real.

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

Definition at line 283 of file OgreMath.h.

References Ogre::Real.

Degree Ogre::Math::Sqrt const Degree   fValue [static]
 

Definition at line 289 of file OgreMath.h.

References Ogre::Degree::valueDegrees().

Radian Ogre::Math::Sqrt const Radian   fValue [static]
 

Definition at line 287 of file OgreMath.h.

References Ogre::Radian::valueRadians().

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

Definition at line 285 of file OgreMath.h.

References Ogre::Real.

Real Ogre::Math::SymmetricRandom   [static]
 

Definition at line 181 of file OgreMath.cpp.

References Ogre::Real, and UnitRandom().

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.

Definition at line 319 of file OgreMath.h.

References Ogre::Real.

Real Ogre::Math::Tan const Radian   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.

Definition at line 309 of file OgreMath.h.

References Ogre::Real, and Ogre::Radian::valueRadians().

Real Ogre::Math::TanTable Real    fValue [static, protected]
 

Definition at line 111 of file OgreMath.cpp.

References mTanTable, mTrigTableFactor, mTrigTableSize, and Ogre::Real.

Real Ogre::Math::UnitRandom   [static]
 

Definition at line 169 of file OgreMath.cpp.

References Ogre::Real.

Referenced by RangeRandom(), and SymmetricRandom().


Member Data Documentation

const Real Ogre::Math::fDeg2Rad = PI / Real(180.0) [static]
 

Definition at line 45 of file OgreMath.cpp.

Referenced by AngleUnitsToRadians(), and DegreesToAngleUnits().

const Real Ogre::Math::fRad2Deg = Real(180.0) / PI [static]
 

Definition at line 46 of file OgreMath.cpp.

Referenced by AngleUnitsToDegrees(), and RadiansToAngleUnits().

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

Definition at line 44 of file OgreMath.cpp.

Referenced by ASin().

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

Definition at line 49 of file OgreMath.cpp.

Referenced by AngleUnitsToDegrees(), AngleUnitsToRadians(), DegreesToAngleUnits(), getAngleUnit(), Math(), RadiansToAngleUnits(), and setAngleUnit().

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

Definition at line 52 of file OgreMath.cpp.

Referenced by buildTrigTables(), Math(), SinTable(), and ~Math().

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

Definition at line 53 of file OgreMath.cpp.

Referenced by buildTrigTables(), Math(), TanTable(), and ~Math().

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

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

Definition at line 51 of file OgreMath.cpp.

Referenced by Math(), SinTable(), and TanTable().

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

Size of the trig tables as determined by constructor.

Definition at line 48 of file OgreMath.cpp.

Referenced by buildTrigTables(), Math(), SinTable(), and TanTable().

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

Definition at line 41 of file OgreMath.cpp.

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

Definition at line 42 of file OgreMath.cpp.

Referenced by ACos().

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

Definition at line 40 of file OgreMath.cpp.

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

Definition at line 43 of file OgreMath.cpp.


The documentation for this class was generated from the following files:

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:51:12 2004