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