A 4x4 transformation matrix stored internally as an array of floats in column-major order so as to be compatible with OpenGL.
Examples:
Matrix4 R = Matrix4::RotateX(GfxMath::toRadians(45.0));
Point3 p1(1,1,1);
Point3 p2 = M * p1;
Vector3 v1(1,1,1);
Vector3 v2 = M * v1;
Ray r1(p1, v1);
Ray r2 = M * r1;
static Matrix4 Scale(const Vector3 &v)
Returns the scale matrix described by the vector.
Matrix4()
The default constructor creates an identity matrix:
static Matrix4 Translation(const Vector3 &v)
Returns the translation matrix described by the vector.
Definition at line 50 of file matrix4.h.
|
| Matrix4 () |
| The default constructor creates an identity matrix: More...
|
|
| Matrix4 (const float *a) |
| Constructs a matrix given from an array of 16 floats in OpenGL matrix format (i.e., column major). More...
|
|
| Matrix4 (const std::vector< float > &a) |
| Constructs a matrix given from a vector of 16 floats in OpenGL matrix format (i.e., column major). More...
|
|
| Matrix4 (const Matrix4 &m2) |
| Copy constructor. More...
|
|
virtual | ~Matrix4 () |
| Destructor. More...
|
|
bool | operator== (const Matrix4 &m2) const |
| Check for "equality", taking floating point imprecision into account. More...
|
|
bool | operator!= (const Matrix4 &m2) const |
| Check for "inequality", taking floating point imprecision into account. More...
|
|
Matrix4 & | operator= (const Matrix4 &m2) |
| Matrix assignment operator. More...
|
|
const float * | value_ptr () const |
| Returns a pointer to the raw data array used to store the matrix. This is a 1D array of 16-elements stored in column-major order. More...
|
|
float | operator[] (const int i) const |
| Accesses the ith element of the raw data array used to store the matrix. This is a 1D array of 16-elements stored in column-major order. More...
|
|
float & | operator[] (const int i) |
| Accesses the ith element of the raw data array used to store the matrix. This is a 1D array of 16-elements stored in column-major order. More...
|
|
float | operator() (const int row, const int col) const |
| Access an individual element of the array using the syntax: Matrix4 mat; float row1col2 = mat(1,2);. More...
|
|
float & | operator() (const int row, const int col) |
| Access an individual element of the array using the syntax: Matrix4 mat; mat(1,2) = 1.0;. More...
|
|
Vector3 | ColumnToVector3 (int c) const |
| Returns the c-th column of the matrix as a Vector type, e.g.,: Vector3 xAxis = mat.getColumnAsVector3(0); Vector3 yAxis = mat.getColumnAsVector3(1); Vector3 zAxis = mat.getColumnAsVector3(2);. More...
|
|
Point3 | ColumnToPoint3 (int c) const |
| Returns the c-th column of the matrix as a Vector type, e.g.,: Point3 pos = mat.getColumnAsPoint3(3);. More...
|
|
std::vector< float > | ToVector () const |
|
Matrix4 | Inverse () const |
| Returns the inverse of the 4x4 matrix if it is nonsingular. If it is singular, then returns the identity matrix. More...
|
|
Matrix4 | Orthonormal () const |
| Returns an orthonormal version of the matrix, i.e., guarantees that the rotational component of the matrix is built from column vectors that are all unit vectors and orthogonal to each other. More...
|
|
Matrix4 | Transpose () const |
| Returns the transpose of the matrix. More...
|
|
float | SubDeterminant (int exclude_row, int exclude_col) const |
| Returns the determinant of the 3x3 matrix formed by excluding the specified row and column from the 4x4 matrix. More...
|
|
Matrix4 | Cofactor () const |
| Returns the cofactor matrix. More...
|
|
float | Determinant () const |
| Returns the determinant of the 4x4 matrix. More...
|
|
|
static Matrix4 | FromRowMajorElements (const float r1c1, const float r1c2, const float r1c3, const float r1c4, const float r2c1, const float r2c2, const float r2c3, const float r2c4, const float r3c1, const float r3c2, const float r3c3, const float r3c4, const float r4c1, const float r4c2, const float r4c3, const float r4c4) |
| Returns a matrix constructed from individual elements passed in row major order so that the matrix looks "correct" on the screen as you write this constructor on 4 lines of code as below. More...
|
|
static Matrix4 | Scale (const Vector3 &v) |
| Returns the scale matrix described by the vector. More...
|
|
static Matrix4 | Translation (const Vector3 &v) |
| Returns the translation matrix described by the vector. More...
|
|
static Matrix4 | RotationX (const float radians) |
| Returns the rotation matrix about the x axis by the specified angle. More...
|
|
static Matrix4 | RotationY (const float radians) |
| Returns the rotation matrix about the y axis by the specified angle. More...
|
|
static Matrix4 | RotationZ (const float radians) |
| Returns the rotation matrix about the z axis by the specified angle. More...
|
|
static Matrix4 | Rotation (const Point3 &p, const Vector3 &v, const float a) |
| Returns the rotation matrix around the vector v placed at point p, rotate by angle a. More...
|
|
static Matrix4 | Align (const Point3 &a_p, const Vector3 &a_v1, const Vector3 &a_v2, const Point3 &b_p, const Vector3 &b_v1, const Vector3 &b_v2) |
| Creates a transformation matrix that maps a coordinate space, a, defined one point, a_p, and two vectors, a_v1 and a_v2, to a new coordinate space, b, also defined by one point, b_p, and two vectors, b_v1 and b_v2. The transformation will thus include both some rotation and some translation. Pseudocode example of aligning a billboard defined in the XY plane with a normal in the +Z direction and that rotates around the Y axis with a camera: More...
|
|
static Matrix4 | LookAt (Point3 eye, Point3 target, Vector3 up) |
| Returns a view matrix that centers the camera at the 'eye' position and orients it to look at the desired 'target' point with the top of the screen pointed as closely as possible in the direction of the 'up' vector. More...
|
|
static Matrix4 | Perspective (float fov_y_in_degrees, float aspect_ratio, float near_plane_dist, float far_plane_dist) |
| Returns a perspective projection matrix equivalent to the one gluPerspective creates. More...
|
|
static Matrix4 | Frustum (float left, float right, float bottom, float top, float near_plane_dist, float far_plane_dist) |
| Returns a projection matrix equivalent the one glFrustum creates. More...
|
|
Creates a transformation matrix that maps a coordinate space, a, defined one point, a_p, and two vectors, a_v1 and a_v2, to a new coordinate space, b, also defined by one point, b_p, and two vectors, b_v1 and b_v2. The transformation will thus include both some rotation and some translation. Pseudocode example of aligning a billboard defined in the XY plane with a normal in the +Z direction and that rotates around the Y axis with a camera:
Point3 a_p = Point3(0,0,0);
Vector3 a_v1 = Vector3(0,1,0);
Vector3 a_v2 = Vector3(0,0,1);
Point3 b_p = desired_base_pos;
Vector3 b_v1 = Vector3(0,1,0);
Vector3 b_v2 = (camera.eye() - desired_base_pos);
b_v2[1] = 0.0;
b_v2.Normalize();
static Matrix4 Align(const Point3 &a_p, const Vector3 &a_v1, const Vector3 &a_v2, const Point3 &b_p, const Vector3 &b_v1, const Vector3 &b_v2)
Creates a transformation matrix that maps a coordinate space, a, defined one point,...