Namespaces | Classes | Typedefs | Enumerations | Functions | Variables

sp::math Namespace Reference

This namespace contains all mathematical basic functions such as sine, cosine, distance calculations etc. More...

Namespaces

namespace  CollisionLibrary
 

Here you will find each function for collision detection, distance computation and intersection tests.


namespace  InterpolatorManager
namespace  Randomizer
 

Namepsace for all random-generation functions.


namespace  Rasterizer
 

Namespace for rasterization templates.


namespace  TriangleCutter

Classes

class  Interpolator
class  FunctionalInterpolator
class  UInt128
class  MD5CheckSum
class  RadianDegreeAngle
class  Degree
 Degree class. An instance of this class will always store a value in the range [0.0 .. 360.0). More...
class  Radian
 Radian class. An instance of this class will always store a value in the range [0.0 .. 2*pi). More...
class  RasterizerVertex
struct  SSplinePolynom
class  Spline
 Multi-dimensional spline class. More...
struct  STriangleCut

Typedefs

typedef FunctionalInterpolator
< f32, f32,&Lerp > 
LinearInterpolator
typedef FunctionalInterpolator
< f32, f32,&LerpParabolic > 
ParabolicInterpolator
typedef FunctionalInterpolator
< f32, f32,&LerpSin > 
SinInterpolator
typedef boost::function< void(s32
x, s32 y, void *UserData) 
RenderPixelCallback )
 Callback function interface for rasterization without vertices.
typedef Spline< dim::point2df,
f32, 2 > 
Spline2D
typedef Spline< dim::vector3df,
f32, 3 > 
Spline3D

Enumerations

enum  ETriangleCutResults { TRIANGLECUT_NONE, TRIANGLECUT_QUAD_AND_TRIANGLE, TRIANGLECUT_TWO_TRIANGLES }
 

Possible results of a triangle clip.

More...

Functions

SP_EXPORT void getVertexInterpolation (const dim::triangle3df &Triangle, const dim::vector3df &Pos, f32 &Vert, f32 &Horz)
SP_EXPORT dim::matrix4f getTangentSpace (const dim::vector3df PosA, const dim::vector3df PosB, const dim::vector3df PosC, const dim::point2df MapA, const dim::point2df MapB, const dim::point2df MapC, dim::vector3df &Tangent, dim::vector3df &Binormal, dim::vector3df &Normal)
template<typename T >
getDistance (const dim::point2d< T > &PosA, const dim::point2d< T > &PosB)
 Returns the distance between the two given 2D points.
template<typename T >
getDistance (const dim::vector3d< T > &PosA, const dim::vector3d< T > &PosB)
 Returns the distance between the two given 3D points.
template<typename T >
getDistanceSq (const dim::point2d< T > &PosA, const dim::point2d< T > &PosB)
template<typename T >
getDistanceSq (const dim::vector3d< T > &PosA, const dim::vector3d< T > &PosB)
template<typename T >
getAngle (const dim::point2d< T > &A, const dim::point2d< T > &B)
template<typename T >
getAngle (const dim::point2d< T > &A, const dim::point2d< T > &B, const T &OffsetAngle)
template<typename T >
dim::vector3d< T > getNormalVectorSq (const dim::vector3d< T > &PosA, const dim::vector3d< T > &PosB, const dim::vector3d< T > &PosC)
 Returns normal vector computed by the three specified coordinates.
template<typename T >
dim::vector3d< T > getNormalVector (const dim::vector3d< T > &PosA, const dim::vector3d< T > &PosB, const dim::vector3d< T > &PosC)
 Returns normalized normal vector computed by the three specified coordinates.
