VR3Math Namespace Reference

Math functions namespace. More...

Functions

3-Components Vectors
GLvoid Cross3 (GLfloat result[3], const GLfloat vector0[3], const GLfloat vector1[3])
 Computes the cross product of two 3-components vectors.
GLfloat Dot3 (const GLfloat vector0[3], const GLfloat vector1[3])
 Computes the dot product of two 3-components vectors.
GLfloat EuclideanNorm3 (const GLfloat vector[3])
 Computes the euclidean norm of a 3-components vector.
GLfloat EuclideanNorm3 (const GLfloat x, const GLfloat y, const GLfloat z)
 Computes the euclidean norm of a 3-components vector.
GLvoid Normalize3 (GLfloat vector[3])
 Normalizes a 3-components vector.
4x4 Matrices
GLfloat Determinant4x4 (const GLfloat m[16])
 Computes the determinant of a 4x4 matrix.
GLboolean InvertMatrix4x4 (GLfloat result[16], const GLfloat m[16])
 Inverts a 4x4 matrix.
GLvoid MultMatrix4x4 (GLfloat matrix[16], const GLfloat matrix0[16], const GLfloat matrix1[16])
 Multiplies two 4x4 matrices.
GLvoid LoadIdentity4x4 (GLfloat matrix[16])
 Loads an identity 4x4 matrix.
