Class to provide access to common mathematical functions. More...
#include <OgreMath.h>
Classes | |
class | RandomValueProvider |
This class is used to provide an external random value provider. More... | |
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. More... | |
Static Public Member Functions | |
static Real | Abs (Real fValue) |
Absolute value function. More... | |
static Degree | Abs (const Degree &dValue) |
Absolute value function. More... | |
static Radian | Abs (const Radian &rValue) |
Absolute value function. More... | |
static Radian | ACos (Real fValue) |
Arc cosine function. More... | |
static Real | AngleUnitsToDegrees (Real units) |
Convert from the current AngleUnit to degrees. More... | |
static Real | AngleUnitsToRadians (Real units) |
Convert from the current AngleUnit to radians. More... | |
static Radian | ASin (Real fValue) |
Arc sine function. More... | |
static Radian | ATan (Real fValue) |
Arc tangent function. More... | |
static Radian | ATan2 (Real fY, Real fX) |
Arc tangent between two values function. More... | |
static Real | boundingRadiusFromAABB (const AxisAlignedBox &aabb) |
Get a bounding radius value from a bounding box. More... | |
static Matrix4 | buildReflectionMatrix (const Plane &p) |
Build a reflection matrix for the passed in plane. More... | |
static Vector3 | calculateBasicFaceNormal (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) |
Calculate a face normal, no w-information. More... | |
static Vector3 | calculateBasicFaceNormalWithoutNormalize (const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) |
Calculate a face normal without normalize, no w-information. 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 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 | 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. More... | |
static Real | Ceil (Real fValue) |
Ceiling function Returns the smallest following integer. More... | |
template<typename T > | |
static T | Clamp (T val, T minval, T maxval) |
Clamp a value within an inclusive range. More... | |
static Real | Cos (const Radian &fValue, bool useTables=false) |
Cosine function. More... | |
static Real | Cos (Real fValue, bool useTables=false) |
Cosine function. More... | |
static Real | DegreesToAngleUnits (Real degrees) |
Convert from degrees to the current AngleUnit. More... | |
static Real | DegreesToRadians (Real degrees) |
static Real | Exp (Real fValue) |
static Real | Floor (Real fValue) |
Floor function Returns the largest previous integer. More... | |
static Real | gaussianDistribution (Real x, Real offset=0.0f, Real scale=1.0f) |
Generates a value based on the Gaussian (normal) distribution function with the given offset and scale parameters. More... | |
static AngleUnit | getAngleUnit (void) |
Get the unit being used for angles. More... | |
static int | IAbs (int iValue) |
static int | ICeil (float fValue) |
static int | IFloor (float fValue) |
static std::pair< bool, Real > | intersects (const Ray &ray, const Plane &plane) |
Ray / plane intersection, returns boolean result and distance. More... | |
static std::pair< bool, Real > | intersects (const Ray &ray, const Sphere &sphere, bool discardInside=true) |
Ray / sphere intersection, returns boolean result and distance. More... | |
static std::pair< bool, Real > | 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, Real *d1, Real *d2) |
Ray / box intersection, returns boolean result and two intersection distance. More... | |
static std::pair< bool, Real > | 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, Real > | 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 Plane &plane, const AxisAlignedBox &box) |
Plane / box intersection test. More... | |
static std::pair< bool, Real > | intersects (const Ray &ray, const vector< Plane >::type &planeList, bool normalIsOutside) |
Ray / convex plane list intersection test. More... | |
static std::pair< bool, Real > | intersects (const Ray &ray, const list< Plane >::type &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 Real | InvSqrt (Real fValue) |
Inverse square root i.e. More... | |
static int | ISign (int iValue) |
static bool | isNaN (Real f) |
template<typename V , typename T > | |
static V | lerp (const V &v0, const V &v1, const T &t) |
static Real | Log (Real fValue) |
static Real | Log2 (Real fValue) |
static Real | LogN (Real base, Real fValue) |
static Matrix4 | makeViewMatrix (const Vector3 &position, const Quaternion &orientation, const Matrix4 *reflectMatrix=0) |
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 Real | Pow (Real fBase, Real fExponent) |
static Real | RadiansToAngleUnits (Real radians) |
Convert from radians to the current AngleUnit . More... | |
static Real | RadiansToDegrees (Real radians) |
static Real | RangeRandom (Real fLow, Real fHigh) |
Generate a random number within the range provided. More... | |
static bool | RealEqual (Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon()) |
Compare 2 reals, using tolerance for inaccuracies. More... | |
static float | saturate (float t) |
static double | saturate (double t) |
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 void | SetRandomValueProvider (RandomValueProvider *provider) |
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. More... | |
static Real | Sin (Real fValue, bool useTables=false) |
Sine function. More... | |
static Real | Sqr (Real fValue) |
Squared function. More... | |
static Real | Sqrt (Real fValue) |
Square root function. More... | |
static Radian | Sqrt (const Radian &fValue) |
Square root function. More... | |
static Degree | Sqrt (const Degree &fValue) |
Square root function. More... | |
static Real | SymmetricRandom () |
Generate a random number in the range [-1,1]. More... | |
static Real | Tan (const Radian &fValue, bool useTables=false) |
Tangent function. More... | |
static Real | Tan (Real fValue, bool useTables=false) |
Tangent function. More... | |
static Real | UnitRandom () |
Generate a random number of unit length. More... | |
Static Public Attributes | |
static const Real | fDeg2Rad |
static const Real | fRad2Deg |
static const Real | HALF_PI |
static const Real | LOG2 |
Stored value of log(2) for frequent use. More... | |
static const Real | NEG_INFINITY |
static const Real | PI |
static const Real | POS_INFINITY |
static const Real | TWO_PI |
Protected Member Functions | |
void | buildTrigTables () |
Private function to build trig tables. More... | |
Static Protected Member Functions | |
static Real | SinTable (Real fValue) |
static Real | TanTable (Real fValue) |
Static Protected Attributes | |
static RandomValueProvider * | mRandProvider |
A random value provider. overriding the default random number generator. More... | |
static AngleUnit | msAngleUnit |
Angle units used by the api. More... | |
static Real * | mSinTable |
static Real * | mTanTable |
static Real | mTrigTableFactor |
Radian -> index factor value ( mTrigTableSize / 2 * PI ) More... | |
static int | mTrigTableSize |
Size of the trig tables as determined by constructor. More... | |
Class to provide access to common mathematical functions.
Definition at line 191 of file OgreMath.h.
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
Enumerator | |
---|---|
AU_DEGREE | |
AU_RADIAN |
Definition at line 199 of file OgreMath.h.
Ogre::Math::Math | ( | unsigned int | trigTableSize = 4096 | ) |
Default constructor.
trigTableSize | Optional parameter to set the size of the tables used to implement Sin, Cos, Tan |
Ogre::Math::~Math | ( | ) |
Default destructor.
Absolute value function.
fValue | The value whose absolute value will be returned. |
Definition at line 258 of file OgreMath.h.
Referenced by Ogre::Vector3::absDotProduct(), Ogre::Vector3::directionEquals(), Ogre::Volume::OctreeNode::isIsoSurfaceNear(), Ogre::Vector3::primaryAxis(), and Ogre::AxisAlignedBox::transformAffine().
Absolute value function.
dValue | The value, in degrees, whose absolute value will be returned. |
Definition at line 264 of file OgreMath.h.
References Ogre::Degree::valueDegrees().
Absolute value function.
rValue | The value, in radians, whose absolute value will be returned. |
Definition at line 270 of file OgreMath.h.
References Ogre::Radian::valueRadians().
Arc cosine function.
fValue | The value whose arc cosine will be returned. |
Referenced by Ogre::Vector2::angleBetween(), Ogre::Vector3::angleBetween(), and Ogre::Vector3::directionEquals().
Convert from the current AngleUnit to degrees.
Referenced by Ogre::Angle::operator Degree().
Convert from the current AngleUnit to radians.
Referenced by Ogre::Angle::operator Radian().
Arc sine function.
fValue | The value whose arc sine will be returned. |
Arc tangent function.
fValue | The value whose arc tangent will be returned. |
Definition at line 288 of file OgreMath.h.
Arc tangent between two values function.
fY | The first value to calculate the arc tangent with. |
fX | The second value to calculate the arc tangent with. |
Definition at line 296 of file OgreMath.h.
|
static |
Get a bounding radius value from a bounding box.
Build a reflection matrix for the passed in plane.
|
protected |
Private function to build trig tables.
|
static |
Calculate a face normal, no w-information.
|
static |
Calculate a face normal without normalize, no w-information.
|
static |
Calculate a face normal, including the w component which is the offset from the origin.
|
static |
Calculate a face normal without normalize, including the w component which is the offset from the origin.
|
static |
Calculates the tangent space vector for a given set of positions / texture coords.
Ceiling function Returns the smallest following integer.
(example: Ceil(1.1) = 2)
fValue | The value to round up to the nearest integer. |
Definition at line 304 of file OgreMath.h.
|
inlinestatic |
Clamp a value within an inclusive range.
Definition at line 690 of file OgreMath.h.
Referenced by Ogre::Vector2::angleBetween(), and Ogre::Vector3::angleBetween().
Cosine function.
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::Radian::valueRadians().
Referenced by Ogre::Vector2::randomDeviant().
Cosine function.
fValue | Angle in radians |
useTables | If true, uses lookup tables rather than calculation - faster but less accurate. |
Definition at line 329 of file OgreMath.h.
Convert from degrees to the current AngleUnit.
Referenced by Ogre::Degree::valueAngleUnits().
Definition at line 475 of file OgreMath.h.
Referenced by Ogre::Degree::valueRadians().
Definition at line 333 of file OgreMath.h.
Floor function Returns the largest previous integer.
(example: Floor(1.9) = 1)
fValue | The value to round down to the nearest integer. |
Definition at line 341 of file OgreMath.h.
|
static |
Generates a value based on the Gaussian (normal) distribution function with the given offset and scale parameters.
|
static |
Get the unit being used for angles.
|
inlinestatic |
Definition at line 249 of file OgreMath.h.
|
inlinestatic |
Definition at line 250 of file OgreMath.h.
|
inlinestatic |
Definition at line 251 of file OgreMath.h.
Ray / plane intersection, returns boolean result and distance.
Referenced by Ogre::Ray::intersects(), Ogre::Sphere::intersects(), Ogre::PlaneBoundedVolume::intersects(), and Ogre::AxisAlignedBox::intersects().
|
static |
Ray / sphere intersection, returns boolean result and distance.
|
static |
Ray / box intersection, returns boolean result and distance.
|
static |
Ray / box intersection, returns boolean result and two intersection distance.
ray | The ray. |
box | The box. |
d1 | A real pointer to retrieve the near intersection distance from the ray origin, maybe null which means don't care about the near intersection distance. |
d2 | A real pointer to retrieve the far intersection distance from the ray origin, maybe null which means don't care about the far intersection distance. |
|
static |
Ray / triangle intersection, returns boolean result and distance.
ray | The ray. |
a | The triangle's first vertex. |
b | The triangle's second vertex. |
c | The triangle's third vertex. |
normal | The 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. |
positiveSide | Intersect with "positive side" of the triangle |
negativeSide | Intersect with "negative side" of the triangle |
|
static |
Ray / triangle intersection, returns boolean result and distance.
ray | The ray. |
a | The triangle's first vertex. |
b | The triangle's second vertex. |
c | The triangle's third vertex. |
positiveSide | Intersect with "positive side" of the triangle |
negativeSide | Intersect with "negative side" of the triangle |
|
static |
Sphere / box intersection test.
|
static |
Plane / box intersection test.
|
static |
Ray / convex plane list intersection test.
ray | The ray to test with |
planeList | List of planes which form a convex volume |
normalIsOutside | Does the normal point outside the volume |
|
static |
Ray / convex plane list intersection test.
ray | The ray to test with |
planeList | List of planes which form a convex volume |
normalIsOutside | Does the normal point outside the volume |
Sphere / plane intersection test.
Inverse square root i.e.
1 / Sqrt(x), good for vector normalisation.
fValue | The value whose inverse square root will be calculated. |
|
static |
|
inlinestatic |
Definition at line 305 of file OgreMath.h.
Referenced by Ogre::DualQuaternion::isNaN(), Ogre::Quaternion::isNaN(), Ogre::Vector4::isNaN(), Ogre::Vector2::isNaN(), and Ogre::Vector3::isNaN().
|
inlinestatic |
Definition at line 371 of file OgreMath.h.
Definition at line 343 of file OgreMath.h.
Definition at line 348 of file OgreMath.h.
Definition at line 350 of file OgreMath.h.
|
static |
|
static |
Checks whether a given point is inside a triangle, in a 2-dimensional (Cartesian) space.
p | The point. |
a | The triangle's first vertex. |
b | The triangle's second vertex. |
c | The triangle's third vertex. |
|
static |
Checks whether a given 3D point is inside a triangle.
p | p The point. |
a | The triangle's first vertex. |
b | The triangle's second vertex. |
c | The triangle's third vertex. |
normal | The triangle plane's normal (passed in rather than calculated on demand since the caller may already have it) |
Definition at line 352 of file OgreMath.h.
Convert from radians to the current AngleUnit .
Referenced by Ogre::Radian::valueAngleUnits().
Definition at line 476 of file OgreMath.h.
Referenced by Ogre::Radian::valueDegrees().
Generate a random number within the range provided.
fLow | The lower bound of the range. |
fHigh | The upper bound of the range. |
Referenced by Ogre::Vector2::randomDeviant().
|
static |
Compare 2 reals, using tolerance for inaccuracies.
Referenced by Ogre::Matrix3::hasScale(), Ogre::Matrix4::hasScale(), Ogre::QueuedRenderableCollection::DepthSortDescendingLess::operator()(), and Ogre::Vector3::positionEquals().
|
inlinestatic |
Definition at line 365 of file OgreMath.h.
|
inlinestatic |
Definition at line 366 of file OgreMath.h.
|
static |
|
static |
Definition at line 355 of file OgreMath.h.
References Ogre::Radian::valueRadians().
Definition at line 359 of file OgreMath.h.
References Ogre::Degree::valueDegrees().
Sine function.
fValue | Angle in radians |
useTables | If true, uses lookup tables rather than calculation - faster but less accurate. |
Definition at line 381 of file OgreMath.h.
References Ogre::Radian::valueRadians().
Referenced by Ogre::Vector2::randomDeviant().
Sine function.
fValue | Angle in radians |
useTables | If true, uses lookup tables rather than calculation - faster but less accurate. |
Definition at line 391 of file OgreMath.h.
Squared function.
fValue | The value to be squared (fValue^2) |
Definition at line 399 of file OgreMath.h.
Referenced by Ogre::Sphere::intersects(), and Ogre::Sphere::merge().
Square root function.
fValue | The value whose square root will be calculated. |
Definition at line 405 of file OgreMath.h.
Referenced by Ogre::AxisAlignedBox::distance(), Ogre::Vector3::getRotationTo(), Ogre::Vector2::length(), Ogre::Vector3::length(), Ogre::Sphere::merge(), Ogre::Vector2::normalise(), and Ogre::Vector3::normalise().
Square root function.
fValue | The value, in radians, whose square root will be calculated. |
Definition at line 413 of file OgreMath.h.
References Ogre::Radian::valueRadians().
Square root function.
fValue | The value, in degrees, whose square root will be calculated. |
Definition at line 421 of file OgreMath.h.
References Ogre::Degree::valueDegrees().
|
static |
Generate a random number in the range [-1,1].
Tangent function.
fValue | Angle in radians |
useTables | If true, uses lookup tables rather than calculation - faster but less accurate. |
Definition at line 461 of file OgreMath.h.
References Ogre::Radian::valueRadians().
Tangent function.
fValue | Angle in radians |
useTables | If true, uses lookup tables rather than calculation - faster but less accurate. |
Definition at line 471 of file OgreMath.h.
|
static |
Generate a random number of unit length.
Referenced by Ogre::Vector3::randomDeviant().
|
static |
Definition at line 709 of file OgreMath.h.
|
static |
Definition at line 710 of file OgreMath.h.
|
static |
Definition at line 708 of file OgreMath.h.
|
static |
Stored value of log(2) for frequent use.
Definition at line 346 of file OgreMath.h.
|
staticprotected |
A random value provider. overriding the default random number generator.
Definition at line 229 of file OgreMath.h.
|
staticprotected |
Angle units used by the api.
Definition at line 218 of file OgreMath.h.
|
staticprotected |
Definition at line 225 of file OgreMath.h.
|
staticprotected |
Definition at line 226 of file OgreMath.h.
|
staticprotected |
Radian -> index factor value ( mTrigTableSize / 2 * PI )
Definition at line 224 of file OgreMath.h.
|
staticprotected |
Size of the trig tables as determined by constructor.
Definition at line 221 of file OgreMath.h.
|
static |
Definition at line 705 of file OgreMath.h.
|
static |
Definition at line 706 of file OgreMath.h.
Referenced by Ogre::Vector3::getRotationTo().
|
static |
Definition at line 704 of file OgreMath.h.
Referenced by Ogre::Volume::CSGCubeSource::distanceTo(), Ogre::AxisAlignedBox::getHalfSize(), Ogre::AxisAlignedBox::getSize(), and Ogre::AxisAlignedBox::volume().
|
static |
Definition at line 707 of file OgreMath.h.
Referenced by Ogre::Vector2::angleTo(), and Ogre::Vector3::randomDeviant().