template<typename T >
dim::vector3d< T > getBarycentricCoord (const dim::triangle3d< T > &Triangle, const dim::vector3d< T > &Point)
template<typename T >
void sortContainerConst (std::vector< T > &ObjectList, bool(*lpFuncCmp)(const T &obj1, const T &obj2))
template<typename T >
void sortContainer (std::vector< T > &ObjectList, bool(*lpFuncCmp)(T &obj1, T &obj2))
template<class T >
getVertexInterpolation (const T &VertexA, const T &VertexB, const T &VertexC, const f32 Vert, const f32 Horz)
dim::vector4df Convert (const video::color &Color)
 Returns color in form of a 4D vector. The color components R, G, B, and A are transformed to the range [0.0, 1.0].
video::color Convert (const dim::vector4df &Color)
 Returns color in typical form. The color components R, G, B, and A are transformed to the range [0, 255].
template<typename T >
Abs (const T &Value)
 Returns the absolute value of the given parameter (5 -> 5 and -5 -> 5).
template<typename T >
Max (const T &A, const T &B)
 Returns the largest value of the specified variables.
template<typename T >
Min (const T &A, const T &B)
 Returns the smallest value of the specified variables.
template<typename T >
Max (const T &A, const T &B, const T &C)
 Returns the largest value of the specified variables.
template<typename T >
Min (const T &A, const T &B, const T &C)
 Returns the smallest value of the specified variables.
template<typename T >
void Increase (T &Value, const T &PotNewValue)
 Increase the given value if the potentially new value is greater.
template<typename T >
void Decrease (T &Value, const T &PotNewValue)
 Decrease the given value if the potentially new value is smaller.
template<typename T >
MinMax (const T &Value, const T &Min, const T &Max)
 Returns the input value if it is inside the range "Min" and "Max. Otherwise the clamped range.
template<typename T >
void Clamp (T &Value, const T &Min, const T &Max)
 Clamps the variable "Value" to the range "Min" and "Max".
template<typename T >
void Swap (T &A, T &B)
 Exchanges (or rather swaps) the content of the specified variables A and B.
template<typename T >
Sgn (const T &Value)
 Returns the signed value. Resulting values can only be 1, -1 or 0.
template<typename T >
Round (const T &Value, s32 Precision)
 Returns the rounded value to the specified precision.
template<typename T >
Pow2 (const T &Value)
 Returns the square of the specified value (Value * Value).
template<typename T >
Sin (const T &Value)
 Returns the sine of the specified value as degree.
template<typename T >
Cos (const T &Value)
 Returns the cosine of the specified value as degree.
template<typename T >
Tan (const T &Value)
 Returns the tangent of the specified value as degree.
template<typename T >
ASin (const T &Value)
 Returns the arcus sine of the specified value as degree.
template<typename T >
ACos (const T &Value)
 Returns arcus cosine of the specified value as degree.
template<typename T >
ATan (const T &Value)
 Returns arcus tangent of the specified value as degree.
template<typename T >
Log (const T &Value, const T &Base=T(10))
 Returns the logarithm with the specified base.
template<typename T , typename I >
void Lerp (T &Result, const T &From, const T &To, const I &Factor)
template<typename T , typename I >
Lerp (const T &From, const T &To, const I &Factor)
 Overloaded function. For more information read the documentation of the first variant of this function.
template<typename T , typename I >
LerpParabolic (const T &From, const T &To, const I &Factor)
 Parabolic interpolation. This is equivalent to "Lerp(From, To, Factor*Factor)".
template<typename T , typename I >
LerpSin (const T &From, const T &To, const I &Factor)
 Sine interpolation. This is equivalent to "Lerp(From, To, Sin(Factor*90))".
s32 Round (f32 Value)
 Rounds the float value to the nearest integer value (e.g. 3.4 to 3 and 3.5 to 4).
s32 RoundPow2 (s32 Value)
 Rounds the given value to the nearest power of two value (e.g. 34 to 32 and 120 to 128).
bool Equal (f32 A, f32 B, f32 Tolerance=ROUNDING_ERROR)
 Returns true if A and B are equal with the specified tolerance.
bool Equal (s32 A, s32 B, s32 Tolerance=0)
bool getBitR2L (u32 Integer, s32 Pos)
 Returns the bit inside the specified integer at the specified position (right to left).
