CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Mat4 Class Reference

#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 &copy)
 
 Mat4 (Mat4 &&copy)
 
 Mat4 (const Quaternion &rotation)
 
 ~Mat4 ()
 
Mat4operator= (const Mat4 &mat)
 
Mat4operator= (Mat4 &&mat)
 
Mat4operator= (const float *array)
 
Mat4operator= (const Quaternion &quat)
 
Mat4set (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)
 
Mat4set (const float *mat)
 
Mat4set (const Quaternion &quat)
 
Mat4set (const Mat4 &mat)
 
Mat4setIdentity ()
 
Mat4setZero ()
 
Mat4add (float scalar)
 
Mat4add (const Mat4 &mat)
 
Mat4subtract (float scalar)
 
Mat4subtract (const Mat4 &mat)
 
Mat4multiply (float scalar)
 
Mat4multiply (const Mat4 &mat)
 
Mat4negate ()
 
Mat4 getNegation () const
 
Mat4invert ()
 
Mat4 getInverse () const
 
Mat4transpose ()
 
Mat4 getTranspose () const
 
Mat4operator+= (const Mat4 &mat)
 
Mat4operator-= (const Mat4 &mat)
 
Mat4operator*= (const Mat4 &mat)
 
Mat4operator*= (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
 
Mat4rotate (const Quaternion &q)
 
Mat4rotate (const Vec3 axis, float angle)
 
Mat4rotateX (float angle)
 
Mat4rotateY (float angle)
 
Mat4rotateZ (float angle)
 
Mat4scale (float value)
 
Mat4scale (const Vec3 s)
 
Mat4scale (float sx, float sy, float sz)
 
Mat4translate (const Vec3 t)
 
Mat4translate (float tx, float ty, float tz)
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Affine2 () const
 
 Mat4 (const Affine2 &aff)
 
Mat4operator= (const Affine2 &aff)
 
Mat4set (const Affine2 &aff)
 

Static Public Member Functions

static Mat4 createLookAt (const Vec3 eye, const Vec3 target, const Vec3 up)
 
static Mat4createLookAt (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 Mat4createLookAt (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 Mat4createPerspective (float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4 *dst)
 
static Mat4 createOrthographic (float width, float height, float zNearPlane, float zFarPlane)
 
static Mat4createOrthographic (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 Mat4createOrthographicOffCenter (float left, float right, float bottom, float top, float zNearPlane, float zFarPlane, Mat4 *dst)
 
static Mat4 createScale (float scale)
 
static Mat4createScale (float scale, Mat4 *dst)
 
static Mat4 createScale (float sx, float sy, float sz)
 
static Mat4createScale (float sx, float sy, float sz, Mat4 *dst)
 
static Mat4 createScale (const Vec3 scale)
 
static Mat4createScale (const Vec3 scale, Mat4 *dst)
 
static Mat4 createRotation (const Quaternion &quat)
 
static Mat4createRotation (const Quaternion &quat, Mat4 *dst)
 
static Mat4 createRotation (const Vec3 axis, float angle)
 
static Mat4createRotation (const Vec3 axis, float angle, Mat4 *dst)
 
static Mat4 createRotationX (float angle)
 
static Mat4createRotationX (float angle, Mat4 *dst)
 
static Mat4 createRotationY (float angle)
 
static Mat4createRotationY (float angle, Mat4 *dst)
 
static Mat4 createRotationZ (float angle)
 
static Mat4createRotationZ (float angle, Mat4 *dst)
 
static Mat4 createTranslation (const Vec3 trans)
 
static Mat4createTranslation (const Vec3 trans, Mat4 *dst)
 
static Mat4 createTranslation (float tx, float ty, float tz)
 
static Mat4createTranslation (float tx, float ty, float tz, Mat4 *dst)
 
static Mat4add (const Mat4 &mat, float scalar, Mat4 *dst)
 
static float * add (const float *mat, float scalar, float *dst)
 
static Mat4add (const Mat4 &m1, const Mat4 &m2, Mat4 *dst)
 
static float * add (const float *m1, const float *m2, float *dst)
 
static Mat4subtract (const Mat4 &mat, float scalar, Mat4 *dst)
 
static float * subtract (const float *mat, float scalar, float *dst)
 
static Mat4subtract (const Mat4 &m1, const Mat4 &m2, Mat4 *dst)
 
static float * subtract (const float *m1, const float *m2, float *dst)
 
static Mat4multiply (const Mat4 &mat, float scalar, Mat4 *dst)
 
static float * multiply (const float *mat, float scalar, float *dst)
 
static Mat4multiply (const Mat4 &m1, const Mat4 &m2, Mat4 *dst)
 
static float * multiply (const float *m1, const float *m2, float *dst)
 
static Mat4negate (const Mat4 &m1, Mat4 *dst)
 
static float * negate (const float *m1, float *dst)
 
static Mat4invert (const Mat4 &m1, Mat4 *dst)
 
static float * invert (const float *m1, float *dst)
 
static Mat4transpose (const Mat4 &m1, Mat4 *dst)
 
static float * transpose (const float *m1, float *dst)
 
static Vec2transform (const Mat4 &mat, const Vec2 point, Vec2 *dst)
 
static float * transform (const Mat4 &mat, const Vec2 point, float *dst)
 
static Recttransform (const Mat4 &mat, const Rect rect, Rect *dst)
 
static Vec2transformVector (const Mat4 &mat, const Vec2 vec, Vec2 *dst)
 
static Vec3transform (const Mat4 &mat, const Vec3 point, Vec3 *dst)
 
static Vec3transformVector (const Mat4 &mat, const Vec3 vec, Vec3 *dst)
 
static Vec4transform (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 Mat4rotate (const Mat4 &mat, const Quaternion &quat, Mat4 *dst)
 
static Mat4rotate (const Mat4 &mat, const Vec3 axis, float angle, Mat4 *dst)
 
static Mat4rotateX (const Mat4 &mat, float angle, Mat4 *dst)
 
static Mat4rotateY (const Mat4 &mat, float angle, Mat4 *dst)
 
static Mat4rotateZ (const Mat4 &mat, float angle, Mat4 *dst)
 
static Mat4scale (const Mat4 &mat, float value, Mat4 *dst)
 
static Mat4scale (const Mat4 &mat, const Vec3 s, Mat4 *dst)
 
static Mat4scale (const Mat4 &mat, float sx, float sy, float sz, Mat4 *dst)
 
static Mat4translate (const Mat4 &mat, const Vec3 t, Mat4 *dst)
 
static Mat4translate (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Mat4() [1/7]

cugl::Mat4::Mat4 ( )

Creates the identity matrix.

1  0  0  0
0  1  0  0
0  0  1  0
0  0  0  1

◆ Mat4() [2/7]

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.

Parameters
m11The first element of the first row.
m12The second element of the first row.
m13The third element of the first row.
m14The fourth element of the first row.
m21The first element of the second row.
m22The second element of the second row.
m23The third element of the second row.
m24The fourth element of the second row.
m31The first element of the third row.
m32The second element of the third row.
m33The third element of the third row.
m34The fourth element of the third row.
m41The first element of the fourth row.
m42The second element of the fourth row.
m43The third element of the fourth row.
m44The fourth element of the fourth row.

◆ Mat4() [3/7]

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
Parameters
matAn array containing 16 elements in column-major order.

◆ Mat4() [4/7]

cugl::Mat4::Mat4 ( const Mat4 copy)

Constructs a new matrix that is the copy of the specified one.

Parameters
copyThe matrix to copy.

◆ Mat4() [5/7]

cugl::Mat4::Mat4 ( Mat4 &&  copy)

Constructs a new matrix that contains the resources of the specified one.

Parameters
copyThe matrix contributing resources.

◆ Mat4() [6/7]

cugl::Mat4::Mat4 ( const Quaternion rotation)
inline

Constructs a new matrix that is specified by the given quaternion.

Parameters
rotationThe quaternion specifying a rotation.

◆ ~Mat4()

cugl::Mat4::~Mat4 ( )
inline

Destroys this matrix, releasing all resources.

◆ Mat4() [7/7]

cugl::Mat4::Mat4 ( const Affine2 aff)
explicit

Creates a matrix from the given affine transform.

The z values are set to the identity.

Parameters
affThe transform to convert

Member Function Documentation

◆ add() [1/6]

static float * cugl::Mat4::add ( const float *  m1,
const float *  m2,
float *  dst 
)
static

Adds the specified matrices and stores the result in dst.

This method assumes the float arrays are in column major order.

Parameters
m1The first matrix in column-major order
m2The second matrix in column-major order
dstThe destination matrix in column-major order
Returns
A reference to dst for chaining

◆ add() [2/6]

static float * cugl::Mat4::add ( const float *  mat,
float  scalar,
float *  dst 
)
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.

Parameters
matThe matrix to add to in column-major order
scalarThe scalar value to add.
dstA matrix to store the result in column-major order
Returns
A reference to dst for chaining

◆ add() [3/6]

static Mat4 * cugl::Mat4::add ( const Mat4 m1,
const Mat4 m2,
Mat4 dst 
)
static

Adds the specified matrices and stores the result in dst.

Parameters
m1The first matrix.
m2The second matrix.
dstThe destination matrix to add to.
Returns
A reference to dst for chaining

◆ add() [4/6]

Mat4 & cugl::Mat4::add ( const Mat4 mat)
inline

Adds the specified matrix to this matrix.

Parameters
matThe matrix to add.
Returns
A reference to the Mat4 after addition.

◆ add() [5/6]

static Mat4 * cugl::Mat4::add ( const Mat4 mat,
float  scalar,
Mat4 dst 
)
static

Adds a scalar to each component of mat and stores the result in dst.

Parameters
matThe matrix to add to.
scalarThe scalar value to add.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ add() [6/6]

Mat4 & cugl::Mat4::add ( float  scalar)
inline

Adds a scalar value to each component of this matrix.

Parameters
scalarThe scalar to add.
Returns
A reference to the Mat4 after addition.

◆ createLookAt() [1/4]

static Mat4 cugl::Mat4::createLookAt ( const Vec3  eye,
const Vec3  target,
const Vec3  up 
)
inlinestatic

Creates a view matrix based on the specified input vectors.

Parameters
eyeThe eye position.
targetThe target's center position.
upThe up vector.
Returns
a view matrix based on the specified input vectors.

◆ createLookAt() [2/4]

static Mat4 * cugl::Mat4::createLookAt ( const Vec3  eye,
const Vec3  target,
const Vec3  up,
Mat4 dst 
)
static

Creates a view matrix based on the specified input vectors, putting it in dst.

Parameters
eyeThe eye position.
targetThe target's center position.
upThe up vector.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createLookAt() [3/4]

static Mat4 cugl::Mat4::createLookAt ( float  eyeX,
float  eyeY,
float  eyeZ,
float  targetX,
float  targetY,
float  targetZ,
float  upX,
float  upY,
float  upZ 
)
inlinestatic

Returns a view matrix based on the specified input parameters.

Parameters
eyeXThe eye x-coordinate position.
eyeYThe eye y-coordinate position.
eyeZThe eye z-coordinate position.
targetXThe target's center x-coordinate position.
targetYThe target's center y-coordinate position.
targetZThe target's center z-coordinate position.
upXThe up vector x-coordinate value.
upYThe up vector y-coordinate value.
upZThe up vector z-coordinate value.
Returns
a view matrix based on the specified input parameters.

◆ createLookAt() [4/4]

static Mat4 * cugl::Mat4::createLookAt ( float  eyeX,
float  eyeY,
float  eyeZ,
float  targetX,
float  targetY,
float  targetZ,
float  upX,
float  upY,
float  upZ,
Mat4 dst 
)
static

Creates a view matrix based on the specified input parameters, putting it in dst.

Parameters
eyeXThe eye x-coordinate position.
eyeYThe eye y-coordinate position.
eyeZThe eye z-coordinate position.
targetXThe target's center x-coordinate position.
targetYThe target's center y-coordinate position.
targetZThe target's center z-coordinate position.
upXThe up vector x-coordinate value.
upYThe up vector y-coordinate value.
upZThe up vector z-coordinate value.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createOrthographic() [1/2]

static Mat4 cugl::Mat4::createOrthographic ( float  width,
float  height,
float  zNearPlane,
float  zFarPlane 
)
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.

Parameters
widthThe width of the view.
heightThe height of the view.
zNearPlaneThe minimum z-value of the view volume.
zFarPlaneThe maximum z-value of the view volume.
Returns
an orthographic projection matrix anchored at the origin.

◆ createOrthographic() [2/2]

static Mat4 * cugl::Mat4::createOrthographic ( float  width,
float  height,
float  zNearPlane,
float  zFarPlane,
Mat4 dst 
)
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.

Parameters
widthThe width of the view.
heightThe height of the view.
zNearPlaneThe minimum z-value of the view volume.
zFarPlaneThe maximum z-value of the view volume.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createOrthographicOffCenter() [1/2]

static Mat4 cugl::Mat4::createOrthographicOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNearPlane,
float  zFarPlane 
)
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.

Parameters
leftThe minimum x-value of the view volume.
rightThe maximum x-value of the view volume.
bottomThe minimum y-value of the view volume.
topThe maximum y-value of the view volume.
zNearPlaneThe minimum z-value of the view volume.
zFarPlaneThe maximum z-value of the view volume.
Returns
an orthographic projection matrix.

◆ createOrthographicOffCenter() [2/2]

static Mat4 * cugl::Mat4::createOrthographicOffCenter ( float  left,
float  right,
float  bottom,
float  top,
float  zNearPlane,
float  zFarPlane,
Mat4 dst 
)
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.

Parameters
leftThe minimum x-value of the view volume.
rightThe maximum x-value of the view volume.
bottomThe minimum y-value of the view volume.
topThe maximum y-value of the view volume.
zNearPlaneThe minimum z-value of the view volume.
zFarPlaneThe maximum z-value of the view volume.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createPerspective() [1/2]

static Mat4 cugl::Mat4::createPerspective ( float  fieldOfView,
float  aspectRatio,
float  zNearPlane,
float  zFarPlane 
)
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.

Parameters
fieldOfViewThe field of view in the y direction (in degrees).
aspectRatioThe aspect ratio, defined as view space width divided by height.
zNearPlaneThe distance to the near view plane.
zFarPlaneThe distance to the far view plane.
Returns
a perspective projection matrix based on a field of view.

◆ createPerspective() [2/2]

static Mat4 * cugl::Mat4::createPerspective ( float  fieldOfView,
float  aspectRatio,
float  zNearPlane,
float  zFarPlane,
Mat4 dst 
)
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.

Parameters
fieldOfViewThe field of view in the y direction (in degrees).
aspectRatioThe aspect ratio, defined as view space width divided by height.
zNearPlaneThe distance to the near view plane.
zFarPlaneThe distance to the far view plane.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createRotation() [1/4]

static Mat4 cugl::Mat4::createRotation ( const Quaternion quat)
inlinestatic

Returns a rotation matrix from the specified quaternion.

Parameters
quatA quaternion describing a 3D orientation.
Returns
a rotation matrix from the specified quaternion.

◆ createRotation() [2/4]

static Mat4 * cugl::Mat4::createRotation ( const Quaternion quat,
Mat4 dst 
)
static

Creates a rotation matrix from the specified quaternion, putting it in dst.

Parameters
quatA quaternion describing a 3D orientation.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createRotation() [3/4]

static Mat4 cugl::Mat4::createRotation ( const Vec3  axis,
float  angle 
)
inlinestatic

Returns a rotation matrix from the specified axis and angle.

The angle measurement is in radians. The rotation is counter clockwise about the axis.

Parameters
axisA vector describing the axis to rotate about.
angleThe angle (in radians).
Returns
a rotation matrix from the specified axis and angle.

◆ createRotation() [4/4]

static Mat4 * cugl::Mat4::createRotation ( const Vec3  axis,
float  angle,
Mat4 dst 
)
static

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.

Parameters
axisA vector describing the axis to rotate about.
angleThe angle (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createRotationX() [1/2]

static Mat4 cugl::Mat4::createRotationX ( float  angle)
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.

Parameters
angleThe angle of rotation (in radians).
Returns
a matrix specifying a rotation around the x-axis.

◆ createRotationX() [2/2]

static Mat4 * cugl::Mat4::createRotationX ( float  angle,
Mat4 dst 
)
static

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.

Parameters
angleThe angle of rotation (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createRotationY() [1/2]

static Mat4 cugl::Mat4::createRotationY ( float  angle)
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.

Parameters
angleThe angle of rotation (in radians).
Returns
a matrix specifying a rotation around the y-axis.

◆ createRotationY() [2/2]

static Mat4 * cugl::Mat4::createRotationY ( float  angle,
Mat4 dst 
)
static

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.

Parameters
angleThe angle of rotation (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createRotationZ() [1/2]

static Mat4 cugl::Mat4::createRotationZ ( float  angle)
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.

Parameters
angleThe angle of rotation (in radians).
Returns
a matrix specifying a rotation around the z-axis.

◆ createRotationZ() [2/2]

static Mat4 * cugl::Mat4::createRotationZ ( float  angle,
Mat4 dst 
)
static

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.

Parameters
angleThe angle of rotation (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [1/6]

static Mat4 cugl::Mat4::createScale ( const Vec3  scale)
inlinestatic

Returns a nonuniform scale matrix from the given vector.

Parameters
scaleThe nonuniform scale value.
Returns
a nonuniform scale matrix from the given vector.

◆ createScale() [2/6]

static Mat4 * cugl::Mat4::createScale ( const Vec3  scale,
Mat4 dst 
)
static

Creates a nonuniform scale matrix from the given vector, putting it in dst.

Parameters
scaleThe nonuniform scale value.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [3/6]

static Mat4 cugl::Mat4::createScale ( float  scale)
inlinestatic

Returns a uniform scale matrix.

Parameters
scaleThe amount to scale.
Returns
a uniform scale matrix.

◆ createScale() [4/6]

static Mat4 * cugl::Mat4::createScale ( float  scale,
Mat4 dst 
)
static

Creates a uniform scale matrix, putting it in dst.

Parameters
scaleThe amount to scale.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [5/6]

static Mat4 cugl::Mat4::createScale ( float  sx,
float  sy,
float  sz 
)
inlinestatic

Returns a nonuniform scale matrix.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
szThe amount to scale along the z-axis.
Returns
a nonuniform scale matrix.

◆ createScale() [6/6]

static Mat4 * cugl::Mat4::createScale ( float  sx,
float  sy,
float  sz,
Mat4 dst 
)
static

Creates a nonuniform scale matrix, putting it in dst.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
szThe amount to scale along the z-axis.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createTranslation() [1/4]

static Mat4 cugl::Mat4::createTranslation ( const Vec3  trans)
inlinestatic

Returns a translation matrix from the given offset.

Parameters
transThe translation offset.
Returns
a translation matrix from the given offset.

◆ createTranslation() [2/4]

static Mat4 * cugl::Mat4::createTranslation ( const Vec3  trans,
Mat4 dst 
)
static

Creates a translation matrix from the given offset, putting it in dst.

Parameters
transThe translation offset.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ createTranslation() [3/4]

static Mat4 cugl::Mat4::createTranslation ( float  tx,
float  ty,
float  tz 
)
inlinestatic

Returns a translation matrix from the given parameters.

Parameters
txThe translation on the x-axis.
tyThe translation on the y-axis.
tzThe translation on the z-axis.
Returns
A reference to dst for chaining

◆ createTranslation() [4/4]

static Mat4 * cugl::Mat4::createTranslation ( float  tx,
float  ty,
float  tz,
Mat4 dst 
)
static

Creates a translation matrix from the given parameters, putting it in dst.

Parameters
txThe translation on the x-axis.
tyThe translation on the y-axis.
tzThe translation on the z-axis.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ decompose()

static bool cugl::Mat4::decompose ( const Mat4 mat,
Vec3 scale,
Quaternion rot,
Vec3 trans 
)
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.

Parameters
matThe matrix to decompose.
scaleThe scale component.
rotThe rotation component.
transThe translation component.
Returns
true if all requested components were properly extracted

◆ equals()

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.

Parameters
matThe matrix to compare against.
epsilonThe comparison tolerance.
Returns
true if the matrices are within tolerance of each other.

◆ getBackVector()

Vec3 cugl::Mat4::getBackVector ( ) const

Returns the backward vector of this matrix, when treated as a camera.

Returns
the backward vector of this matrix, when treated as a camera.

◆ getDeterminant()

float cugl::Mat4::getDeterminant ( ) const

Returns the determinant of this matrix.

Returns
the determinant of this matrix.

◆ getDownVector()

Vec3 cugl::Mat4::getDownVector ( ) const

Returns the down vector of this matrix, when treated as a camera.

Returns
the down vector of this matrix, when treated as a camera.

◆ getForwardVector()

Vec3 cugl::Mat4::getForwardVector ( ) const

Returns the forward vector of this matrix, when treated as a camera.

Returns
the forward vector of this matrix, when treated as a camera.

◆ getInverse()

Mat4 cugl::Mat4::getInverse ( ) const
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.

Returns
a copy of the inverse of this matrix.

◆ getLeftVector()

Vec3 cugl::Mat4::getLeftVector ( ) const

Returns the left vector of this matrix, when treated as a camera.

Returns
the left vector of this matrix, when treated as a camera.

◆ getNegation()

Mat4 cugl::Mat4::getNegation ( ) const
inline

Returns a copy of this matrix with all elements negated.

Note: This does not modify the matrix.

Returns
a copy of this matrix with all elements negated.

◆ getRightVector()

Vec3 cugl::Mat4::getRightVector ( ) const

Returns the right vector of this matrix, when treated as a camera.

Returns
the right vector of this matrix, when treated as a camera.

◆ getRotation()

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. (

Returns
the rotational component of this matrix.

◆ getScale()

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.

Returns
the scale component of this matrix.

◆ getTranslation()

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.

Returns
the translational component of this matrix.

◆ getTranspose()

Mat4 cugl::Mat4::getTranspose ( ) const
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.

Returns
a copy of the transpose of this matrix.

◆ getUpVector()

Vec3 cugl::Mat4::getUpVector ( ) const

Returns the up vector of this matrix, when treated as a camera.

Returns
the up vector of this matrix, when treated as a camera.

◆ invert() [1/3]

Mat4 & cugl::Mat4::invert ( )
inline

Inverts this matrix in place.

If the matrix cannot be inverted, this method sets it to the zero matrix.

Returns
A reference to the Mat4 after the inversion.

◆ invert() [2/3]

static float * cugl::Mat4::invert ( const float *  m1,
float *  dst 
)
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.

Parameters
m1The matrix to invert in column major order
dstA matrix to store the result in column major order
Returns
A reference to dst for chaining

◆ invert() [3/3]

static Mat4 * cugl::Mat4::invert ( const Mat4 m1,
Mat4 dst 
)
static

Inverts m1 and stores the result in dst.

If the matrix cannot be inverted, this method stores the zero matrix in dst.

Parameters
m1The matrix to invert.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ isExactly()

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.

Parameters
matThe matrix to compare against.
Returns
true if the matrices are exactly equal to each other.

◆ isIdentity()

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.

Parameters
epsilonThe comparison tolerance
Returns
true if this matrix is equal to the identity matrix.

◆ isInvertible()

bool cugl::Mat4::isInvertible ( float  epsilon = CU_MATH_EPSILON) const
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.

Parameters
epsilonThe comparison tolerance
Returns
true if this matrix is invertible.

◆ isOrthogonal()

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.

Parameters
epsilonThe comparison tolerance
Returns
true if this matrix is orthogonal.

◆ multiply() [1/6]

static float * cugl::Mat4::multiply ( const float *  m1,
const float *  m2,
float *  dst 
)
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.

Parameters
m1The first matrix to multiply in column-major order
m2The second matrix to multiply in column-major order
dstA matrix to store the result in column-major order
Returns
A reference to dst for chaining

◆ multiply() [2/6]

static float * cugl::Mat4::multiply ( const float *  mat,
float  scalar,
float *  dst 
)
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.

Parameters
matThe matrix in column-major order
scalarThe scalar value.
dstA matrix to store the result in column-major order
Returns
A reference to dst for chaining

◆ multiply() [3/6]

static Mat4 * cugl::Mat4::multiply ( const Mat4 m1,
const Mat4 m2,
Mat4 dst 
)
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.

Parameters
m1The first matrix to multiply.
m2The second matrix to multiply.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [4/6]

Mat4 & cugl::Mat4::multiply ( const Mat4 mat)
inline

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.

Parameters
matThe matrix to multiply.
Returns
A reference to the Mat4 after multiplication.

◆ multiply() [5/6]

static Mat4 * cugl::Mat4::multiply ( const Mat4 mat,
float  scalar,
Mat4 dst 
)
static

Multiplies the specified matrix by a scalar and stores the result in dst.

Parameters
matThe matrix.
scalarThe scalar value.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [6/6]

Mat4 & cugl::Mat4::multiply ( float  scalar)
inline

Multiplies the components of this matrix by the specified scalar.

Parameters
scalarThe scalar value.
Returns
A reference to the Mat4 after multiplication.

◆ negate() [1/3]

Mat4 & cugl::Mat4::negate ( )
inline

Negates this matrix in place.

Returns
A reference to the Mat4 after negation.

◆ negate() [2/3]

static float * cugl::Mat4::negate ( const float *  m1,
float *  dst 
)
static

Negates m1 and stores the result in dst.

This method assumes the float arrays are in column major order.

Parameters
m1The matrix to negate in column major order
dstA matrix to store the result in column major order
Returns
A reference to dst for chaining

◆ negate() [3/3]

static Mat4 * cugl::Mat4::negate ( const Mat4 m1,
Mat4 dst 
)
static

Negates m1 and stores the result in dst.

Parameters
m1The matrix to negate.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ operator Affine2()

cugl::Mat4::operator Affine2 ( ) const

Cast from Mat4 to a Affine2.

The z values are all uniformly ignored. However, it the final element of the matrix is not 1 (e.g. the translation has a w value of 1), then it divides the entire matrix before creating the affine transform.

◆ operator std::string()

cugl::Mat4::operator std::string ( ) const
inline

Cast from Vec4 to a string.

◆ operator!=()

bool cugl::Mat4::operator!= ( const Mat4 mat) const
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.

Parameters
matThe matrix to compare against.
Returns
true if this matrix is not equal to the given matrix.

◆ operator*() [1/2]

const Mat4 cugl::Mat4::operator* ( const Mat4 mat) const
inline

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.

Parameters
matThe matrix to multiply by.
Returns
the matrix product of this matrix with the given matrix.

◆ operator*() [2/2]

const Mat4 cugl::Mat4::operator* ( float  scalar) const
inline

Returns a copy of this matrix with all elements multiplied by the scalar.

Note: This does not modify the matrix.

Parameters
scalarThe scalar value.
Returns
the matrix product of this matrix with the given matrix.

◆ operator*=() [1/2]

Mat4 & cugl::Mat4::operator*= ( const Mat4 mat)
inline

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.

Parameters
matThe matrix to multiply by.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator*=() [2/2]

Mat4 & cugl::Mat4::operator*= ( float  scalar)
inline

Multiplies the components of this matrix by the specified scalar.

Parameters
scalarThe scalar value.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator+()

const Mat4 cugl::Mat4::operator+ ( const Mat4 mat) const
inline

Returns the sum of this matrix with the given matrix.

Note: This does not modify the matrix.

Parameters
matThe matrix to add.
Returns
the sum of this matrix with the given matrix.

◆ operator+=()

Mat4 & cugl::Mat4::operator+= ( const Mat4 mat)
inline

Adds the given matrix to this one in place.

Parameters
matThe matrix to add
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator-() [1/2]

const Mat4 cugl::Mat4::operator- ( ) const
inline

Returns the negation of this matrix.

Note: This does not modify the matrix.

Returns
the negation of this matrix.

◆ operator-() [2/2]

const Mat4 cugl::Mat4::operator- ( const Mat4 mat) const
inline

Returns the difference of this matrix with the given matrix.

Note: This does not modify the matrix.

Parameters
matThe matrix to subtract.
Returns
the difference of this matrix with the given matrix.

◆ operator-=()

Mat4 & cugl::Mat4::operator-= ( const Mat4 mat)
inline

Subtracts the given matrix from this one in place.

Parameters
matThe matrix to subtract
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [1/5]

Mat4 & cugl::Mat4::operator= ( const Affine2 aff)

Sets the elements of this matrix to those of the given transform.

The z values are set to the identity.

Parameters
affThe transform to convert
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [2/5]

Mat4 & cugl::Mat4::operator= ( const float *  array)
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
Parameters
arrayAn array containing 16 elements in column-major order.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [3/5]

Mat4 & cugl::Mat4::operator= ( const Mat4 mat)
inline

Sets the elements of this matrix to those in the specified matrix.

Parameters
matThe matrix to copy.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [4/5]

Mat4 & cugl::Mat4::operator= ( const Quaternion quat)
inline

Sets this matrix as a rotation matrix from the specified quaternion.

Parameters
quatA quaternion describing a 3D orientation.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [5/5]

Mat4 & cugl::Mat4::operator= ( Mat4 &&  mat)
inline

Sets the elements of this matrix to those in the specified one.

Parameters
matThe matrix to take resources from.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator==()

bool cugl::Mat4::operator== ( const Mat4 mat) const
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.

Parameters
matThe matrix to compare against.
Returns
true if this matrix is equal to the given matrix.

◆ rotate() [1/4]

static Mat4 * cugl::Mat4::rotate ( const Mat4 mat,
const Quaternion quat,
Mat4 dst 
)
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.

Parameters
matThe matrix to rotate.
quatThe quaternion to rotate by.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ rotate() [2/4]

static Mat4 * cugl::Mat4::rotate ( const Mat4 mat,
const Vec3  axis,
float  angle,
Mat4 dst 
)
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.

Parameters
matThe matrix to rotate.
axisThe axis to rotate about.
angleThe angle (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ rotate() [3/4]

Mat4 & cugl::Mat4::rotate ( const Quaternion q)
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.

Parameters
qThe quaternion to rotate by.
Returns
This matrix, after rotation.

◆ rotate() [4/4]

Mat4 & cugl::Mat4::rotate ( const Vec3  axis,
float  angle 
)
inline

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.

Parameters
axisThe axis to rotate about.
angleThe angle (in radians).
Returns
This matrix, after rotation.

◆ rotateX() [1/2]

static Mat4 * cugl::Mat4::rotateX ( const Mat4 mat,
float  angle,
Mat4 dst 
)
inlinestatic

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.

Parameters
matThe matrix to rotate.
angleThe angle (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ rotateX() [2/2]

Mat4 & cugl::Mat4::rotateX ( float  angle)
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.

Parameters
angleThe angle (in radians).
Returns
This matrix, after rotation.

◆ rotateY() [1/2]

static Mat4 * cugl::Mat4::rotateY ( const Mat4 mat,
float  angle,
Mat4 dst 
)
inlinestatic

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.

Parameters
matThe matrix to rotate.
angleThe angle (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ rotateY() [2/2]

Mat4 & cugl::Mat4::rotateY ( float  angle)
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.

Parameters
angleThe angle (in radians).
Returns
This matrix, after rotation.

◆ rotateZ() [1/2]

static Mat4 * cugl::Mat4::rotateZ ( const Mat4 mat,
float  angle,
Mat4 dst 
)
inlinestatic

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.

Parameters
matThe matrix to rotate.
angleThe angle (in radians).
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ rotateZ() [2/2]

Mat4 & cugl::Mat4::rotateZ ( float  angle)
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.

Parameters
angleThe angle (in radians).
Returns
This matrix, after rotation.

◆ scale() [1/6]

static Mat4 * cugl::Mat4::scale ( const Mat4 mat,
const Vec3  s,
Mat4 dst 
)
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.

Parameters
matThe matrix to scale.
sThe vector storing the individual scaling factors
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ scale() [2/6]

static Mat4 * cugl::Mat4::scale ( const Mat4 mat,
float  sx,
float  sy,
float  sz,
Mat4 dst 
)
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.

Parameters
matThe matrix to scale.
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
szThe amount to scale along the z-axis.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ scale() [3/6]

static Mat4 * cugl::Mat4::scale ( const Mat4 mat,
float  value,
Mat4 dst 
)
inlinestatic

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.

Parameters
matThe matrix to scale.
valueThe scalar to multiply by.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ scale() [4/6]

Mat4 & cugl::Mat4::scale ( const Vec3  s)
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.

Parameters
sThe vector storing the individual scaling factors
Returns
This matrix, after scaling.

◆ scale() [5/6]

Mat4 & cugl::Mat4::scale ( float  sx,
float  sy,
float  sz 
)
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.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
szThe amount to scale along the z-axis.
Returns
This matrix, after scaling.

◆ scale() [6/6]

Mat4 & cugl::Mat4::scale ( float  value)
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.

Parameters
valueThe scalar to multiply by.
Returns
This matrix, after scaling.

◆ set() [1/5]

Mat4 & cugl::Mat4::set ( const Affine2 aff)

Sets the elements of this matrix to those of the given transform.

The z values are set to the identity.

Parameters
affThe transform to convert
Returns
A reference to this (modified) Mat4 for chaining.

◆ set() [2/5]

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
Parameters
matAn array containing 16 elements in column-major order.
Returns
A reference to this (modified) Mat4 for chaining.

◆ set() [3/5]

Mat4 & cugl::Mat4::set ( const Mat4 mat)

Sets the elements of this matrix to those in the specified matrix.

Parameters
matThe matrix to copy.
Returns
A reference to this (modified) Mat4 for chaining.

◆ set() [4/5]

Mat4 & cugl::Mat4::set ( const Quaternion quat)

Sets this matrix as a rotation matrix from the specified quaternion.

Parameters
quatA quaternion describing a 3D orientation.
Returns
A reference to this (modified) Mat4 for chaining.

◆ set() [5/5]

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.

Parameters
m11The first element of the first row.
m12The second element of the first row.
m13The third element of the first row.
m14The fourth element of the first row.
m21The first element of the second row.
m22The second element of the second row.
m23The third element of the second row.
m24The fourth element of the second row.
m31The first element of the third row.
m32The second element of the third row.
m33The third element of the third row.
m34The fourth element of the third row.
m41The first element of the fourth row.
m42The second element of the fourth row.
m43The third element of the fourth row.
m44The fourth element of the fourth row.
Returns
A reference to this (modified) Mat4 for chaining.

◆ setIdentity()

Mat4 & cugl::Mat4::setIdentity ( )

Sets this matrix to the identity matrix.

Returns
A reference to this (modified) Mat4 for chaining.

◆ setZero()

Mat4 & cugl::Mat4::setZero ( )

Sets all elements of the current matrix to zero.

Returns
A reference to this (modified) Mat4 for chaining.

◆ subtract() [1/6]

static float * cugl::Mat4::subtract ( const float *  m1,
const float *  m2,
float *  dst 
)
static

Subtracts the matrix m2 from m1 and stores the result in dst.

This method assumes the float arrays are in column major order.

Parameters
m1The first matrix in column-major order
m2The second matrix in column-major order
dstThe destination matrix in column-major order
Returns
A reference to dst for chaining

◆ subtract() [2/6]

static float * cugl::Mat4::subtract ( const float *  mat,
float  scalar,
float *  dst 
)
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.

Parameters
matThe matrix to subtract from in column major order
scalarThe scalar value to subtract in column major order
dstA matrix to store the result in column major order
Returns
A reference to dst for chaining

◆ subtract() [3/6]

static Mat4 * cugl::Mat4::subtract ( const Mat4 m1,
const Mat4 m2,
Mat4 dst 
)
static

Subtracts the matrix m2 from m1 and stores the result in dst.

Parameters
m1The first matrix.
m2The second matrix.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ subtract() [4/6]

Mat4 & cugl::Mat4::subtract ( const Mat4 mat)
inline

Subtracts the specified matrix from the current matrix.

Parameters
matThe matrix to subtract.
Returns
A reference to the Mat4 after subtraction.

◆ subtract() [5/6]

static Mat4 * cugl::Mat4::subtract ( const Mat4 mat,
float  scalar,
Mat4 dst 
)
static

Subtracts a scalar from each component of mat and stores the result in dst.

Parameters
matThe matrix to subtract from.
scalarThe scalar value to subtract.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ subtract() [6/6]

Mat4 & cugl::Mat4::subtract ( float  scalar)
inline

Subtracts a scalar value from each component of this matrix.

Parameters
scalarThe scalar to subtract.
Returns
A reference to the Mat4 after subtraction.

◆ toString()

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.

Parameters
verboseWhether to include class information
Returns
a string representation of this matrix for debugging purposes.

◆ transform() [1/11]

static float * cugl::Mat4::transform ( const float *  mat,
float const *  input,
float *  output,
size_t  size 
)
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 (

See also
Vec4). The transform is applied in order and written to the output array. The float array for the matrix should be in column major order
Parameters
matThe transform matrix in column major order
inputThe array of vectors to transform.
outputThe array to store the transformed vectors.
sizeThe size of the two arrays.
Returns
A reference to dst for chaining

◆ transform() [2/11]

static Rect * cugl::Mat4::transform ( const Mat4 mat,
const Rect  rect,
Rect dst 
)
static

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.

Parameters
matThe transform matrix.
rectThe rect to transform.
dstA rect to store the transformed rectangle in.
Returns
A reference to dst for chaining

◆ transform() [3/11]

static float * cugl::Mat4::transform ( const Mat4 mat,
const Vec2  point,
float *  dst 
)
static

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.

Parameters
matThe transform matrix.
pointThe point to transform.
dstAn array to store the transformed point.
Returns
A reference to dst for chaining

◆ transform() [4/11]

static Vec2 * cugl::Mat4::transform ( const Mat4 mat,
const Vec2  point,
Vec2 dst 
)
static

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.

Parameters
matThe transform matrix.
pointThe point to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transform() [5/11]

static Vec3 * cugl::Mat4::transform ( const Mat4 mat,
const Vec3  point,
Vec3 dst 
)
static

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.

Parameters
matThe transform matrix.
pointThe point to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transform() [6/11]

static Vec4 * cugl::Mat4::transform ( const Mat4 mat,
const Vec4  vec,
Vec4 dst 
)
static

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.

Parameters
matThe transform matrix.
vecThe vector to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transform() [7/11]

static float * cugl::Mat4::transform ( const Mat4 mat,
float const *  input,
float *  output,
size_t  size 
)
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 (

See also
Vec4). The transform is applied in order and written to the output array.
Parameters
matThe transform matrix.
inputThe array of vectors to transform.
outputThe array to store the transformed vectors.
sizeThe size of the two arrays.
Returns
A reference to dst for chaining

◆ transform() [8/11]

Rect cugl::Mat4::transform ( const Rect  rect) const

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.

Parameters
rectThe rect to transform.
Returns
A reference to dst for chaining

◆ transform() [9/11]

Vec2 cugl::Mat4::transform ( const Vec2  point) const

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).

Parameters
pointThe point to transform.
Returns
a copy of this point transformed by the matrix.

◆ transform() [10/11]

Vec3 cugl::Mat4::transform ( const Vec3  point) const

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).

Parameters
pointThe point to transform.
Returns
a copy of this point transformed by the matrix.

◆ transform() [11/11]

Vec4 cugl::Mat4::transform ( const Vec4  vec) const

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).

Parameters
vecThe vector to transform.
Returns
a copy of this point transformed by the matrix.

◆ transformVector() [1/4]

static Vec2 * cugl::Mat4::transformVector ( const Mat4 mat,
const Vec2  vec,
Vec2 dst 
)
static

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.

Parameters
matThe transform matrix.
vecThe vector to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transformVector() [2/4]

static Vec3 * cugl::Mat4::transformVector ( const Mat4 mat,
const Vec3  vec,
Vec3 dst 
)
static

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.

Parameters
matThe transform matrix.
vecThe vector to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transformVector() [3/4]

Vec2 cugl::Mat4::transformVector ( const Vec2  vec) const

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).

Parameters
vecThe vector to transform.
Returns
a copy of this point transformed by the matrix.

◆ transformVector() [4/4]

Vec3 cugl::Mat4::transformVector ( const Vec3  vec) const

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).

Parameters
vecThe vector to transform.
Returns
a copy of this point transformed by the matrix.

◆ translate() [1/4]

static Mat4 * cugl::Mat4::translate ( const Mat4 mat,
const Vec3  t,
Mat4 dst 
)
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.

Parameters
matThe matrix to translate.
tThe vector storing the individual translation offsets
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ translate() [2/4]

static Mat4 * cugl::Mat4::translate ( const Mat4 mat,
float  tx,
float  ty,
float  tz,
Mat4 dst 
)
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.

Parameters
matThe matrix to translate.
txThe translation offset for the x-axis.
tyThe translation offset for the y-axis.
tzThe translation offset for the z-axis.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ translate() [3/4]

Mat4 & cugl::Mat4::translate ( const Vec3  t)
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.

Parameters
tThe vector storing the individual translation offsets
Returns
This matrix, after translation.

◆ translate() [4/4]

Mat4 & cugl::Mat4::translate ( float  tx,
float  ty,
float  tz 
)
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.

Parameters
txThe translation offset for the x-axis.
tyThe translation offset for the y-axis.
tzThe translation offset for the z-axis.
Returns
This matrix, after translation.

◆ transpose() [1/3]

Mat4 & cugl::Mat4::transpose ( )
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.

Returns
A reference to the Mat4 after the transposition.

◆ transpose() [2/3]

static float * cugl::Mat4::transpose ( const float *  m1,
float *  dst 
)
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.

Parameters
m1The matrix to transpose in column major order
dstA matrix to store the result in column major order
Returns
A reference to dst for chaining

◆ transpose() [3/3]

static Mat4 * cugl::Mat4::transpose ( const Mat4 m1,
Mat4 dst 
)
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.

Parameters
m1The matrix to transpose.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

Member Data Documentation

◆ IDENTITY

const Mat4 cugl::Mat4::IDENTITY
static

The identity matrix (ones on the diagonal)

◆ m

float cugl::Mat4::m[16]

The underlying matrix elements

◆ ONE

const Mat4 cugl::Mat4::ONE
static

The matrix with all ones

◆ ZERO

const Mat4 cugl::Mat4::ZERO
static

The matrix with all zeroes


The documentation for this class was generated from the following file: