Go to the documentation of this file.
86 ( std::ostream& o,
const Radian& v )
88 o <<
"Radian(" << v.valueRadians() <<
")";
137 ( std::ostream& o,
const Degree& v )
139 o <<
"Degree(" << v.valueDegrees() <<
")";
243 Math(
unsigned int trigTableSize = 4096);
249 static inline int IAbs (
int iValue) {
return ( iValue >= 0 ? iValue : -iValue ); }
250 static inline int ICeil (
float fValue) {
return int(ceil(fValue)); }
251 static inline int IFloor (
float fValue) {
return int(floor(fValue)); }
330 return (!useTables) ?
Real(cos(fValue)) : SinTable(fValue + HALF_PI);
365 static inline float saturate(
float t) {
return (t < 0) ? 0 : ((t > 1) ? 1 : t); }
366 static inline double saturate(
double t) {
return (t < 0) ? 0 : ((t > 1) ? 1 : t); }
371 template<
typename V,
typename T>
static V
lerp(
const V& v0,
const V& v1,
const T& t) {
372 return v0 * (1 - t) + v1 * t; }
392 return (!useTables) ?
Real(sin(fValue)) : SinTable(fValue);
472 return (!useTables) ?
Real(tan(fValue)) : TanTable(fValue);
552 bool discardInside =
true);
608 bool positiveSide =
true,
bool negativeSide =
true);
632 bool positiveSide =
true,
bool negativeSide =
true);
647 bool normalIsOutside);
655 bool normalIsOutside);
665 Real tolerance = std::numeric_limits<Real>::epsilon());
689 template <
typename T>
690 static T
Clamp(T val, T minval, T maxval)
692 assert (minval <= maxval &&
"Invalid clamp range");
693 return std::max(std::min(val, maxval), minval);
697 const Matrix4* reflectMatrix = 0);
This class is used to provide an external random value provider.
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.
static std::pair< bool, Real > intersects(const Ray &ray, const list< Plane >::type &planeList, bool normalIsOutside)
Ray / convex plane list intersection test.
Radian & operator*=(Real f)
Real valueRadians() const
Defines a plane in 3D space.
static Degree Sqrt(const Degree &fValue)
Square root function.
static const Real LOG2
Stored value of log(2) for frequent use.
static int ICeil(float fValue)
static Real Tan(const Radian &fValue, bool useTables=false)
Tangent function.
static Real RangeRandom(Real fLow, Real fHigh)
Generate a random number within the range provided.
Real valueAngleUnits() const
static Degree Abs(const Degree &dValue)
Absolute value function.
static Radian Sqrt(const Radian &fValue)
Square root function.
static Radian ACos(Real fValue)
Arc cosine function.
static void SetRandomValueProvider(RandomValueProvider *provider)
bool operator<=(const Degree &d) const
static std::pair< bool, Real > intersects(const Ray &ray, const Sphere &sphere, bool discardInside=true)
Ray / sphere intersection, returns boolean result and distance.
static bool intersects(const Sphere &sphere, const AxisAlignedBox &box)
Sphere / box intersection test.
bool operator!=(const Radian &r) const
static std::pair< bool, Real > intersects(const Ray &ray, const AxisAlignedBox &box)
Ray / box intersection, returns boolean result and distance.
static Real Cos(const Radian &fValue, bool useTables=false)
Cosine function.
static T Clamp(T val, T minval, T maxval)
Clamp a value within an inclusive range.
static Real boundingRadiusFromAABB(const AxisAlignedBox &aabb)
Get a bounding radius value from a bounding box.
static Real Cos(Real fValue, bool useTables=false)
Cosine function.
Radian operator*(Real a, const Radian &b)
static double saturate(double t)
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.
static Real DegreesToRadians(Real degrees)
static Real Sign(Real fValue)
static Real Exp(Real fValue)
static bool intersects(const Sphere &sphere, const Plane &plane)
Sphere / plane intersection test.
const Degree & operator+() const
virtual ~RandomValueProvider()
static Real TanTable(Real fValue)
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 scal...
bool operator>=(const Degree &d) const
bool operator<=(const Radian &r) const
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.
Radian operator/(Real a, const Radian &b)
static Matrix4 buildReflectionMatrix(const Plane &p)
Build a reflection matrix for the passed in plane.
Class to provide access to common mathematical functions.
bool operator!=(const Degree &d) const
bool operator==(const Radian &r) const
static AngleUnit msAngleUnit
Angle units used by the api.
static float saturate(float t)
static Real Log2(Real fValue)
static bool intersects(const Ray &ray, const AxisAlignedBox &box, Real *d1, Real *d2)
Ray / box intersection, returns boolean result and two intersection distance.
static Radian Sign(const Radian &rValue)
Degree & operator+=(const Degree &d)
static Real Sin(const Radian &fValue, bool useTables=false)
Sine function.
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.
static bool intersects(const Plane &plane, const AxisAlignedBox &box)
Plane / box intersection test.
Wrapper class which indicates a given angle value is in Degrees.
static Vector3 calculateBasicFaceNormalWithoutNormalize(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
Calculate a face normal without normalize, no w-information.
Implementation of a Quaternion, i.e.
static Real AngleUnitsToDegrees(Real units)
Convert from the current AngleUnit to degrees.
Wrapper class which identifies a value as the currently default angle type, as defined by Math::setAn...
static Real Sqrt(Real fValue)
Square root function.
Class encapsulating a standard 4x4 homogeneous matrix.
static Real RadiansToAngleUnits(Real radians)
Convert from radians to the current AngleUnit .
Radian & operator+=(const Radian &r)
const Radian & operator+() const
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 ori...
static int ISign(int iValue)
static int IAbs(int iValue)
static Radian ATan2(Real fY, Real fX)
Arc tangent between two values function.
static Real RadiansToDegrees(Real radians)
Radian operator/(Real f) const
Wrapper class which indicates a given angle value is in Radians.
static const Real fRad2Deg
static Real DegreesToAngleUnits(Real degrees)
Convert from degrees to the current AngleUnit.
static Real InvSqrt(Real fValue)
Inverse square root i.e.
A 3D box aligned with the x/y/z axes.
static const Real POS_INFINITY
static const Real HALF_PI
static std::pair< bool, Real > intersects(const Ray &ray, const vector< Plane >::type &planeList, bool normalIsOutside)
Ray / convex plane list intersection test.
static Matrix4 makeViewMatrix(const Vector3 &position, const Quaternion &orientation, const Matrix4 *reflectMatrix=0)
Radian operator*(Real f) const
static bool isNaN(Real f)
Real valueRadians() const
~Math()
Default destructor.
A sphere primitive, mostly used for bounds checking.
Radian & operator/=(Real f)
static Real Floor(Real fValue)
Floor function Returns the largest previous integer.
static Real mTrigTableFactor
Radian -> index factor value ( mTrigTableSize / 2 * PI )
static Real Pow(Real fBase, Real fExponent)
Degree operator/(Real f) const
static Radian Abs(const Radian &rValue)
Absolute value function.
static const Real NEG_INFINITY
static Real Log(Real fValue)
virtual Real getRandomUnit()=0
When called should return a random values in the range of [0,1].
Degree & operator/=(Real f)
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
bool operator>(const Degree &d) const
4-dimensional homogeneous vector.
bool operator<(const Degree &d) const
Radian & operator-=(const Radian &r)
AngleUnit
The angular units used by the API.
Standard 2-dimensional vector.
bool operator>=(const Radian &r) const
static RandomValueProvider * mRandProvider
A random value provider. overriding the default random number generator.
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 AngleUnit getAngleUnit(void)
Get the unit being used for angles.
bool operator>(const Radian &r) const
static Degree Sign(const Degree &dValue)
Real valueDegrees() const
static Radian ASin(Real fValue)
Arc sine function.
Radian & operator=(const Real &f)
static Real AngleUnitsToRadians(Real units)
Convert from the current AngleUnit to radians.
void buildTrigTables()
Private function to build trig tables.
static void setAngleUnit(AngleUnit unit)
These functions used to set the assumed angle units (radians or degrees) expected when using the Angl...
static Vector3 calculateBasicFaceNormal(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
Calculate a face normal, no w-information.
static V lerp(const V &v0, const V &v1, const T &t)
static Real Ceil(Real fValue)
Ceiling function Returns the smallest following integer.
float Real
Software floating point type.
static int IFloor(float fValue)
Degree & operator=(const Real &f)
static const Real fDeg2Rad
bool operator==(const Degree &d) const
Real valueAngleUnits() const
static bool RealEqual(Real a, Real b, Real tolerance=std::numeric_limits< Real >::epsilon())
Compare 2 reals, using tolerance for inaccuracies.
static Real LogN(Real base, Real fValue)
static Real Sin(Real fValue, bool useTables=false)
Sine function.
Representation of a ray in space, i.e.
static int mTrigTableSize
Size of the trig tables as determined by constructor.
Real valueDegrees() const
static Real UnitRandom()
Generate a random number of unit length.
Degree & operator-=(const Degree &d)
bool operator<(const Radian &r) const
static Real Abs(Real fValue)
Absolute value function.
Standard 3-dimensional vector.
Degree & operator*=(Real f)
static Real Sqr(Real fValue)
Squared function.
static Real SinTable(Real fValue)
static Real Tan(Real fValue, bool useTables=false)
Tangent function.
static Real SymmetricRandom()
Generate a random number in the range [-1,1].
Math(unsigned int trigTableSize=4096)
Default constructor.
static Radian ATan(Real fValue)
Arc tangent function.
Degree operator*(Real f) const
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.
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.