void setBitR2L (u32 &Integer, s32 Pos, bool Enable)
 Sets the bit inside the specified integer at the specified position (right to left).
bool getBitL2R (u32 Integer, s32 Pos)
 Returns the bit inside the specified integer at the specified position (left to right).
void setBitL2R (u32 &Integer, s32 Pos, bool Enable)
 Sets the bit inside the specified integer at the specified position (left to right).
bool getBitR2L (u8 Integer, s32 Pos)
 Returns the bit inside the specified integer at the specified position (right to left).
void setBitR2L (u8 &Integer, s32 Pos, bool Enable)
 Sets the bit inside the specified integer at the specified position (right to left).
bool getBitL2R (u8 Integer, s32 Pos)
 Returns the bit inside the specified integer at the specified position (left to right).
void setBitL2R (u8 &Integer, s32 Pos, bool Enable)
 Sets the bit inside the specified integer at the specified position (left to right).
template<typename T >
getTriangleArea2D (const T &x1, const T &y1, const T &x2, const T &y2, const T &x3, const T &y3)
template<typename T >
getBezierValue (const f32 t, const T &Pos1, const T &Pos2, const T &Radial1, const T &Radial2)
 Returns a bezier value used for bezier curves.
template<typename T >
getBernsteinValue (const f32 t, const T Points[4])
 Returns a bernstein value used for bezier patch generation.
template<typename T >
getGaussianValue (const T &X, const T &Mean, const T &StdDeviation)
 Returns a gaussian value used for gaussian blur.
template<typename T >
getHaltonSequence (s32 Index, s32 Base)
template<typename T >
ModularPow (T Base, T Exp, const T &Modulus)

Variables

const f32 DEG = PI / 180.0f
const f32 RAD = 180.0f / PI
const f64 DEG64 = PI64 / 180.0
const f64 RAD64 = 180.0 / PI64
const f64 SQRT2 = sqrt(2.0)
const f32 SQRT2F = sqrtf(2.0f)
const f64 STDASPECT = 4.0 / 3.0

Detailed Description

This namespace contains all mathematical basic functions such as sine, cosine, distance calculations etc.


Typedef Documentation

typedef boost::function<void (s32 x, s32 y, void* UserData) sp::math::RenderPixelCallback)

Callback function interface for rasterization without vertices.


Enumeration Type Documentation

Possible results of a triangle clip.

Enumerator:
TRIANGLECUT_NONE 

The triangle is not cut.

TRIANGLECUT_QUAD_AND_TRIANGLE 

The cut brought out a quadrangle and a triangle.

TRIANGLECUT_TWO_TRIANGLES 

The cut brought out two triangles.


Function Documentation

template<typename T >
T sp::math::Abs ( const T &  Value  )  [inline]

Returns the absolute value of the given parameter (5 -> 5 and -5 -> 5).

template<typename T >
T sp::math::ACos ( const T &  Value  )  [inline]

Returns arcus cosine of the specified value as degree.

template<typename T >
T sp::math::ASin ( const T &  Value  )  [inline]

Returns the arcus sine of the specified value as degree.

template<typename T >
T sp::math::ATan ( const T &  Value  )  [inline]

Returns arcus tangent of the specified value as degree.

template<typename T >
void sp::math::Clamp ( T &  Value,
const T &  Min,
const T &  Max 
) [inline]

Clamps the variable "Value" to the range "Min" and "Max".

dim::vector4df sp::math::Convert ( const video::color &  Color  )  [inline]

Returns color in form of a 4D vector. The color components R, G, B, and A are transformed to the range [0.0, 1.0].

video::color sp::math::Convert ( const dim::vector4df &  Color  )  [inline]

Returns color in typical form. The color components R, G, B, and A are transformed to the range [0, 255].

template<typename T >
T sp::math::Cos ( const T &  Value  )  [inline]

