My Project
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
ParaEngine::Math Class Reference

standard math lib More...

#include <ParaMath.h>

Public Types

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

Public Member Functions

 Math (unsigned int trigTableSize=4096)
 Default constructor. More...
 
 ~Math ()
 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 float Abs (float fValue)
 
static double Abs (double fValue)
 
static int Abs (int nValue)
 
static Degree Abs (const Degree &dValue)
 
static Radian Abs (const Radian &rValue)
 
static Radian ACos (float fValue)
 
static Radian ASin (float fValue)
 
static Radian ATan (float fValue)
 
static Radian ATan2 (float fY, float fX)
 
static float Ceil (float fValue)
 
static float Cos (const Radian &fValue, bool useTables=false)
 Cosine function. More...
 
static float Cos (float fValue, bool useTables=false)
 Cosine function. More...
 
static float Exp (float fValue)
 
static float Floor (float fValue)
 
static float Log (float fValue)
 
static float Pow (float fBase, float fExponent)
 
static float Sign (float fValue)
 
static Radian Sign (const Radian &rValue)
 
static Degree Sign (const Degree &dValue)
 
static float Sin (const Radian &fValue, bool useTables=false)
 Sine function. More...
 
static float Sin (float fValue, bool useTables=false)
 Sine function. More...
 
static float Sqr (float fValue)
 
static float Sqrt (float fValue)
 
static double Sqr (double fValue)
 
static double Sqrt (double fValue)
 
static Radian Sqrt (const Radian &fValue)
 
static Degree Sqrt (const Degree &fValue)
 
static float InvSqrt (float fValue)
 Inverse square root i.e. More...
 
static float UnitRandom ()
 
static float RangeRandom (float fLow, float fHigh)
 
static float SymmetricRandom ()
 
static float Tan (const Radian &fValue, bool useTables=false)
 Tangent function. More...
 
static float Tan (float fValue, bool useTables=false)
 Tangent function. More...
 
static float DegreesToRadians (float degrees)
 
static float RadiansToDegrees (float radians)
 
static void setAngleUnit (AngleUnit unit)
 These functions used to set the assumed angle units (radians or degrees) expected when using the Angle type. More...
 
static AngleUnit getAngleUnit (void)
 Get the unit being used for angles. More...
 
static float AngleUnitsToRadians (float units)
 Convert from the current AngleUnit to radians. More...
 
static float RadiansToAngleUnits (float radians)
 Convert from radians to the current AngleUnit . More...
 
static float AngleUnitsToDegrees (float units)
 Convert from the current AngleUnit to degrees. More...
 
static float DegreesToAngleUnits (float degrees)
 Convert from degrees to the current AngleUnit. More...
 
static bool pointInTri2D (const Vector2 &p, const Vector2 &a, const Vector2 &b, const Vector2 &c)
 Checks whether a given point is inside a triangle, in a 2-dimensional (Cartesian) space. More...
 
static bool pointInTri3D (const Vector3 &p, const Vector3 &a, const Vector3 &b, const Vector3 &c, const Vector3 &normal)
 Checks whether a given 3D point is inside a triangle. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const Plane &plane)
 Ray / plane intersection, returns boolean result and distance. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const Sphere &sphere, bool discardInside=true)
 Ray / sphere intersection, returns boolean result and distance. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const AxisAlignedBox &box)
 Ray / box intersection, returns boolean result and distance. More...
 
static bool intersects (const Ray &ray, const AxisAlignedBox &box, float *d1, float *d2)
 Ray / box intersection, returns boolean result and two intersection distance. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const Vector3 &a, const Vector3 &b, const Vector3 &c, const Vector3 &normal, bool positiveSide=true, bool negativeSide=true)
 Ray / triangle intersection, returns boolean result and distance. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const Vector3 &a, const Vector3 &b, const Vector3 &c, bool positiveSide=true, bool negativeSide=true)
 Ray / triangle intersection, returns boolean result and distance. More...
 
