Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

peon::MathUnit Class Reference

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

#include <MathUnit.h>

List of all members.

Public Types

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

Public Member Functions

 MathUnit (unsigned int trigTableSize=4096)
 Default constructor.
 ~MathUnit ()
 Default destructor.

Static Public Member Functions

static int IAbs (int iValue)
static int ICeil (float fValue)
static int IFloor (float fValue)
static int ISign (int iValue)
static Real Abs (Real fValue)
static Degree Abs (const Degree &dValue)
static Radian Abs (const Radian &rValue)
static Radian ACos (Real fValue)
static Radian ASin (Real fValue)
static Radian ATan (Real fValue)
static Radian ATan2 (Real fY, Real fX)
static Real Ceil (Real fValue)
static Real Cos (const Radian &fValue, bool useTables=false)
 Cosine function.
static Real Cos (Real fValue, bool useTables=false)
 Cosine function.
static Real Exp (Real fValue)
static Real Floor (Real fValue)
static Real Log (Real fValue)
static Real Pow (Real fBase, Real fExponent)
static Real Sign (Real fValue)
static Radian Sign (const Radian &rValue)
static Degree Sign (const Degree &dValue)
static Real Sin (const Radian &fValue, bool useTables=false)
 Sine function.
static Real Sin (Real fValue, bool useTables=false)
 Sine function.
static Real Sqr (Real fValue)
static Real Sqrt (Real fValue)
static Radian Sqrt (const Radian &fValue)
static Degree Sqrt (const Degree &fValue)
static Real InvSqrt (Real fValue)
 Inverse square root i.e.
static Real UnitRandom ()
static Real RangeRandom (Real fLow, Real fHigh)
static Real SymmetricRandom ()
static Real Tan (const Radian &fValue, bool useTables=false)
 Tangent function.
static Real Tan (Real fValue, bool useTables=false)
 Tangent function.
static Real DegreesToRadians (Real degrees)
static Real RadiansToDegrees (Real radians)
static void setAngleUnit (AngleUnit unit)
 These functions used to set the assumed angle units (radians or degrees) expected when using the Angle type.
static AngleUnit getAngleUnit (void)
 Get the unit being used for angles.
static Real AngleUnitsToRadians (Real units)
 Convert from the current AngleUnit to radians.
static Real RadiansToAngleUnits (Real radians)
 Convert from radians to the current AngleUnit .
static Real AngleUnitsToDegrees (Real units)
 Convert from the current AngleUnit to degrees.
static Real DegreesToAngleUnits (Real degrees)
 Convert from degrees to the current AngleUnit.
static 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.
static std::pair< bool, Realintersects (const Ray &ray, const Plane &plane)
 Ray / plane intersection, returns boolean result and distance.
static std::pair< bool, Realintersects (const Ray &ray, const Sphere &sphere, bool discardInside=true)
 Ray / sphere intersection, returns boolean result and distance.
static std::pair< bool, Realintersects (const Ray &ray, const AxisAlignedBox &sphere)
 Ray / box intersection, returns boolean result and distance.
static bool intersects (const Sphere &sphere, const AxisAlignedBox &box)
 Sphere / box intersection test.
static bool intersects (const Plane &plane, const AxisAlignedBox &box)
 Plane / box intersection test.
static std::pair< bool, Realintersects (const Ray &ray, const std::vector< Plane > &planeList, bool normalIsOutside)
 Ray / convex plane list intersection test.
static std::pair< bool, Realintersects (const Ray &ray, const std::list< Plane > &planeList, bool normalIsOutside)
 Ray / convex plane list intersection test.
static bool intersects (const Sphere &sphere, const Plane &plane)
 Sphere / plane intersection test.
static bool RealEqual (Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
 Compare 2 reals, using tolerance for inaccuracies.
static 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.
static Matrix44 buildReflectionMatrix (const Plane &p)
 Build a reflection matrix for the passed in plane.
static 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.
static Vector3 calculateBasicFaceNormal (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal, no w-information.
static Vector4 calculateFaceNormalWithoutNormalize (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal without normalize, including the w component which is the offset from the origin.
static Vector3 calculateBasicFaceNormalWithoutNormalize (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal without normalize, no w-information.

Static Public Attributes

static const Real POS_INFINITY
static const Real NEG_INFINITY
static const Real PI
static const Real TWO_PI
static const Real HALF_PI
static const Real fDeg2Rad
static const Real fRad2Deg

Protected Member Functions

void buildTrigTables ()
 Private function to build trig tables.

Static Protected Member Functions

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

Static Protected Attributes

static AngleUnit msAngleUnit
static int mTrigTableSize
 Size of the trig tables as determined by constructor.
static Real mTrigTableFactor
 Radian -> index factor value ( mTrigTableSize / 2 * PI ).
static RealmSinTable
static RealmTanTable


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 peon::MathUnit::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


Constructor & Destructor Documentation

peon::MathUnit::MathUnit unsigned int  trigTableSize = 4096  ) 
 

Default constructor.

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


Member Function Documentation

static Real peon::MathUnit::Cos Real  fValue,
bool  useTables = false
[inline, static]
 

Cosine function.

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

static Real peon::MathUnit::Cos const Radian fValue,
bool  useTables = false
[inline, static]
 

Cosine function.

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

static bool peon::MathUnit::intersects const Sphere sphere,
const Plane plane
[static]
 

Sphere / plane intersection test.

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

static std::pair<bool, Real> peon::MathUnit::intersects const Ray ray,
const std::list< Plane > &  planeList,
bool  normalIsOutside
[static]
 

Ray / convex plane list intersection test.

Parameters:
ray The ray to test with
plaeList List of planes which form a convex volume
normalIsOutside Does the normal point outside the volume

static std::pair<bool, Real> peon::MathUnit::intersects const Ray ray,
const std::vector< Plane > &  planeList,
bool  normalIsOutside
[static]
 

Ray / convex plane list intersection test.

Parameters:
ray The ray to test with
plaeList List of planes which form a convex volume
normalIsOutside Does the normal point outside the volume

static Real peon::MathUnit::InvSqrt Real  fValue  )  [static]
 

Inverse square root i.e.

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

static bool peon::MathUnit::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.

static void peon::MathUnit::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.

static Real peon::MathUnit::Sin Real  fValue,
bool  useTables = false
[inline, static]
 

Sine function.

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

static Real peon::MathUnit::Sin const Radian fValue,
bool  useTables = false
[inline, static]
 

Sine function.

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

static Real peon::MathUnit::Tan Real  fValue,
bool  useTables = false
[inline, static]
 

Tangent function.

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

static Real peon::MathUnit::Tan const Radian fValue,
bool  useTables = false
[inline, static]
 

Tangent function.

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


The documentation for this class was generated from the following file:
Generated on Wed Nov 9 09:37:07 2005 for Peon by  doxygen 1.4.3