GLvoid Rotate4x4 (GLfloat matrix[16], GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 Combines a rototranslation matrix with a new rotation obtained using and angle and an axis.
GLvoid RotateAngles4x4 (GLfloat matrix[16], GLfloat ax, GLfloat ay, GLfloat az)
 Combines a rototranslation matrix with a new rotation obtained using three angles.
GLvoid Translate4x4 (GLfloat matrix[16], GLfloat x, GLfloat y, GLfloat z)
 Combines a rototranslation matrix with a new translation matrix.
GLvoid Scale4x4 (GLfloat matrix[16], GLfloat x, GLfloat y, GLfloat z)
 Combines a rototranslation matrix with a new scale matrix.
GLvoid LookAt4x4 (GLfloat result[16], GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ)
 Initializes a rototranslation matrix to look at a specified point.
GLvoid Ortho4x4 (GLfloat result[16], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal)
 Sets up an orthogonal projection matrix.
GLvoid Perspective4x4 (GLfloat result[16], GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
 Sets up a perspective projection matrix.
GLvoid Frustum4x4 (GLfloat result[16], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal)
 Prepare perspective matrix that produces a perspective projection.
Matrices and vectors
GLvoid MultMat4x4Vector3 (GLfloat result[3], const GLfloat matrix[16], const GLfloat vector[3])
 Multiplies a transformation matrix to a 3-components vector.
GLvoid MultMat4x4Vector4 (GLfloat result[4], const GLfloat matrix[16], const GLfloat vector[4])
 Multiplies a transformation matrix to a 4-components vector.
void TriangleNormal (const GLfloat *vertex1, const GLfloat *vertex2, const GLfloat *vertex3, GLfloat *normal)
 Computes the normal vector for a given triangle.

Detailed Description

Math functions namespace.


Function Documentation

GLvoid VR3Math::Cross3 ( GLfloat  result[3],
const GLfloat  vector0[3],
const GLfloat  vector1[3] 
)

Computes the cross product of two 3-components vectors.

The product is written in the result out parameter, no strange behaviour will arise if the vector used to store the result is also one of the operands.

Parameters:
[out]resultThe result vector
[in]vector0The first vector
[in]vector1The second vector
GLfloat VR3Math::Determinant4x4 ( const GLfloat  m[16] )

Computes the determinant of a 4x4 matrix.

Parameters:
[in]m4x4 GLfloat matrix
GLfloat VR3Math::Dot3 ( const GLfloat  vector0[3],
const GLfloat  vector1[3] 
)

Computes the dot product of two 3-components vectors.

The product is returned by this function.

Parameters:
[in]vector0The first vector
[in]vector1The second vector
GLfloat VR3Math::EuclideanNorm3 ( const GLfloat  x,
const GLfloat  y,
const GLfloat  z 
)

Computes the euclidean norm of a 3-components vector.

Parameters:
[in]x,y,zThe 3 components of the given vector
GLfloat VR3Math::EuclideanNorm3 ( const GLfloat  vector[3] )

Computes the euclidean norm of a 3-components vector.

Parameters:
[in]vectorThe given 3-components vector
GLvoid VR3Math::Frustum4x4 ( GLfloat  result[16],
GLfloat  left,
GLfloat  right,
GLfloat  bottom,
GLfloat  top,
GLfloat  nearVal,
GLfloat  farVal 
)

Prepare perspective matrix that produces a perspective projection.

Sets up a projection matrix according to the specified parameters.

Parameters:
[out]resultResulting projection matrix
[in]left,rightThe coordinates for the left and right vertical clipping planes
[in]bottom,topThe coordinates for the bottom and top horizontal clipping planes
[in]nearVal,farValThe distances to the near and far depth clipping planes
GLboolean VR3Math::InvertMatrix4x4 ( GLfloat  result[16],
const GLfloat  m[16] 
)

Inverts a 4x4 matrix.

Computes the invert matrix of a 4x4 GLfloat matrix. The operation is not always possible, if the inversion is impossible the return value states the failure. Please note that if the result matrix and the input matrix are the same, the operation will work as expected.

Parameters:
[in]mThe matrix to invert
[out]resultThe result matrix
Returns:
GL_TRUE on success, GL_FALSE on failure
GLvoid VR3Math::LoadIdentity4x4 ( GLfloat  matrix[16] )

Loads an identity 4x4 matrix.

Loads a 4x4 identity matrix into the matrix out parameter.

Parameters:
[in,out]matrixThe matrix where to load identity matrix
GLvoid VR3Math::LookAt4x4 ( GLfloat  result[16],
GLfloat  eyeX,
GLfloat  eyeY,
GLfloat  eyeZ,
GLfloat  centerX,
GLfloat  centerY,
GLfloat  centerZ,
GLfloat  upX,
GLfloat  upY,
GLfloat  upZ 
)

Initializes a rototranslation matrix to look at a specified point.

The resulting matrix is stored in the result GLfloat array, the eye position may be specified using the eye parameters while the target center is expressed using the center parameters. The up vector is used to understand the camera orientation.

Parameters:
[out]resultThe resulting rototranslation matrix
[in]eyeX,eyeY,eyeZThe eye (camera) position
[in]centerX,centerY,centerZThe target center position
[in]upX,upY,upZThe camera up vector
GLvoid VR3Math::MultMat4x4Vector3 ( GLfloat  result[3],
const GLfloat  matrix[16],
const GLfloat  vector[3] 
)

Multiplies a transformation matrix to a 3-components vector.

No strange behaviour will arise if the vector used to store the result is also one of the operands. We assume that the 3 component vector is the first part of a homogenous coordinate vector (x,y,z,w) and that w is 1.0f, we do not compute the last component of the resulting 4 components vector assuming that it will be 1.0f (this means that this operation is only useful for modeling and viewing transformation but not with perspective projection matrices).

Parameters:
[in]matrixThe 4x4 matrix
[in]vectorThe 3-components vector
[out]resultThe resulting vector = matrix*vector
GLvoid VR3Math::MultMat4x4Vector4 ( GLfloat  result[4],
const GLfloat  matrix[16],
const GLfloat  vector[4] 
)

Multiplies a transformation matrix to a 4-components vector.

No strange behaviour will arise if the vector used to store the result is also one of the operands.

Parameters:
[in]matrixThe 4x4 matrix
[in]vectorThe 4-components vector
[out]resultThe resulting vector = matrix*vector
GLvoid VR3Math::MultMatrix4x4 ( GLfloat  matrix[16],
const GLfloat  matrix0[16],
const GLfloat  matrix1[16] 
)

Multiplies two 4x4 matrices.

Two matrices are multiplied and the result is copied in a new GLfloat vector. Please note that if one of the matrices or both are used as input matrix AND output matrix the operation will work as expected.

Parameters:
[in]matrix0The first matrix
[in]matrix1The second matrix
[out]matrixThe resulting matrix (matrix0*matrix1)
GLvoid VR3Math::Normalize3 ( GLfloat  vector[3] )

Normalizes a 3-components vector.

Parameters:
[in,out]vectorThe given 3-components vector
GLvoid VR3Math::Ortho4x4 ( GLfloat  result[16],
GLfloat  left,
GLfloat  right,
GLfloat  bottom,
GLfloat  top,
GLfloat  nearVal,
GLfloat  farVal 
)

Sets up an orthogonal projection matrix.

Sets up a projection matrix according to the specified parameters.

Parameters:
[out]resultResulting projection matrix
[in]left,rightCoordinates for the left and right vertical clipping planes
[in]bottom,topCoordinates for the bottom and top horizontal clipping planes
[in]nearVal,farValDistances to the nearer and farther depth clipping planes, these values are negative if the plane is to be behind the viewer
GLvoid VR3Math::Perspective4x4 ( GLfloat  result[16],
GLfloat  fovy,
GLfloat  aspect,
GLfloat  zNear,
GLfloat  zFar 
)

Sets up a perspective projection matrix.

Sets up a projection matrix according to the specified parameters.

Parameters:
[out]resultResulting projection matrix
[in]fovyThe field of view angle in the y direction (degrees)
[in]aspectThe aspect ratio that determines the field of view in the x direction (width/height)
[in]zNearThe distance from the viewer to the near clipping plane (always positive)
[in]zFarThe distance from the viewer to the far clipping plane (always positive)
GLvoid VR3Math::Rotate4x4 ( GLfloat  matrix[16],
GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Combines a rototranslation matrix with a new rotation obtained using and angle and an axis.

Post-multiplies the given matrix with the rotation matrix obtained by rotating angle degrees around the (x,y,z) axis.

Parameters:
[in,out]matrixThe resulting altered matrix
[in]angleThe rotation angle
[in]x,y,zThe rotation axis components
GLvoid VR3Math::RotateAngles4x4 ( GLfloat  matrix[16],
GLfloat  ax,
GLfloat  ay,
GLfloat  az 
)

Combines a rototranslation matrix with a new rotation obtained using three angles.

Post-multiplies the given matrix with the rotation matrix obtained by rotating according to the angles in the following order:

  • rotate ax degrees around the X axis (roll)
  • rotate ay degrees around the Y axis (pitch)
  • rotate az degrees around the Z axis (yaw)
Parameters:
[in,out]matrixThe resulting altered matrix
[in]ax,ay,azThe rotation angles
GLvoid VR3Math::Scale4x4 ( GLfloat  matrix[16],
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Combines a rototranslation matrix with a new scale matrix.

Post-multiplies the given matrix with the scale matrix obtained by scaling by (x,y,z) on the three axis.

Parameters:
[in,out]matrixThe resulting altered matrix
[in]x,y,zThe scaling factors
GLvoid VR3Math::Translate4x4 ( GLfloat  matrix[16],
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Combines a rototranslation matrix with a new translation matrix.

Post-multiplies the given matrix with the translation matrix obtained by translating by the (x,y,z) vector.

Parameters:
[in,out]matrixThe resulting altered matrix
[in]x,y,zThe translation vector components
void VR3Math::TriangleNormal ( const GLfloat *  vertex1,
const GLfloat *  vertex2,
const GLfloat *  vertex3,
GLfloat *  normal 
)

Computes the normal vector for a given triangle.

Parameters:
[in]vertex1,vertex2,vertex3Triangle vertices
[out]normalThe normal vector
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines