CUGL 2.3
Cornell University Game Library
|
#include <CUMat4.h>
Public Member Functions | |
Mat4 () | |
Mat4 (float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) | |
Mat4 (const float *mat) | |
Mat4 (const Mat4 ©) | |
Mat4 (Mat4 &©) | |
Mat4 (const Quaternion &rotation) | |
~Mat4 () | |
Mat4 & | operator= (const Mat4 &mat) |
Mat4 & | operator= (Mat4 &&mat) |
Mat4 & | operator= (const float *array) |
Mat4 & | operator= (const Quaternion &quat) |
Mat4 & | set (float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) |
Mat4 & | set (const float *mat) |
Mat4 & | set (const Quaternion &quat) |
Mat4 & | set (const Mat4 &mat) |
Mat4 & | setIdentity () |
Mat4 & | setZero () |
Mat4 & | add (float scalar) |
Mat4 & | add (const Mat4 &mat) |
Mat4 & | subtract (float scalar) |
Mat4 & | subtract (const Mat4 &mat) |
Mat4 & | multiply (float scalar) |
Mat4 & | multiply (const Mat4 &mat) |
Mat4 & | negate () |
Mat4 | getNegation () const |
Mat4 & | invert () |
Mat4 | getInverse () const |
Mat4 & | transpose () |
Mat4 | getTranspose () const |
Mat4 & | operator+= (const Mat4 &mat) |
Mat4 & | operator-= (const Mat4 &mat) |
Mat4 & | operator*= (const Mat4 &mat) |
Mat4 & | operator*= (float scalar) |
const Mat4 | operator+ (const Mat4 &mat) const |
const Mat4 | operator- (const Mat4 &mat) const |
const Mat4 | operator- () const |
const Mat4 | operator* (const Mat4 &mat) const |
const Mat4 | operator* (float scalar) const |
bool | isExactly (const Mat4 &mat) const |
bool | equals (const Mat4 &mat, float epsilon=CU_MATH_EPSILON) const |
bool | operator== (const Mat4 &mat) const |
bool | operator!= (const Mat4 &mat) const |
bool | isIdentity (float epsilon=CU_MATH_EPSILON) const |
bool | isInvertible (float epsilon=CU_MATH_EPSILON) const |
bool | isOrthogonal (float epsilon=CU_MATH_EPSILON) const |
float | getDeterminant () const |
Vec3 | getScale () const |
Quaternion | getRotation () const |
Vec3 | getTranslation () const |
Vec3 | getUpVector () const |
Vec3 | getDownVector () const |
Vec3 | getLeftVector () const |
Vec3 | getRightVector () const |
Vec3 | getForwardVector () const |
Vec3 | getBackVector () const |
Vec2 | transform (const Vec2 point) const |
Rect | transform (const Rect rect) const |
Vec2 | transformVector (const Vec2 vec) const |
Vec3 | transform (const Vec3 point) const |
Vec3 | transformVector (const Vec3 vec) const |
Vec4 | transform (const Vec4 vec) const |
Mat4 & | rotate (const Quaternion &q) |
Mat4 & | rotate (const Vec3 axis, float angle) |
Mat4 & | rotateX (float angle) |
Mat4 & | rotateY (float angle) |
Mat4 & | rotateZ (float angle) |
Mat4 & | scale (float value) |
Mat4 & | scale (const Vec3 s) |
Mat4 & | scale (float sx, float sy, float sz) |
Mat4 & | translate (const Vec3 t) |
Mat4 & | translate (float tx, float ty, float tz) |
std::string | toString (bool verbose=false) const |
operator std::string () const | |
operator Affine2 () const | |
Mat4 (const Affine2 &aff) | |
Mat4 & | operator= (const Affine2 &aff) |
Mat4 & | set (const Affine2 &aff) |
Static Public Member Functions | |
static Mat4 | createLookAt (const Vec3 eye, const Vec3 target, const Vec3 up) |
static Mat4 * | createLookAt (const Vec3 eye, const Vec3 target, const Vec3 up, Mat4 *dst) |
static Mat4 | createLookAt (float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ) |
static Mat4 * | createLookAt (float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, Mat4 *dst) |
static Mat4 | createPerspective (float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane) |
static Mat4 * | createPerspective (float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4 *dst) |
static Mat4 | createOrthographic (float width, float height, float zNearPlane, float zFarPlane) |
static Mat4 * | createOrthographic (float width, float height, float zNearPlane, float zFarPlane, Mat4 *dst) |
static Mat4 | createOrthographicOffCenter (float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) |
static Mat4 * | createOrthographicOffCenter (float left, float right, float bottom, float top, float zNearPlane, float zFarPlane, Mat4 *dst) |
static Mat4 | createScale (float scale) |
static Mat4 * | createScale (float scale, Mat4 *dst) |
static Mat4 | createScale (float sx, float sy, float sz) |
static Mat4 * | createScale (float sx, float sy, float sz, Mat4 *dst) |
static Mat4 | createScale (const Vec3 scale) |
static Mat4 * | createScale (const Vec3 scale, Mat4 *dst) |
static Mat4 | createRotation (const Quaternion &quat) |
static Mat4 * | createRotation (const Quaternion &quat, Mat4 *dst) |
static Mat4 | createRotation (const Vec3 axis, float angle) |
static Mat4 * | createRotation (const Vec3 axis, float angle, Mat4 *dst) |
static Mat4 | createRotationX (float angle) |
static Mat4 * | createRotationX (float angle, Mat4 *dst) |
static Mat4 | createRotationY (float angle) |
static Mat4 * | createRotationY (float angle, Mat4 *dst) |
static Mat4 | createRotationZ (float angle) |
static Mat4 * | createRotationZ (float angle, Mat4 *dst) |
static Mat4 | createTranslation (const Vec3 trans) |
static Mat4 * | createTranslation (const Vec3 trans, Mat4 *dst) |
static Mat4 | createTranslation (float tx, float ty, float tz) |
static Mat4 * | createTranslation (float tx, float ty, float tz, Mat4 *dst) |
static Mat4 * | add (const Mat4 &mat, float scalar, Mat4 *dst) |
static float * | add (const float *mat, float scalar, float *dst) |
static Mat4 * | add (const Mat4 &m1, const Mat4 &m2, Mat4 *dst) |
static float * | add (const float *m1, const float *m2, float *dst) |
static Mat4 * | subtract (const Mat4 &mat, float scalar, Mat4 *dst) |
static float * | subtract (const float *mat, float scalar, float *dst) |
static Mat4 * | subtract (const Mat4 &m1, const Mat4 &m2, Mat4 *dst) |
static float * | subtract (const float *m1, const float *m2, float *dst) |
static Mat4 * | multiply (const Mat4 &mat, float scalar, Mat4 *dst) |
static float * | multiply (const float *mat, float scalar, float *dst) |
static Mat4 * | multiply (const Mat4 &m1, const Mat4 &m2, Mat4 *dst) |
static float * | multiply (const float *m1, const float *m2, float *dst) |
static Mat4 * | negate (const Mat4 &m1, Mat4 *dst) |
static float * | negate (const float *m1, float *dst) |
static Mat4 * | invert (const Mat4 &m1, Mat4 *dst) |
static float * | invert (const float *m1, float *dst) |
static Mat4 * | transpose (const Mat4 &m1, Mat4 *dst) |
static float * | transpose (const float *m1, float *dst) |
static Vec2 * | transform (const Mat4 &mat, const Vec2 point, Vec2 *dst) |
static float * | transform (const Mat4 &mat, const Vec2 point, float *dst) |
static Rect * | transform (const Mat4 &mat, const Rect rect, Rect *dst) |
static Vec2 * | transformVector (const Mat4 &mat, const Vec2 vec, Vec2 *dst) |
static Vec3 * | transform (const Mat4 &mat, const Vec3 point, Vec3 *dst) |
static Vec3 * | transformVector (const Mat4 &mat, const Vec3 vec, Vec3 *dst) |
static Vec4 * | transform (const Mat4 &mat, const Vec4 vec, Vec4 *dst) |
static float * | transform (const Mat4 &mat, float const *input, float *output, size_t size) |
static float * | transform (const float *mat, float const *input, float *output, size_t size) |
static Mat4 * | rotate (const Mat4 &mat, const Quaternion &quat, Mat4 *dst) |
static Mat4 * | rotate (const Mat4 &mat, const Vec3 axis, float angle, Mat4 *dst) |
static Mat4 * | rotateX (const Mat4 &mat, float angle, Mat4 *dst) |
static Mat4 * | rotateY (const Mat4 &mat, float angle, Mat4 *dst) |
static Mat4 * | rotateZ (const Mat4 &mat, float angle, Mat4 *dst) |
static Mat4 * | scale (const Mat4 &mat, float value, Mat4 *dst) |
static Mat4 * | scale (const Mat4 &mat, const Vec3 s, Mat4 *dst) |
static Mat4 * | scale (const Mat4 &mat, float sx, float sy, float sz, Mat4 *dst) |
static Mat4 * | translate (const Mat4 &mat, const Vec3 t, Mat4 *dst) |
static Mat4 * | translate (const Mat4 &mat, float tx, float ty, float tz, Mat4 *dst) |
static bool | decompose (const Mat4 &mat, Vec3 *scale, Quaternion *rot, Vec3 *trans) |
Public Attributes | |
float | m [16] |
Static Public Attributes | |
static const Mat4 | ZERO |
static const Mat4 | ONE |
static const Mat4 | IDENTITY |
This class defines a 4 x 4 floating point matrix representing a 3D transformation.
Vectors are treated as columns, resulting in a matrix that is represented as follows, where x, y and z are the translation components of the matrix:
1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1
This matrix class is directly compatible with OpenGL since its elements are laid out in memory exactly as they are expected by OpenGL.
The matrix uses column-major format such that array indices increase down column first. However, this is only a data representation format, and it should not have any affect on issues such as multiplication order.
With that said, the convention in OpenGL (and respected by this class) is that transforms are applied by multiplying a vector on the right. For example, suppose we have a translation matrix T and a rotation matrix R. To first rotate an object around the origin and then translate it, you would multiply the two matrices as RT, with T on the right.
cugl::Mat4::Mat4 | ( | ) |
Creates the identity matrix.
1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
cugl::Mat4::Mat4 | ( | float | m11, |
float | m12, | ||
float | m13, | ||
float | m14, | ||
float | m21, | ||
float | m22, | ||
float | m23, | ||
float | m24, | ||
float | m31, | ||
float | m32, | ||
float | m33, | ||
float | m34, | ||
float | m41, | ||
float | m42, | ||
float | m43, | ||
float | m44 | ||
) |
Constructs a matrix initialized to the specified values.
m11 | The first element of the first row. |
m12 | The second element of the first row. |
m13 | The third element of the first row. |
m14 | The fourth element of the first row. |
m21 | The first element of the second row. |
m22 | The second element of the second row. |
m23 | The third element of the second row. |
m24 | The fourth element of the second row. |
m31 | The first element of the third row. |
m32 | The second element of the third row. |
m33 | The third element of the third row. |
m34 | The fourth element of the third row. |
m41 | The first element of the fourth row. |
m42 | The second element of the fourth row. |
m43 | The third element of the fourth row. |
m44 | The fourth element of the fourth row. |
cugl::Mat4::Mat4 | ( | const float * | mat | ) |
Creates a matrix initialized to the specified column-major array.
The passed-in array is in column-major order, so the memory layout of the array is as follows:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
mat | An array containing 16 elements in column-major order. |
cugl::Mat4::Mat4 | ( | const Mat4 & | copy | ) |
Constructs a new matrix that is the copy of the specified one.
copy | The matrix to copy. |
cugl::Mat4::Mat4 | ( | Mat4 && | copy | ) |
Constructs a new matrix that contains the resources of the specified one.
copy | The matrix contributing resources. |
|
inline |
Constructs a new matrix that is specified by the given quaternion.
rotation | The quaternion specifying a rotation. |
|
inline |
Destroys this matrix, releasing all resources.
|
explicit |
Creates a matrix from the given affine transform.
The z values are set to the identity.
aff | The transform to convert |
|
static |
Adds the specified matrices and stores the result in dst.
This method assumes the float arrays are in column major order.
m1 | The first matrix in column-major order |
m2 | The second matrix in column-major order |
dst | The destination matrix in column-major order |
|
static |
Adds a scalar to each component of mat and stores the result in dst.
This method assumes the float arrays are in column major order.
mat | The matrix to add to in column-major order |
scalar | The scalar value to add. |
dst | A matrix to store the result in column-major order |
Adds the specified matrices and stores the result in dst.
m1 | The first matrix. |
m2 | The second matrix. |
dst | The destination matrix to add to. |
Adds the specified matrix to this matrix.
mat | The matrix to add. |
Adds a scalar to each component of mat and stores the result in dst.
mat | The matrix to add to. |
scalar | The scalar value to add. |
dst | A matrix to store the result in. |
|
inline |
Adds a scalar value to each component of this matrix.
scalar | The scalar to add. |
|
inlinestatic |
Creates a view matrix based on the specified input vectors.
eye | The eye position. |
target | The target's center position. |
up | The up vector. |
|
static |
Creates a view matrix based on the specified input vectors, putting it in dst.
eye | The eye position. |
target | The target's center position. |
up | The up vector. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a view matrix based on the specified input parameters.
eyeX | The eye x-coordinate position. |
eyeY | The eye y-coordinate position. |
eyeZ | The eye z-coordinate position. |
targetX | The target's center x-coordinate position. |
targetY | The target's center y-coordinate position. |
targetZ | The target's center z-coordinate position. |
upX | The up vector x-coordinate value. |
upY | The up vector y-coordinate value. |
upZ | The up vector z-coordinate value. |
|
static |
Creates a view matrix based on the specified input parameters, putting it in dst.
eyeX | The eye x-coordinate position. |
eyeY | The eye y-coordinate position. |
eyeZ | The eye z-coordinate position. |
targetX | The target's center x-coordinate position. |
targetY | The target's center y-coordinate position. |
targetZ | The target's center z-coordinate position. |
upX | The up vector x-coordinate value. |
upY | The up vector y-coordinate value. |
upZ | The up vector z-coordinate value. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns an orthographic projection matrix anchored at the origin.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x and y coordinates ranging from -1 to 1, and z coordinates ranging from 0 to 1. Unlike perspective projection, there is no perspective foreshortening in orthographic projection.
The viewable area of this orthographic projection places the origin at the center, with the given width and height.. The z-axis is bound between zNearPlane and zFarPlane. These values are relative to the position and x, y, and z-axes of the view.
To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
width | The width of the view. |
height | The height of the view. |
zNearPlane | The minimum z-value of the view volume. |
zFarPlane | The maximum z-value of the view volume. |
|
inlinestatic |
Creates an orthographic projection matrix anchored at the origin, putting it in dst.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x and y coordinates ranging from -1 to 1, and z coordinates ranging from 0 to 1. Unlike perspective projection, there is no perspective foreshortening in orthographic projection.
The viewable area of this orthographic projection places the origin at the center, with the given width and height.. The z-axis is bound between zNearPlane and zFarPlane. These values are relative to the position and x, y, and z-axes of the view.
To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
width | The width of the view. |
height | The height of the view. |
zNearPlane | The minimum z-value of the view volume. |
zFarPlane | The maximum z-value of the view volume. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns an orthographic projection matrix.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x and y coordinates ranging from -1 to 1, and z coordinates ranging from 0 to 1. Unlike perspective projection, there is no perspective foreshortening in orthographic projection.
The viewable area of this orthographic projection extends from left to right on the x-axis and bottom to top on the y-axis. The z-axis is bound between zNearPlane and zFarPlane. These values are relative to the position and x, y, and z-axes of the view.
To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
left | The minimum x-value of the view volume. |
right | The maximum x-value of the view volume. |
bottom | The minimum y-value of the view volume. |
top | The maximum y-value of the view volume. |
zNearPlane | The minimum z-value of the view volume. |
zFarPlane | The maximum z-value of the view volume. |
|
static |
Creates an orthographic projection matrix, putting it in dst.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x and y coordinates ranging from -1 to 1, and z coordinates ranging from 0 to 1. Unlike perspective projection, there is no perspective foreshortening in orthographic projection.
The viewable area of this orthographic projection extends from left to right on the x-axis and bottom to top on the y-axis. The z-axis is bound between zNearPlane and zFarPlane. These values are relative to the position and x, y, and z-axes of the view.
To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
left | The minimum x-value of the view volume. |
right | The maximum x-value of the view volume. |
bottom | The minimum y-value of the view volume. |
top | The maximum y-value of the view volume. |
zNearPlane | The minimum z-value of the view volume. |
zFarPlane | The maximum z-value of the view volume. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a perspective projection matrix based on a field of view.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x- and y-coordinates ranging from -1 to 1, and a z-coordinate ranging from 0 to 1. To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
fieldOfView | The field of view in the y direction (in degrees). |
aspectRatio | The aspect ratio, defined as view space width divided by height. |
zNearPlane | The distance to the near view plane. |
zFarPlane | The distance to the far view plane. |
|
static |
Creates a perspective projection matrix based on a field of view, putting it in dst.
Projection space refers to the space after applying projection transformation from view space. After the projection transformation, visible content has x- and y-coordinates ranging from -1 to 1, and a z-coordinate ranging from 0 to 1. To obtain the viewable area (in world space) of a scene, create a bounding frustum and pass the combined view and projection matrix to the constructor.
fieldOfView | The field of view in the y direction (in degrees). |
aspectRatio | The aspect ratio, defined as view space width divided by height. |
zNearPlane | The distance to the near view plane. |
zFarPlane | The distance to the far view plane. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a rotation matrix from the specified quaternion.
quat | A quaternion describing a 3D orientation. |
|
static |
Creates a rotation matrix from the specified quaternion, putting it in dst.
quat | A quaternion describing a 3D orientation. |
dst | A matrix to store the result in. |
Returns a rotation matrix from the specified axis and angle.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
axis | A vector describing the axis to rotate about. |
angle | The angle (in radians). |
Creates a rotation matrix from the specified axis and angle, putting it in dst.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
axis | A vector describing the axis to rotate about. |
angle | The angle (in radians). |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a matrix specifying a rotation around the x-axis.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
Creates a matrix specifying a rotation around the x-axis, putting it in dst.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a matrix specifying a rotation around the y-axis.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
Creates a matrix specifying a rotation around the y-axis, putting it in dst.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a matrix specifying a rotation around the z-axis.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
Creates a matrix specifying a rotation around the z-axis, putting it in dst.
The angle measurement is in radians. The rotation is counter clockwise about the axis.
angle | The angle of rotation (in radians). |
dst | A matrix to store the result in. |
Returns a nonuniform scale matrix from the given vector.
scale | The nonuniform scale value. |
Creates a nonuniform scale matrix from the given vector, putting it in dst.
scale | The nonuniform scale value. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a uniform scale matrix.
scale | The amount to scale. |
Creates a uniform scale matrix, putting it in dst.
scale | The amount to scale. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a nonuniform scale matrix.
sx | The amount to scale along the x-axis. |
sy | The amount to scale along the y-axis. |
sz | The amount to scale along the z-axis. |
Creates a nonuniform scale matrix, putting it in dst.
sx | The amount to scale along the x-axis. |
sy | The amount to scale along the y-axis. |
sz | The amount to scale along the z-axis. |
dst | A matrix to store the result in. |
Returns a translation matrix from the given offset.
trans | The translation offset. |
Creates a translation matrix from the given offset, putting it in dst.
trans | The translation offset. |
dst | A matrix to store the result in. |
|
inlinestatic |
Returns a translation matrix from the given parameters.
tx | The translation on the x-axis. |
ty | The translation on the y-axis. |
tz | The translation on the z-axis. |
Creates a translation matrix from the given parameters, putting it in dst.
tx | The translation on the x-axis. |
ty | The translation on the y-axis. |
tz | The translation on the z-axis. |
dst | A matrix to store the result in. |
|
static |
Decomposes the scale, rotation and translation components of the given matrix.
To work properly, the matrix must have been constructed in the following order: scale, then rotate, then translation. While the rotation matrix will always be correct, the scale and translation are not guaranteed to be correct if this is violated.
If any pointer is null, the method simply does not assign that result. However, it will still continue to compute the component with non-null vectors to store the result.
If the scale component is too small, then it may be impossible to extract the rotation. In that case, if the rotation pointer is not null, this method will return false.
mat | The matrix to decompose. |
scale | The scale component. |
rot | The rotation component. |
trans | The translation component. |
bool cugl::Mat4::equals | ( | const Mat4 & | mat, |
float | epsilon = CU_MATH_EPSILON |
||
) | const |
Returns true if the matrices are within tolerance of each other.
The tolerance is applied to each element of the matrix individually.
mat | The matrix to compare against. |
epsilon | The comparison tolerance. |
Vec3 cugl::Mat4::getBackVector | ( | ) | const |
Returns the backward vector of this matrix, when treated as a camera.
float cugl::Mat4::getDeterminant | ( | ) | const |
Returns the determinant of this matrix.
Vec3 cugl::Mat4::getDownVector | ( | ) | const |
Returns the down vector of this matrix, when treated as a camera.
Vec3 cugl::Mat4::getForwardVector | ( | ) | const |
Returns the forward vector of this matrix, when treated as a camera.
|
inline |
Returns a copy of the inverse of this matrix.
If the matrix cannot be inverted, this method returns the zero matrix.
Note: This does not modify the matrix.
Vec3 cugl::Mat4::getLeftVector | ( | ) | const |
Returns the left vector of this matrix, when treated as a camera.
|
inline |
Returns a copy of this matrix with all elements negated.
Note: This does not modify the matrix.
Vec3 cugl::Mat4::getRightVector | ( | ) | const |
Returns the right vector of this matrix, when treated as a camera.
Quaternion cugl::Mat4::getRotation | ( | ) | const |
Returns the rotational component of this matrix.
If the scale component is too close to zero, we cannot extract the rotation. In that case, we return the zero quaternion. (
Vec3 cugl::Mat4::getScale | ( | ) | const |
Returns the scale component of this matrix.
If the scale component of this matrix has negative parts, it is not possible to always extract the exact scale component. In that case, a scale vector that is mathematically equivalent to the original scale vector is extracted and returned.
To work properly, the matrix must have been constructed in the following order: scale, then rotate, then translation. In any other order, the scale is not guaranteed to be correct.
Vec3 cugl::Mat4::getTranslation | ( | ) | const |
Returns the translational component of this matrix.
To work properly, the matrix must have been constructed in the following order: scale, then rotate, then translation. In any other order, the translation is not guaranteed to be correct.
|
inline |
Returns a copy of the transpose of this matrix.
Transposing a matrix swaps columns and rows. This allows to transform a vector by multiplying it on the left. If the matrix is orthonormal, this is also the inverse.
Note: This does not modify the matrix.
Vec3 cugl::Mat4::getUpVector | ( | ) | const |
Returns the up vector of this matrix, when treated as a camera.
|
inline |
Inverts this matrix in place.
If the matrix cannot be inverted, this method sets it to the zero matrix.
|
static |
Inverts m1 and stores the result in dst.
If the matrix cannot be inverted, this method stores the zero matrix in dst.
This method assumes the float arrays are in column major order.
m1 | The matrix to invert in column major order |
dst | A matrix to store the result in column major order |
Inverts m1 and stores the result in dst.
If the matrix cannot be inverted, this method stores the zero matrix in dst.
m1 | The matrix to invert. |
dst | A matrix to store the result in. |
bool cugl::Mat4::isExactly | ( | const Mat4 & | mat | ) | const |
Returns true if the matrices are exactly equal to each other.
This method may be unreliable given that the elements are floats. It should only be used to compared matrices that have not undergone a lot of transformations.
mat | The matrix to compare against. |
bool cugl::Mat4::isIdentity | ( | float | epsilon = CU_MATH_EPSILON | ) | const |
Returns true if this matrix is equal to the identity matrix.
The optional comparison tolerance takes into accout that elements are floats and this may not be exact. The tolerance is applied to each element individually. By default, the match must be exact.
epsilon | The comparison tolerance |
|
inline |
Returns true if this matrix is invertible.
The optional comparison tolerance takes into accout that elements are floats and this may not be exact. The tolerance is applied to the matrix determinant.
epsilon | The comparison tolerance |
bool cugl::Mat4::isOrthogonal | ( | float | epsilon = CU_MATH_EPSILON | ) | const |
Returns true if this matrix is orthogonal.
The optional comparison tolerance takes into accout that elements are floats and this may not be exact. The tolerance is applied to BOTH the normality test and the dot-product test for each pair.
epsilon | The comparison tolerance |
|
static |
Multiplies m1 by the matrix m2 and stores the result in dst.
The matrix m2 is on the right. This means that it corresponds to an subsequent transform, when looking at a sequence of transforms.
This method assumes the float arrays are in column major order.
m1 | The first matrix to multiply in column-major order |
m2 | The second matrix to multiply in column-major order |
dst | A matrix to store the result in column-major order |
|
static |
Multiplies the specified matrix by a scalar and stores the result in dst.
This method assumes the float arrays are in column major order.
mat | The matrix in column-major order |
scalar | The scalar value. |
dst | A matrix to store the result in column-major order |
Multiplies m1 by the matrix m2 and stores the result in dst.
The matrix m2 is on the right. This means that it corresponds to an subsequent transform, when looking at a sequence of transforms.
m1 | The first matrix to multiply. |
m2 | The second matrix to multiply. |
dst | A matrix to store the result in. |
Multiplies this matrix by the specified one.
The matrix mat is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms.
mat | The matrix to multiply. |
Multiplies the specified matrix by a scalar and stores the result in dst.
mat | The matrix. |
scalar | The scalar value. |
dst | A matrix to store the result in. |
|
inline |
Multiplies the components of this matrix by the specified scalar.
scalar | The scalar value. |
|
inline |
Negates this matrix in place.
|
static |
Negates m1 and stores the result in dst.
This method assumes the float arrays are in column major order.
m1 | The matrix to negate in column major order |
dst | A matrix to store the result in column major order |
Negates m1 and stores the result in dst.
m1 | The matrix to negate. |
dst | A matrix to store the result in. |
cugl::Mat4::operator Affine2 | ( | ) | const |
|
inline |
Cast from Vec4 to a string.
|
inline |
Returns true if this matrix is not equal to the given matrix.
Comparison is exact, which may be unreliable given that the elements are floats.
mat | The matrix to compare against. |
Returns the matrix product of this matrix with the given matrix.
The matrix mat is on the right. This means that it corresponds to an subsequent transform, when looking at a sequence of transforms.
Note: This does not modify the matrix.
mat | The matrix to multiply by. |
|
inline |
Returns a copy of this matrix with all elements multiplied by the scalar.
Note: This does not modify the matrix.
scalar | The scalar value. |
Right-multiplies this matrix by the given matrix.
The matrix mat is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms.
mat | The matrix to multiply by. |
|
inline |
Multiplies the components of this matrix by the specified scalar.
scalar | The scalar value. |
Returns the sum of this matrix with the given matrix.
Note: This does not modify the matrix.
mat | The matrix to add. |
Adds the given matrix to this one in place.
mat | The matrix to add |
|
inline |
Returns the negation of this matrix.
Note: This does not modify the matrix.
Returns the difference of this matrix with the given matrix.
Note: This does not modify the matrix.
mat | The matrix to subtract. |
Subtracts the given matrix from this one in place.
mat | The matrix to subtract |
Sets the elements of this matrix to those of the given transform.
The z values are set to the identity.
aff | The transform to convert |
|
inline |
Sets the values of this matrix to those in the specified column-major array.
The passed-in array is in column-major order, so the memory layout of the array is as follows:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
array | An array containing 16 elements in column-major order. |
Sets the elements of this matrix to those in the specified matrix.
mat | The matrix to copy. |
|
inline |
Sets this matrix as a rotation matrix from the specified quaternion.
quat | A quaternion describing a 3D orientation. |
Sets the elements of this matrix to those in the specified one.
mat | The matrix to take resources from. |
|
inline |
Returns true if this matrix is equal to the given matrix.
Comparison is exact, which may be unreliable given that the elements are floats. It should only be used to compared matrices that have not undergone a lot of transformations.
mat | The matrix to compare against. |
|
inlinestatic |
Applies a quaternion rotation to the given matrix and stores the result in dst.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to rotate. |
quat | The quaternion to rotate by. |
dst | A matrix to store the result in. |
|
inlinestatic |
Applies an axis rotation to the given matrix and stores the result in dst.
The rotation is in radians, counter-clockwise about the given axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to rotate. |
axis | The axis to rotate about. |
angle | The angle (in radians). |
dst | A matrix to store the result in. |
|
inline |
Applies a quaternion rotation to this matrix.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
q | The quaternion to rotate by. |
Applies an axis rotation to the this matrix.
The rotation is in radians, counter-clockwise about the given axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
axis | The axis to rotate about. |
angle | The angle (in radians). |
Applies an x-axis rotation to the given matrix and stores the result in dst.
The rotation is in radians, counter-clockwise about the x-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to rotate. |
angle | The angle (in radians). |
dst | A matrix to store the result in. |
|
inline |
Applies an x-axis rotation to this matrix.
The rotation is in radians, counter-clockwise about the x-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
angle | The angle (in radians). |
Applies an y-axis rotation to the given matrix and stores the result in dst.
The rotation is in radians, counter-clockwise about the y-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to rotate. |
angle | The angle (in radians). |
dst | A matrix to store the result in. |
|
inline |
Applies a y-axis rotation to this matrix.
The rotation is in radians, counter-clockwise about the y-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
angle | The angle (in radians). |
Applies an z-axis rotation to the given matrix and stores the result in dst.
The rotation is in radians, counter-clockwise about the z-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to rotate. |
angle | The angle (in radians). |
dst | A matrix to store the result in. |
|
inline |
Applies a z-axis rotation to this matrix.
The rotation is in radians, counter-clockwise about the z-axis.
The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
angle | The angle (in radians). |
Applies a non-uniform scale to the given matrix and stores the result in dst.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to scale. |
s | The vector storing the individual scaling factors |
dst | A matrix to store the result in. |
|
inlinestatic |
Applies a non-uniform scale to the given matrix and stores the result in dst.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to scale. |
sx | The amount to scale along the x-axis. |
sy | The amount to scale along the y-axis. |
sz | The amount to scale along the z-axis. |
dst | A matrix to store the result in. |
Applies a uniform scale to the given matrix and stores the result in dst.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to scale. |
value | The scalar to multiply by. |
dst | A matrix to store the result in. |
Applies a non-uniform scale to this matrix.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
s | The vector storing the individual scaling factors |
|
inline |
Applies a non-uniform scale to this matrix.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
sx | The amount to scale along the x-axis. |
sy | The amount to scale along the y-axis. |
sz | The amount to scale along the z-axis. |
|
inline |
Applies a uniform scale to this matrix.
The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
value | The scalar to multiply by. |
Sets the elements of this matrix to those of the given transform.
The z values are set to the identity.
aff | The transform to convert |
Mat4 & cugl::Mat4::set | ( | const float * | mat | ) |
Sets the values of this matrix to those in the specified column-major array.
The passed-in array is in column-major order, so the memory layout of the array is as follows:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
mat | An array containing 16 elements in column-major order. |
Sets the elements of this matrix to those in the specified matrix.
mat | The matrix to copy. |
Mat4 & cugl::Mat4::set | ( | const Quaternion & | quat | ) |
Sets this matrix as a rotation matrix from the specified quaternion.
quat | A quaternion describing a 3D orientation. |
Mat4 & cugl::Mat4::set | ( | float | m11, |
float | m12, | ||
float | m13, | ||
float | m14, | ||
float | m21, | ||
float | m22, | ||
float | m23, | ||
float | m24, | ||
float | m31, | ||
float | m32, | ||
float | m33, | ||
float | m34, | ||
float | m41, | ||
float | m42, | ||
float | m43, | ||
float | m44 | ||
) |
Sets the individal values of this matrix.
m11 | The first element of the first row. |
m12 | The second element of the first row. |
m13 | The third element of the first row. |
m14 | The fourth element of the first row. |
m21 | The first element of the second row. |
m22 | The second element of the second row. |
m23 | The third element of the second row. |
m24 | The fourth element of the second row. |
m31 | The first element of the third row. |
m32 | The second element of the third row. |
m33 | The third element of the third row. |
m34 | The fourth element of the third row. |
m41 | The first element of the fourth row. |
m42 | The second element of the fourth row. |
m43 | The third element of the fourth row. |
m44 | The fourth element of the fourth row. |
Mat4 & cugl::Mat4::setIdentity | ( | ) |
Sets this matrix to the identity matrix.
Mat4 & cugl::Mat4::setZero | ( | ) |
Sets all elements of the current matrix to zero.
|
static |
Subtracts the matrix m2 from m1 and stores the result in dst.
This method assumes the float arrays are in column major order.
m1 | The first matrix in column-major order |
m2 | The second matrix in column-major order |
dst | The destination matrix in column-major order |
|
static |
Subtracts a scalar from each component of mat and stores the result in dst.
This method assumes the float arrays are in column major order.
mat | The matrix to subtract from in column major order |
scalar | The scalar value to subtract in column major order |
dst | A matrix to store the result in column major order |
Subtracts the matrix m2 from m1 and stores the result in dst.
m1 | The first matrix. |
m2 | The second matrix. |
dst | A matrix to store the result in. |
Subtracts the specified matrix from the current matrix.
mat | The matrix to subtract. |
Subtracts a scalar from each component of mat and stores the result in dst.
mat | The matrix to subtract from. |
scalar | The scalar value to subtract. |
dst | A matrix to store the result in. |
|
inline |
Subtracts a scalar value from each component of this matrix.
scalar | The scalar to subtract. |
std::string cugl::Mat4::toString | ( | bool | verbose = false | ) | const |
Returns a string representation of this matrix for debugging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information |
|
static |
Transforms the vector array by the given matrix, and stores the result in dst.
The vector is array is treated as a list of 4 element vectors (
mat | The transform matrix in column major order |
input | The array of vectors to transform. |
output | The array to store the transformed vectors. |
size | The size of the two arrays. |
Transforms the rectangle by the given matrix, and stores the result in dst.
This method transforms the four defining points of the rectangle. It then computes the minimal bounding box storing these four points.
mat | The transform matrix. |
rect | The rect to transform. |
dst | A rect to store the transformed rectangle in. |
Transforms the point by the given matrix, and stores the result in dst.
The vector is treated as a point, which means that translation is applied to the result. The destination array will be assigned only 2 elements.
mat | The transform matrix. |
point | The point to transform. |
dst | An array to store the transformed point. |
Transforms the point by the given matrix, and stores the result in dst.
The vector is treated as a point, which means that translation is applied to the result.
mat | The transform matrix. |
point | The point to transform. |
dst | A vector to store the transformed point in. |
Transforms the point by the given matrix, and stores the result in dst.
The vector is treated as a point, which means that translation is applied to the result.
mat | The transform matrix. |
point | The point to transform. |
dst | A vector to store the transformed point in. |
Transforms the vector by the given matrix, and stores the result in dst.
The vector is treated as is. Hence whether or not translation is applied depends on the value of w.
mat | The transform matrix. |
vec | The vector to transform. |
dst | A vector to store the transformed point in. |
|
static |
Transforms the vector array by the given matrix, and stores the result in dst.
The vector is array is treated as a list of 4 element vectors (
mat | The transform matrix. |
input | The array of vectors to transform. |
output | The array to store the transformed vectors. |
size | The size of the two arrays. |
Returns a copy of the given rectangle transformed.
This method transforms the four defining points of the rectangle. It then computes the minimal bounding box storing these four points
Note: This does not modify the original rectangle. To transform a point in place, use the static method.
rect | The rect to transform. |
Returns a copy of this point transformed by the matrix.
The vector is treated as a point, which means that translation is applied to the result.
Note: This does not modify the original point. To transform a point in place, use the static method (or the appropriate operator).
point | The point to transform. |
Returns a copy of this point transformed by the matrix.
The vector is treated as a point, which means that translation is applied to the result.
Note: This does not modify the original point. To transform a point in place, use the static method (or the appropriate operator).
point | The point to transform. |
Returns a copy of this vector transformed by the matrix.
The vector is treated as is. Hence whether or not translation is applied depends on the value of w.
Note: This does not modify the original vector. To transform a vector in place, use the static method (or the appropriate operator).
vec | The vector to transform. |
Transforms the vector by the given matrix, and stores the result in dst.
The vector is treated as a direction, which means that translation is not applied to the result.
mat | The transform matrix. |
vec | The vector to transform. |
dst | A vector to store the transformed point in. |
Transforms the vector by the given matrix, and stores the result in dst.
The vector is treated as a direction, which means that translation is not applied to the result.
mat | The transform matrix. |
vec | The vector to transform. |
dst | A vector to store the transformed point in. |
Returns a copy of this vector transformed by the matrix.
The vector is treated as a direction, which means that translation is not applied to the result.
Note: This does not modify the original vector. To transform a vector in place, use the static method (or the appropriate operator).
vec | The vector to transform. |
Returns a copy of this vector transformed by the matrix.
The vector is treated as a direction, which means that translation is not applied to the result.
Note: This does not modify the original vector. To transform a vector in place, use the static method (or the appropriate operator).
vec | The vector to transform. |
Applies a translation to the given matrix and stores the result in dst.
The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to translate. |
t | The vector storing the individual translation offsets |
dst | A matrix to store the result in. |
|
inlinestatic |
Applies a translation to the given matrix and stores the result in dst.
The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
mat | The matrix to translate. |
tx | The translation offset for the x-axis. |
ty | The translation offset for the y-axis. |
tz | The translation offset for the z-axis. |
dst | A matrix to store the result in. |
Applies a translation to this matrix.
The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
t | The vector storing the individual translation offsets |
|
inline |
Applies a translation to this matrix.
The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.
tx | The translation offset for the x-axis. |
ty | The translation offset for the y-axis. |
tz | The translation offset for the z-axis. |
|
inline |
Transposes this matrix in place.
Transposing a matrix swaps columns and rows. This allows to transform a vector by multiplying it on the left. If the matrix is orthonormal, this is also the inverse.
|
static |
Transposes m1 and stores the result in dst.
Transposing a matrix swaps columns and rows. This allows to transform a vector by multiplying it on the left. If the matrix is orthonormal, this is also the inverse.
This method assumes the float arrays are in column major order.
m1 | The matrix to transpose in column major order |
dst | A matrix to store the result in column major order |
Transposes m1 and stores the result in dst.
Transposing a matrix swaps columns and rows. This allows to transform a vector by multiplying it on the left. If the matrix is orthonormal, this is also the inverse.
m1 | The matrix to transpose. |
dst | A matrix to store the result in. |
|
static |
The identity matrix (ones on the diagonal)
float cugl::Mat4::m[16] |
The underlying matrix elements
|
static |
The matrix with all ones
|
static |
The matrix with all zeroes