Returns the cosine of the specified value as degree.

template<typename T >
void sp::math::Decrease ( T &  Value,
const T &  PotNewValue 
) [inline]

Decrease the given value if the potentially new value is smaller.

bool sp::math::Equal ( f32  A,
f32  B,
f32  Tolerance = ROUNDING_ERROR 
) [inline]

Returns true if A and B are equal with the specified tolerance.

bool sp::math::Equal ( s32  A,
s32  B,
s32  Tolerance = 0 
) [inline]

Returns true if A and B are equal. The tolerance factor is only used to have the same interface like the floating-point version of this function.

template<typename T >
T sp::math::getAngle ( const dim::point2d< T > &  A,
const dim::point2d< T > &  B,
const T &  OffsetAngle 
)

Returns the angle between the two given 2D points to the offset angle. This is in the range [-180.0 .. 180.0].

template<typename T >
T sp::math::getAngle ( const dim::point2d< T > &  A,
const dim::point2d< T > &  B 
)

Returns the angle between the two given 2D points.

Parameters:
[in] A Specifies the first 2D point.
[in] B Specifies the second 2D point.
Returns:
Angle between the two points. This is in the range [0.0 .. 360.0). If B.X >= A.X and B.Y >= A.Y then the return value is in the range [0.0 .. 90.0). If B.X >= A.X and B.Y < A.Y then the return value is in the range [90.0 .. 180.0). If B.X < A.X and B.Y < A.Y then the return value is in the range [180.0 .. 270.0). If B.X < A.X and B.Y >= A.Y then the return value is in the range [270.0 .. 360.0).
template<typename T >
dim::vector3d<T> sp::math::getBarycentricCoord ( const dim::triangle3d< T > &  Triangle,
const dim::vector3d< T > &  Point 
)

Returns the barycentric coordinate given by the cartesian point respectively to the given triangle.

Parameters:
[in] Triangle Specifies the 3D triangle.
[in] Point Specifies the cartesian point. This point must lie onto the triangle.
Returns:
Barycentric coordinate of the given point respectively to the given triangle.
template<typename T >
T sp::math::getBernsteinValue ( const f32  t,
const T  Points[4] 
)

Returns a bernstein value used for bezier patch generation.

template<typename T >
T sp::math::getBezierValue ( const f32  t,
const T &  Pos1,
const T &  Pos2,
const T &  Radial1,
const T &  Radial2 
)

Returns a bezier value used for bezier curves.

bool sp::math::getBitL2R ( u32  Integer,
s32  Pos 
) [inline]

Returns the bit inside the specified integer at the specified position (left to right).

bool sp::math::getBitL2R ( u8  Integer,
s32  Pos 
) [inline]

Returns the bit inside the specified integer at the specified position (left to right).

bool sp::math::getBitR2L ( u32  Integer,
s32  Pos 
) [inline]

Returns the bit inside the specified integer at the specified position (right to left).

bool sp::math::getBitR2L ( u8  Integer,
s32  Pos 
) [inline]

Returns the bit inside the specified integer at the specified position (right to left).

template<typename T >
T sp::math::getDistance ( const dim::vector3d< T > &  PosA,
const dim::vector3d< T > &  PosB 
) [inline]

Returns the distance between the two given 3D points.

template<typename T >
T sp::math::getDistance ( const dim::point2d< T > &  PosA,
const dim::point2d< T > &  PosB 
) [inline]

Returns the distance between the two given 2D points.

template<typename T >
T sp::math::getDistanceSq ( const dim::point2d< T > &  PosA,
const dim::point2d< T > &  PosB 
) [inline]
Returns:
Suqare distance between two 2D points (used for fast distance comparisions).
template<typename T >
T sp::math::getDistanceSq ( const dim::vector3d< T > &  PosA,
const dim::vector3d< T > &  PosB 
) [inline]
Returns:
Suqare distance between two 3D points (used for fast distance comparisions).
template<typename T >
T sp::math::getGaussianValue ( const T &  X,
const T &  Mean,
const T &  StdDeviation 
)