static bool intersects (const Sphere &sphere, const AxisAlignedBox &box)
 Sphere / box intersection test. More...
 
static bool intersects (const CShapeSphere &sphere, const CShapeBox &box)
 
static bool intersects (const Plane &plane, const AxisAlignedBox &box)
 Plane / box intersection test. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const std::vector< Plane > &planeList, bool normalIsOutside)
 Ray / convex plane list intersection test. More...
 
static std::pair< bool, float > intersects (const Ray &ray, const std::list< Plane > &planeList, bool normalIsOutside)
 Ray / convex plane list intersection test. More...
 
static bool intersects (const Sphere &sphere, const Plane &plane)
 Sphere / plane intersection test. More...
 
static bool RealEqual (float a, float b, float tolerance=std::numeric_limits< float >::epsilon())
 Compare 2 reals, using tolerance for inaccuracies.
 
static Vector3 calculateTangentSpaceVector (const Vector3 &position1, const Vector3 &position2, const Vector3 &position3, float u1, float v1, float u2, float v2, float u3, float v3)
 Calculates the tangent space vector for a given set of positions / texture coords. More...
 
static Matrix4 buildReflectionMatrix (const Plane &p)
 Build a reflection matrix for the passed in plane. More...
 
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. More...
 
static Vector3 calculateBasicFaceNormal (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal, no w-information. More...
 
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. More...
 
static Vector3 calculateBasicFaceNormalWithoutNormalize (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
 Calculate a face normal without normalize, no w-information. More...
 
static float gaussianDistribution (float x, float offset=0.0f, float scale=1.0f)
 Generates a value based on the Gaussian (normal) distribution function with the given offset and scale parameters.
 
template<class T >
static T Clamp (const T X, const T Min, const T Max)
 Clamps X to be between Min and Max, inclusive.
 
static Matrix4 makeViewMatrix (const Vector3 &position, const Quaternion &orientation, const Matrix4 *reflectMatrix=0)
 
static bool IsEquivalent (float f1, float f2)
 Returns whether two floating-point values are equivalent within a given tolerance. More...
 
static bool IsEquivalent (float f1, float f2, float tolerance)
 Returns whether two floating-point values are equivalent within a given tolerance. More...
 
static bool IsEquivalent (double f1, double f2)
 Returns whether two double-sized floating-point values are equivalent. More...
 
static bool IsEquivalent (double f1, double f2, double tolerance)
 Returns whether two double-sized floating-point values are equivalent within a given tolerance. More...
 
template<class T >
static bool IsEquivalent (const T *al, size_t acount, const T *bl, size_t bcount)
 Returns whether two constant-sized arrays are equivalent. More...
 
static int log2 (unsigned int x)
 this is a fast version of log2. More...
 
static int log2_ceil (unsigned int x)
 this is a fast version of log2. More...
 
template<class T >
static T Max (const T A, const T B)
 Returns higher value in a generic way.
 
template<class T >
static T Min (const T A, const T B)
 Returns lower value in a generic way.
 
static int32 Trunc (float F)
 Converts a float to an integer with truncation towards zero. More...
 
static float TruncFloat (float F)
 Converts a float to an integer value with truncation towards zero. More...
 
static float Fractional (float Value)
 Returns the fractional part of a float. More...
 
static float GridSnap (float Location, float Grid)
 Snaps a value to the nearest grid multiple.
 
template<class T >
static T DivideAndRoundUp (T Dividend, T Divisor)
 Divides two integers and rounds up.
 
template<class T >
static T Max3 (const T A, const T B, const T C)
 Returns highest of 3 values.
 
template<class T >
static T Min3 (const T A, const T B, const T C)
 Returns lowest of 3 values.
 
template<class T , class U >
static T Lerp (const T &A, const T &B, const U &Alpha)
 Performs a linear interpolation between two values, Alpha ranges from 0-1.
 
static int32 Rand ()
 Returns a random integer between 0 and RAND_MAX, inclusive.
 
static void RandInit (int32 Seed)
 Seeds global random number functions Rand() and FRand()
 
static float FRand ()
 Returns a random float between 0 and 1, inclusive. More...
 
static void SRandInit (int32 Seed)
 Seeds future calls to SRand()
 
static float SRand ()
 Returns a seeded random float in the range [0,1), using the seed from SRandInit(). More...
 
static float FloatSelect (float Comparand, float ValueGEZero, float ValueLTZero)
 Returns value based on comparand. More...
 
static bool SmoothMoveFloat1 (float &src, const float dest, const float fMaxStep)
 change src from src to dest, by a maximum of fMaxStep. More...
 
static bool SmoothMoveAngle1 (float &src, const float dest, const float fMaxStep)
 change src from src to dest, by a maximum of fMaxStep. More...
 
static bool SmoothMoveVec3 (Vector3 *result, const Vector3 &vPosTarget, const Vector3 &vPos, FLOAT fIncrease, FLOAT fTolerance)
 linearly (smoothly) move vPos to vPosTarget by the amount fIncrease return true if we have reached the target. More...
 
static float ToStandardAngle (float fAngle)
 make sure that the angle is in the range (-Pi,Pi]
 
static double ToStandardAngle (double fAngle)
 
static bool MatchString (const std::string &matchPattern, const std::string &matchStr)
 check if the matchStr matches the string pattern in matchPattern More...
 
static bool ComputeFacingTarget (const Vector3 &target, const Vector3 &source, FLOAT &fFacing)
 facing target in xz plane fFacing: [out] it is in the range [0, 2PI] return true if target!=source(a valid facing can be computed)
 
static bool ComputeFacingTarget (const DVector3 &target, const DVector3 &source, float &fFacing)
 
static int Round (float fValue)
 get the closest integer near the specified float number. More...
 
static float MinVec3 (const Vector3 &v)
 Returns MIN(x, y, z);.
 
static float MaxVec3 (const Vector3 &v)
 Returns MAX(x, y, z);.
 
template<class T >
static bool CompareXZ (const T &a, const T &b)
 return true if equal. More...
 
template<class T >
static bool CompareXZ (const T &a, const T &b, float epsilon)
 return true if equal. More...
 
static bool FuzzyCompare (double p1, double p2)
 
static bool FuzzyCompare (float p1, float p2)
 
static bool FuzzyIsNull (double d)
 
static bool FuzzyIsNull (float f)
 
static bool IsNull (double d)
 
static bool IsNull (float f)
 
template<typename T >
static bool is_nan (T value)
 whether value is not a number, T is usually float or double
 
template<typename T >
static bool is_infinity (T value)
 whether value is infinity, T is usually float or double
 
static void GetMatrixScaling (const Matrix4 &globalMat, float *fScalingX, float *fScalingY, float *fScalingZ)
 Get the scaling factor from globalMat. More...
 
static Matrix4CreateBillboardMatrix (Matrix4 *pOut, const Matrix4 *matModelview, const Vector3 *vBillboardPos, bool bAxisAligned=false)
 create a billboard matrix More...
 
static void CameraRotMatrixYawPitch (Matrix4 &out, float fYaw, float fPitch)
 
static int NextPowerOf2 (int x)
 get nearest power of two of x
 

Static Public Attributes

static const float POS_INFINITY = std::numeric_limits<float>::infinity()
 
static const float NEG_INFINITY = -std::numeric_limits<float>::infinity()
 
static const float PI = float( 4.0f * atan( 1.0f ) )
 
static const float TWO_PI = float( 2.0f * PI )
 
static const float HALF_PI = float( 0.5 * PI )
 
static const float fDeg2Rad = PI / float(180.0)
 
static const float fRad2Deg = float(180.0) / PI
 

Protected Member Functions

void buildTrigTables ()
 Private function to build trig tables.
 

Static Protected Member Functions

static float SinTable (float fValue)
 
static float TanTable (float fValue)
 

Static Protected Attributes

static AngleUnit msAngleUnit
 
static int mTrigTableSize
 Size of the trig tables as determined by constructor.
 
static float mTrigTableFactor
 Radian -> index factor value ( mTrigTableSize / 2 * PI )
 
static float * mSinTable = NULL
 
static float * mTanTable = NULL
 

Detailed Description

standard math lib

Member Enumeration Documentation

§ 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

§ Math()

Math::Math ( unsigned int  trigTableSize = 4096)

Default constructor.

Parameters
trigTableSizeOptional parameter to set the size of the tables used to implement Sin, Cos, Tan

Member Function Documentation

§ AngleUnitsToDegrees()

float Math::AngleUnitsToDegrees ( float  units)
static

Convert from the current AngleUnit to degrees.

§ AngleUnitsToRadians()

float Math::AngleUnitsToRadians ( float  units)
static

Convert from the current AngleUnit to radians.

§ buildReflectionMatrix()

Matrix4 Math::buildReflectionMatrix ( const Plane p)
static

Build a reflection matrix for the passed in plane.

§ calculateBasicFaceNormal()

Vector3 Math::calculateBasicFaceNormal ( const Vector3 v1,
const Vector3 v2,
const Vector3 v3 
)
static

Calculate a face normal, no w-information.

§ calculateBasicFaceNormalWithoutNormalize()

Vector3 Math::calculateBasicFaceNormalWithoutNormalize ( const Vector3 v1,
const Vector3 v2,
const Vector3 v3 
)
static

Calculate a face normal without normalize, no w-information.

§ calculateFaceNormal()

Vector4 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.

§ calculateFaceNormalWithoutNormalize()

Vector4 Math::calculateFaceNormalWithoutNormalize ( const Vector3 v1,
const Vector3 v2,
const Vector3 v3 
)
static

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

§ calculateTangentSpaceVector()

Vector3 Math::calculateTangentSpaceVector ( const Vector3 position1,
const Vector3 position2,
const Vector3 position3,
float  u1,
float  v1,
float  u2,
float  v2,
float  u3,
float  v3 
)
static

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

§ CameraRotMatrixYawPitch()

void ParaEngine::Math::CameraRotMatrixYawPitch ( Matrix4 out,
float  fYaw,
float  fPitch 
)
static

LXZ: 2009.6.26. for unknown reasons, ParaMatrixRotationYawPitchRoll sometimes yields invalid matrix. So I need to emulate it with standard multiplication. The order of transformations is roll first, then pitch, then yaw, where:

  • Yaw around the y-axis, in radians.
  • Pitch around the x-axis, in radians.
  • Roll around the z-axis, in radians. ParaMatrixRotationYawPitchRoll( &mCameraRot, m_fCameraYawAngle, m_fCameraPitchAngle, 0 );

§ CompareXZ() [1/2]

template<class T >
static bool ParaEngine::Math::CompareXZ ( const T &  a,
const T &  b 
)
inlinestatic

return true if equal.

T is a 3D vector, such as Vector3

§ CompareXZ() [2/2]

template<class T >
static bool ParaEngine::Math::CompareXZ ( const T &  a,
const T &  b,
float  epsilon 
)
inlinestatic

return true if equal.

T is a 3D vector, such as Vector3

§ Cos() [1/2]

static float ParaEngine::Math::Cos ( const Radian fValue,
bool  useTables = false 
)
inlinestatic

Cosine function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ Cos() [2/2]

static float ParaEngine::Math::Cos ( float  fValue,
bool  useTables = false 
)
inlinestatic

Cosine function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ CreateBillboardMatrix()

Matrix4 * ParaEngine::Math::CreateBillboardMatrix ( Matrix4 pOut,
const Matrix4 matModelview,
const Vector3 vBillboardPos,
bool  bAxisAligned = false 
)
static

create a billboard matrix

Parameters
pOut[out], the output billboard matrix
matModelviewthe current model view matrix. if NULL, the current model and view matrix on the global stack is used
vBillboardPosthe billboard position in model space. if NULL, (0,0,0) is used.
bAxisAlignedif true, it will create a billboard with Y (up) axis fixed. Default to false.
Returns
pOut is returned.

§ DegreesToAngleUnits()

float Math::DegreesToAngleUnits ( float  degrees)
static

Convert from degrees to the current AngleUnit.

§ FloatSelect()

static float ParaEngine::Math::FloatSelect ( float  Comparand,
float  ValueGEZero,
float  ValueLTZero 
)
inlinestatic

Returns value based on comparand.

The main purpose of this function is to avoid branching based on floating point comparison which can be avoided via compiler intrinsics.

Please note that we don't define what happens in the case of NaNs as there might be platform specific differences.

Parameters
ComparandComparand the results are based on
ValueGEZeroReturn value if Comparand >= 0
ValueLTZeroReturn value if Comparand < 0
Returns
ValueGEZero if Comparand >= 0, ValueLTZero otherwise

§ Fractional()

static float ParaEngine::Math::Fractional ( float  Value)
inlinestatic

Returns the fractional part of a float.

Parameters
ValueFloating point value to convert
Returns
A float between >=0 and < 1.

§ FRand()

static float ParaEngine::Math::FRand ( )
inlinestatic

Returns a random float between 0 and 1, inclusive.

§ getAngleUnit()

Math::AngleUnit Math::getAngleUnit ( void  )
static

Get the unit being used for angles.

§ GetMatrixScaling()

void Math::GetMatrixScaling ( const Matrix4 globalMat,
float *  fScalingX,
float *  fScalingY,
float *  fScalingZ 
)
static

Get the scaling factor from globalMat.

since we need to create separate physics mesh with different scaling factors even for the same mesh model. it is assumed that components of globalMat satisfies the following equation: |(globalMat._11, globalMat._12, globalMat._13)| = 1; |(globalMat._21, globalMat._22, globalMat._23)| = 1; |(globalMat._31, globalMat._32, globalMat._33)| = 1;

Parameters
globalMatthe input matrix
fScalingX[out] maybe NULL
fScalingY[out] maybe NULL
fScalingZ[out] maybe NULL

§ intersects() [1/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const Plane plane 
)
static

Ray / plane intersection, returns boolean result and distance.

§ intersects() [2/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const Sphere sphere,
bool  discardInside = true 
)
static

Ray / sphere intersection, returns boolean result and distance.

§ intersects() [3/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const AxisAlignedBox box 
)
static

Ray / box intersection, returns boolean result and distance.

§ intersects() [4/11]

bool Math::intersects ( const Ray ray,
const AxisAlignedBox box,
float *  d1,
float *  d2 
)
static

Ray / box intersection, returns boolean result and two intersection distance.

Parameters
rayThe ray.
boxThe box.
d1A real pointer to retrieve the near intersection distance from the ray origin, maybe null which means don't care about the near intersection distance.
d2A real pointer to retrieve the far intersection distance from the ray origin, maybe null which means don't care about the far intersection distance.
Returns
If the ray is intersects the box, true is returned, and the near intersection distance is return by d1, the far intersection distance is return by d2. Guarantee 0 <= d1 <= d2.
If the ray isn't intersects the box, false is returned, and d1 and d2 is unmodified.

§ intersects() [5/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const Vector3 a,
const Vector3 b,
const Vector3 c,
const Vector3 normal,
bool  positiveSide = true,
bool  negativeSide = true 
)
static

Ray / triangle intersection, returns boolean result and distance.

Parameters
rayThe ray.
aThe triangle's first vertex.
bThe triangle's second vertex.
cThe triangle's third vertex.
normalThe triangle plane's normal (passed in rather than calculated on demand since the caller may already have it), doesn't need normalised since we don't care.
positiveSideIntersect with "positive side" of the triangle
negativeSideIntersect with "negative side" of the triangle
Returns
If the ray is intersects the triangle, a pair of true and the distance between intersection point and ray origin returned.
If the ray isn't intersects the triangle, a pair of false and 0 returned.

§ intersects() [6/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const Vector3 a,
const Vector3 b,
const Vector3 c,
bool  positiveSide = true,
bool  negativeSide = true 
)
static

Ray / triangle intersection, returns boolean result and distance.

Parameters
rayThe ray.
aThe triangle's first vertex.
bThe triangle's second vertex.
cThe triangle's third vertex.
positiveSideIntersect with "positive side" of the triangle
negativeSideIntersect with "negative side" of the triangle
Returns
If the ray is intersects the triangle, a pair of true and the distance between intersection point and ray origin returned.
If the ray isn't intersects the triangle, a pair of false and 0 returned.

§ intersects() [7/11]

bool Math::intersects ( const Sphere sphere,
const AxisAlignedBox box 
)
static

Sphere / box intersection test.

§ intersects() [8/11]

bool Math::intersects ( const Plane plane,
const AxisAlignedBox box 
)
static

Plane / box intersection test.

§ intersects() [9/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const std::vector< Plane > &  planeList,
bool  normalIsOutside 
)
static

Ray / convex plane list intersection test.

Parameters
rayThe ray to test with
plaeListList of planes which form a convex volume
normalIsOutsideDoes the normal point outside the volume

§ intersects() [10/11]

std::pair< bool, float > Math::intersects ( const Ray ray,
const std::list< Plane > &  planeList,
bool  normalIsOutside 
)
static

Ray / convex plane list intersection test.

Parameters
rayThe ray to test with
plaeListList of planes which form a convex volume
normalIsOutsideDoes the normal point outside the volume

§ intersects() [11/11]

bool 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!

§ InvSqrt()

float Math::InvSqrt ( float  fValue)
static

Inverse square root i.e.

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

§ IsEquivalent() [1/5]

static bool ParaEngine::Math::IsEquivalent ( float  f1,
float  f2 
)
inlinestatic

Returns whether two floating-point values are equivalent within a given tolerance.

Parameters
f1A first floating-point value.
f2A second floating-point value.

§ IsEquivalent() [2/5]

static bool ParaEngine::Math::IsEquivalent ( float  f1,
float  f2,
float  tolerance 
)
inlinestatic

Returns whether two floating-point values are equivalent within a given tolerance.

Parameters
f1A first floating-point value.
f2A second floating-point value.
toleranceThe tolerance in which to accept the two floating-point values as equivalent.

§ IsEquivalent() [3/5]

static bool ParaEngine::Math::IsEquivalent ( double  f1,
double  f2 
)
inlinestatic

Returns whether two double-sized floating-point values are equivalent.

Parameters
f1A first double-sized floating-point value.
f2A second double-sized floating-point value.

§ IsEquivalent() [4/5]

static bool ParaEngine::Math::IsEquivalent ( double  f1,
double  f2,
double  tolerance 
)
inlinestatic

Returns whether two double-sized floating-point values are equivalent within a given tolerance.

Parameters
f1A first double-sized floating-point value.
f2A second double-sized floating-point value.
toleranceThe tolerance in which to accept the two double-sized floating-point values as equivalent.

§ IsEquivalent() [5/5]

template<class T >
static bool ParaEngine::Math::IsEquivalent ( const T *  al,
size_t  acount,
const T *  bl,
size_t  bcount 
)
inlinestatic

Returns whether two constant-sized arrays are equivalent.

Parameters
alA first constant-sized array.
acountThe number of elements in the first array.
blA second constant-sized array.
bcountThe number of elements in the second array.
Returns
Whether the two arrays are equivalent.

§ log2()

int Math::log2 ( unsigned int  x)
static

this is a fast version of log2.

return the smaller

§ log2_ceil()

static int ParaEngine::Math::log2_ceil ( unsigned int  x)
inlinestatic

this is a fast version of log2.

return the bigger

§ MatchString()

bool Math::MatchString ( const std::string &  matchPattern,
const std::string &  matchStr 
)
static

check if the matchStr matches the string pattern in matchPattern

Parameters
matchPatternthe match pattern. It may end with "*" in which case "*" will match any character(s). e.g "Li*" will match both "LiXizhi" and "LiTC", whereas "Li" will only match "Li"
matchStrthe match string.
Returns
: return true if the two string matches.

§ pointInTri2D()

bool Math::pointInTri2D ( const Vector2 p,
const Vector2 a,
const Vector2 b,
const Vector2 c 
)
static

Checks whether 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
pThe point.
aThe triangle's first vertex.
bThe triangle's second vertex.
cThe 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.

§ pointInTri3D()

bool Math::pointInTri3D ( const Vector3 p,
const Vector3 a,
const Vector3 b,
const Vector3 c,
const Vector3 normal 
)
static

Checks whether a given 3D point is inside a triangle.

Remarks
The vertices of the triangle must be given in either trigonometrical (anticlockwise) or inverse trigonometrical (clockwise) order, and the point must be guaranteed to be in the same plane as the triangle
Parameters
pThe point.
aThe triangle's first vertex.
bThe triangle's second vertex.
cThe triangle's third vertex.
normalThe triangle plane's normal (passed in rather than calculated on demand since the caller may already have it)
Returns
If the point resides in the triangle, true is returned.
If the point is outside the triangle, false is returned.

§ RadiansToAngleUnits()

float Math::RadiansToAngleUnits ( float  radians)
static

Convert from radians to the current AngleUnit .

§ Round()

int ParaEngine::Math::Round ( float  fValue)
inlinestatic

get the closest integer near the specified float number.

E.g. Round(1.49)==1, Round(1.51)==2, ToInt(

§ setAngleUnit()

void Math::setAngleUnit ( Math::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.

§ Sin() [1/2]

static float ParaEngine::Math::Sin ( const Radian fValue,
bool  useTables = false 
)
inlinestatic

Sine function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ Sin() [2/2]

static float ParaEngine::Math::Sin ( float  fValue,
bool  useTables = false 
)
inlinestatic

Sine function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ SmoothMoveAngle1()

bool Math::SmoothMoveAngle1 ( float &  src,
const float  dest,
const float  fMaxStep 
)
static

change src from src to dest, by a maximum of fMaxStep.

If dest has been reached, return true; otherwise return false.

§ SmoothMoveFloat1()

bool Math::SmoothMoveFloat1 ( float &  src,
const float  dest,
const float  fMaxStep 
)
static

change src from src to dest, by a maximum of fMaxStep.

If dest has been reached, return true; otherwise return false.

§ SmoothMoveVec3()

bool Math::SmoothMoveVec3 ( Vector3 result,
const Vector3 vPosTarget,
const Vector3 vPos,
FLOAT  fIncrease,
FLOAT  fTolerance 
)
static

linearly (smoothly) move vPos to vPosTarget by the amount fIncrease return true if we have reached the target.

if the distance between target and the pos is within fTolerance, result is set to target

§ SRand()

float Math::SRand ( )
static

Returns a seeded random float in the range [0,1), using the seed from SRandInit().

§ Tan() [1/2]

static float ParaEngine::Math::Tan ( const Radian fValue,
bool  useTables = false 
)
inlinestatic

Tangent function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ Tan() [2/2]

static float ParaEngine::Math::Tan ( float  fValue,
bool  useTables = false 
)
inlinestatic

Tangent function.

Parameters
fValueAngle in radians
useTablesIf true, uses lookup tables rather than calculation - faster but less accurate.

§ Trunc()

static int32 ParaEngine::Math::Trunc ( float  F)
inlinestatic

Converts a float to an integer with truncation towards zero.

Parameters
FFloating point value to convert
Returns
Truncated integer.

§ TruncFloat()

static float ParaEngine::Math::TruncFloat ( float  F)
inlinestatic

Converts a float to an integer value with truncation towards zero.

Parameters
FFloating point value to convert
Returns
Truncated integer value.

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