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. |
Math functions namespace.
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.
[out] | result | The result vector |
[in] | vector0 | The first vector |
[in] | vector1 | The second vector |
GLfloat VR3Math::Determinant4x4 | ( | const GLfloat | m[16] ) |
Computes the determinant of a 4x4 matrix.
[in] | m | 4x4 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.
[in] | vector0 | The first vector |
[in] | vector1 | The second vector |
GLfloat VR3Math::EuclideanNorm3 | ( | const GLfloat | x, |
const GLfloat | y, | ||
const GLfloat | z | ||
) |
Computes the euclidean norm of a 3-components vector.
[in] | x,y,z | The 3 components of the given vector |
GLfloat VR3Math::EuclideanNorm3 | ( | const GLfloat | vector[3] ) |
Computes the euclidean norm of a 3-components vector.
[in] | vector | The 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.
[out] | result | Resulting projection matrix |
[in] | left,right | The coordinates for the left and right vertical clipping planes |
[in] | bottom,top | The coordinates for the bottom and top horizontal clipping planes |
[in] | nearVal,farVal | The 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.
[in] | m | The matrix to invert |
[out] | result | The result matrix |
GLvoid VR3Math::LoadIdentity4x4 | ( | GLfloat | matrix[16] ) |
Loads an identity 4x4 matrix.
Loads a 4x4 identity matrix into the matrix out parameter.
[in,out] | matrix | The 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.
[out] | result | The resulting rototranslation matrix |
[in] | eyeX,eyeY,eyeZ | The eye (camera) position |
[in] | centerX,centerY,centerZ | The target center position |
[in] | upX,upY,upZ | The 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).
[in] | matrix | The 4x4 matrix |
[in] | vector | The 3-components vector |
[out] | result | The 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.
[in] | matrix | The 4x4 matrix |
[in] | vector | The 4-components vector |
[out] | result | The 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.
[in] | matrix0 | The first matrix |
[in] | matrix1 | The second matrix |
[out] | matrix | The resulting matrix (matrix0*matrix1) |
GLvoid VR3Math::Normalize3 | ( | GLfloat | vector[3] ) |
Normalizes a 3-components vector.
[in,out] | vector | The 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.
[out] | result | Resulting projection matrix |
[in] | left,right | Coordinates for the left and right vertical clipping planes |
[in] | bottom,top | Coordinates for the bottom and top horizontal clipping planes |
[in] | nearVal,farVal | Distances 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.
[out] | result | Resulting projection matrix |
[in] | fovy | The field of view angle in the y direction (degrees) |
[in] | aspect | The aspect ratio that determines the field of view in the x direction (width/height) |
[in] | zNear | The distance from the viewer to the near clipping plane (always positive) |
[in] | zFar | The 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.
[in,out] | matrix | The resulting altered matrix |
[in] | angle | The rotation angle |
[in] | x,y,z | The 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:
[in,out] | matrix | The resulting altered matrix |
[in] | ax,ay,az | The 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.
[in,out] | matrix | The resulting altered matrix |
[in] | x,y,z | The 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.
[in,out] | matrix | The resulting altered matrix |
[in] | x,y,z | The 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.
[in] | vertex1,vertex2,vertex3 | Triangle vertices |
[out] | normal | The normal vector |