Returns a gaussian value used for gaussian blur.

template<typename T >
T sp::math::getHaltonSequence ( s32  Index,
s32  Base 
)

Returns the halton sequence for the given input and base. This is used for quasi-random values. For more details take a look at: http://orion.math.iastate.edu/reu/2001/voronoi/halton_sequence.html.

Parameters:
[in] Index Specifies the sequence index.
[in] Base Specifies the sequence base. This has to be a prime number! Usually beginning with 2, 3, etc.
Todo:
This is currently not used and has not been tested!
template<typename T >
dim::vector3d<T> sp::math::getNormalVector ( const dim::vector3d< T > &  PosA,
const dim::vector3d< T > &  PosB,
const dim::vector3d< T > &  PosC 
) [inline]

Returns normalized normal vector computed by the three specified coordinates.

template<typename T >
dim::vector3d<T> sp::math::getNormalVectorSq ( const dim::vector3d< T > &  PosA,
const dim::vector3d< T > &  PosB,
const dim::vector3d< T > &  PosC 
) [inline]

Returns normal vector computed by the three specified coordinates.

SP_EXPORT dim::matrix4f sp::math::getTangentSpace ( const dim::vector3df  PosA,
const dim::vector3df  PosB,
const dim::vector3df  PosC,
const dim::point2df  MapA,
const dim::point2df  MapB,
const dim::point2df  MapC,
dim::vector3df &  Tangent,
dim::vector3df &  Binormal,
dim::vector3df &  Normal 
)
template<typename T >
T sp::math::getTriangleArea2D ( const T &  x1,
const T &  y1,
const T &  x2,
const T &  y2,
const T &  x3,
const T &  y3 
) [inline]

Returns the 2D triangle area.

Note:
This is actually only used inside the dim::triangle3d::getBarycentricCoord function.
SP_EXPORT void sp::math::getVertexInterpolation ( const dim::triangle3df &  Triangle,
const dim::vector3df &  Pos,
f32 &  Vert,
f32 &  Horz 
)
Todo:
Develop this new
template<class T >
T sp::math::getVertexInterpolation ( const T &  VertexA,
const T &  VertexB,
const T &  VertexC,
const f32  Vert,
const f32  Horz 
)
template<typename T >
void sp::math::Increase ( T &  Value,
const T &  PotNewValue 
) [inline]

Increase the given value if the potentially new value is greater.

template<typename T , typename I >
void sp::math::Lerp ( T &  Result,
const T &  From,
const T &  To,
const I &  Factor 
) [inline]

Returns a linear-interpolation ('lerp') between the two given points ('From' and 'To').

Parameters:
[out] Result Specifies the resulting output point.
[in] From Specifies the start point.
[in] To Specifies the end point.
[in] Factor Specifies the interpolation factor. This should be in the range [0.0 .. 1.0].
Template Parameters:
T Specifies the type of the points (e.g. float, dim::point2df, dim::vector3df etc.).
I Specifies the interpolation data type. This should be a float or a double.
See also:
dim::point2d
dim::vector3d
template<typename T , typename I >
T sp::math::Lerp ( const T &  From,
const T &  To,
const I &  Factor 
) [inline]

Overloaded function. For more information read the documentation of the first variant of this function.

template<typename T , typename I >
T sp::math::LerpParabolic ( const T &  From,
const T &  To,
const I &  Factor 
) [inline]

Parabolic interpolation. This is equivalent to "Lerp(From, To, Factor*Factor)".

template<typename T , typename I >
T sp::math::LerpSin ( const T &  From,
const T &  To,
const I &  Factor 
) [inline]

Sine interpolation. This is equivalent to "Lerp(From, To, Sin(Factor*90))".

template<typename T >
T sp::math::Log ( const T &  Value,
const T &  Base = T(10) 
) [inline]

Returns the logarithm with the specified base.

template<typename T >
T sp::math::Max ( const T &  A,
const T &  B 
) [inline]

Returns the largest value of the specified variables.

template<typename T >
T sp::math::Max ( const T &  A,
const T &  B,
const T &  C 
) [inline]

Returns the largest value of the specified variables.

template<typename T >
T sp::math::Min ( const T &  A,
const T &  B,
const T &  C 
) [inline]

Returns the smallest value of the specified variables.

template<typename T >
T sp::math::Min ( const T &  A,
const T &  B 
) [inline]

Returns the smallest value of the specified variables.

template<typename T >
T sp::math::MinMax ( const T &  Value,
const T &  Min,
const T &  Max 
) [inline]

Returns the input value if it is inside the range "Min" and "Max. Otherwise the clamped range.

template<typename T >
T sp::math::ModularPow ( Base,
Exp,
const T &  Modulus 
)

Computes the efficient modular pow value.

Template Parameters:
T This type must support the following operators: %, =, *= and >>=.
Parameters:
[in] Base Specifies the base value.
[in] Exp Specifies the exponent value.
[in] Modulus Specifies the modulus value.
Returns:
'Base' power of 'Exp' modulo 'Modulus'. This is equivalent to '(Base ^ Exp) % Modulus' but faster.
template<typename T >
T sp::math::Pow2 ( const T &  Value  )  [inline]

Returns the square of the specified value (Value * Value).

template<typename T >
T sp::math::Round ( const T &  Value,
s32  Precision 
) [inline]

Returns the rounded value to the specified precision.

s32 sp::math::Round ( f32  Value  )  [inline]

Rounds the float value to the nearest integer value (e.g. 3.4 to 3 and 3.5 to 4).

s32 sp::math::RoundPow2 ( s32  Value  )  [inline]

Rounds the given value to the nearest power of two value (e.g. 34 to 32 and 120 to 128).

void sp::math::setBitL2R ( u32 &  Integer,
s32  Pos,
bool  Enable 
) [inline]

Sets the bit inside the specified integer at the specified position (left to right).

void sp::math::setBitL2R ( u8 &  Integer,
s32  Pos,
bool  Enable 
) [inline]

Sets the bit inside the specified integer at the specified position (left to right).

void sp::math::setBitR2L ( u8 &  Integer,
s32  Pos,
bool  Enable 
) [inline]

Sets the bit inside the specified integer at the specified position (right to left).

void sp::math::setBitR2L ( u32 &  Integer,
s32  Pos,
bool  Enable 
) [inline]

Sets the bit inside the specified integer at the specified position (right to left).

template<typename T >
T sp::math::Sgn ( const T &  Value  )  [inline]

Returns the signed value. Resulting values can only be 1, -1 or 0.

template<typename T >
T sp::math::Sin ( const T &  Value  )  [inline]

Returns the sine of the specified value as degree.

template<typename T >
void sp::math::sortContainer ( std::vector< T > &  ObjectList,
bool(*)(T &obj1, T &obj2)  lpFuncCmp 
)
template<typename T >
void sp::math::sortContainerConst ( std::vector< T > &  ObjectList,
bool(*)(const T &obj1, const T &obj2)  lpFuncCmp 
)
template<typename T >
void sp::math::Swap ( T &  A,
T &  B 
) [inline]

Exchanges (or rather swaps) the content of the specified variables A and B.

template<typename T >
T sp::math::Tan ( const T &  Value  )  [inline]

Returns the tangent of the specified value as degree.


Variable Documentation

const f32 sp::math::DEG = PI / 180.0f
const f64 sp::math::DEG64 = PI64 / 180.0
const f32 sp::math::RAD = 180.0f / PI
const f64 sp::math::RAD64 = 180.0 / PI64
const f64 sp::math::SQRT2 = sqrt(2.0)
const f32 sp::math::SQRT2F = sqrtf(2.0f)
const f64 sp::math::STDASPECT = 4.0 / 3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines