CUGL  2.0
Public Member Functions | Private Attributes | Friends | List of all members
cugl::Matrix Class Reference

#include <cugl.h>

Public Member Functions

 Matrix ()
 
 Matrix (GL_Matrix r)
 
 Matrix (GLenum mode)
 
 Matrix (const Vector &axis, double theta)
 
 Matrix (const Plane &refl)
 
 Matrix (const Point &lightPos, const Plane &plane)
 
 Matrix (const Quaternion &q)
 
 Matrix (const Vector &u, const Vector &v)
 
 Matrix (const GLfloat m00, const GLfloat m10, const GLfloat m20, const GLfloat m30, const GLfloat m01, const GLfloat m11, const GLfloat m21, const GLfloat m31, const GLfloat m02, const GLfloat m12, const GLfloat m22, const GLfloat m32, const GLfloat m03, const GLfloat m13, const GLfloat m23, const GLfloat m33)
 
Quaternion quaternion () const
 
GLfloat * get ()
 
Matrix transpose () const
 
GLfloat trace ()
 
Matrix inv () const
 
Matrix operator~ () const
 
void apply () const
 
Point apply (const Point &p) const
 
Vector apply (const Vector &v) const
 
Vector axis () const
 
double angle () const
 
GLfloat & operator() (int i, int j)
 
const GLfloat & operator() (int i, int j) const
 
void reflect (const Plane &p)
 
void shadow (const Point &lightPos, const Plane &plane)
 
Matrix operator+= (const Matrix &rhs)
 
Matrix operator-= (const Matrix &rhs)
 
Matrix operator*= (const Matrix &rhs)
 
Matrixoperator*= (GLfloat s)
 
Matrixoperator/= (GLfloat s)
 

Private Attributes

GL_Matrix m
 

Friends

Matrix operator+ (const Matrix &m, const Matrix &n)
 
Matrix operator- (const Matrix &m, const Matrix &n)
 
Matrix operator* (const Matrix &m, const Matrix &n)
 
Matrix operator* (GLfloat s, const Matrix &m)
 
Matrix operator* (const Matrix &m, GLfloat s)
 
Matrix operator/ (const Matrix &m, GLfloat s)
 
bool operator== (const Matrix &x, const Matrix &y)
 
bool operator!= (const Matrix &x, const Matrix &y)
 
std::ostream & operator<< (std::ostream &os, const Matrix &m)
 

Detailed Description

An instance is a matrix compatible with an OpenGL transformation matrix. An instance of class Matrix is a 4 by 4 matrix with components of type GLfloat. The components are ordered in the same way as an OpenGL matrix (column-row order, for compatibility with FORTRAN).

Note that OpenGL performs matrix calculations very efficiently. As far as possible, construct transformations using sequences of OpenGL matrix operations. Construct and use the matrices here only if OpenGL does not provide the required facilities.

Definition at line 873 of file cugl.h.

Constructor & Destructor Documentation

cugl::Matrix::Matrix ( )

Construct the identity matrix.

cugl::Matrix::Matrix ( GL_Matrix  r)

Construct a copy of an arbitrary OpenGL matrix.

cugl::Matrix::Matrix ( GLenum  mode)
explicit

Construct a copy of an OpenGL projection or model view matrix.

Parameters
modeshould be GL_PROJECTION_MATRIX or GL_MODELVIEW_MATRIX.

Report error BAD_MATRIX_MODE and construct identity matrix for other values of mode.

cugl::Matrix::Matrix ( const Vector axis,
double  theta 
)

Construct a rotation matrix.

Parameters
axisis the axis of rotation.
thetais the magnitude of the rotation.
Note
The angle theta should be in radians (unlike OpenGL, which uses degrees).
cugl::Matrix::Matrix ( const Plane refl)
inlineexplicit

Construct a matrix that reflects a point in the given plane. The matrix can be used to simulate a mirror in an OpenGL program. See also Matrix::reflect().

Parameters
reflis the plane of reflection.

Definition at line 2894 of file cugl.h.

References reflect().

cugl::Matrix::Matrix ( const Point lightPos,
const Plane plane 
)
inline

Construct a shadow matrix from a point light source and a plane. The matrix transforms an object into its shadow on the given plane. It is your job to ensure that the shadow has the appropriate colour, transparency, etc. The light source may be a local point (w > 0) or a point at infinity (w = 0). See also Matrix::shadow().

Parameters
lightPosis the position of the light source.
planeis the plane onto which the shadow is projected.

Definition at line 2899 of file cugl.h.

References shadow().

cugl::Matrix::Matrix ( const Quaternion q)
explicit

Construct a rotation matrix from a quaternion.

Precondition
The quaternion must be a unit quaternion.
cugl::Matrix::Matrix ( const Vector u,
const Vector v 
)

Construct the matrix that rotates one vector to another.

Parameters
uis a vector representing an initial orientation.
vis a vector representing the final orientation. The matrix, applied to u, will yield v.
Precondition
The vectors u and v must be unit vectors.
cugl::Matrix::Matrix ( const GLfloat  m00,
const GLfloat  m10,
const GLfloat  m20,
const GLfloat  m30,
const GLfloat  m01,
const GLfloat  m11,
const GLfloat  m21,
const GLfloat  m31,
const GLfloat  m02,
const GLfloat  m12,
const GLfloat  m22,
const GLfloat  m32,
const GLfloat  m03,
const GLfloat  m13,
const GLfloat  m23,
const GLfloat  m33 
)
inline

Construct a matrix from 16 floats.

Definition at line 2904 of file cugl.h.

References m.

Member Function Documentation

double cugl::Matrix::angle ( ) const

Return the angle (in radians) of a rotation matrix. Report error BAD_ROTATION_MATRIX and leave result undefined, if the matrix is not a rotation.

Returns
the angle (in radians) of a rotation matrix.
void cugl::Matrix::apply ( ) const
inline

Multiply the current OpenGL matrix by this matrix.

Definition at line 2941 of file cugl.h.

References m.

Point cugl::Matrix::apply ( const Point p) const
inline

Apply this matrix to a point.

Definition at line 2930 of file cugl.h.

References m, cugl::Point::w, cugl::Point::x, cugl::Point::y, and cugl::Point::z.

Vector cugl::Matrix::apply ( const Vector v) const
inline

Apply this matrix to a vector.

Definition at line 2966 of file cugl.h.

References m.

Vector cugl::Matrix::axis ( ) const

Return the axis of a rotation matrix. Report error BAD_ROTATION_MATRIX and leave result undefined, if the matrix is not a rotation.

Returns
the axis of a rotation matrix.
GLfloat * cugl::Matrix::get ( )
inline

Return a pointer to the first element of the matrix. This function may be used in conjunction with glMultMatrix() to apply this matrix to the current OpenGL matrix.

Returns
a pointer to the first element of the matrix.

Definition at line 2946 of file cugl.h.

References m.

Matrix cugl::Matrix::inv ( ) const

Compute the inverse of this matrix using Gauss-Jordan elimination. If the matrix is singular, report SINGULAR_MATRIX and return the zero matrix. Calculations are performed in double precision because this gives slightly better results. The prefix operator ~ has the same effect.

Returns
the inverse of this matrix.

Referenced by operator~().

GLfloat & cugl::Matrix::operator() ( int  i,
int  j 
)
inline

Return a reference to the element m[i][j] of the matrix.

Precondition
The values of i and j must be in the range [0,3].
Returns
the element m[i][j] of the matrix.

Definition at line 2951 of file cugl.h.

References m.

const GLfloat & cugl::Matrix::operator() ( int  i,
int  j 
) const
inline

Return a reference to the element m[i][j] of the const matrix. This version is used for const instances (m(i,j) cannot appear on the left of =).

Precondition
The values of i and j must be in the range [0,3].
Returns
the element m[i][j] of the matrix.

Definition at line 2956 of file cugl.h.

References m.

Matrix cugl::Matrix::operator*= ( const Matrix rhs)
inline

Multiply and assign matrices.

Definition at line 3051 of file cugl.h.

Matrix & cugl::Matrix::operator*= ( GLfloat  s)
inline

Multiply by scalar and assign.

Definition at line 2998 of file cugl.h.

References m.

Matrix cugl::Matrix::operator+= ( const Matrix rhs)
inline

Add and assign matrices.

Definition at line 3021 of file cugl.h.

References m.

Matrix cugl::Matrix::operator-= ( const Matrix rhs)
inline

Subtract and assign matrices.

Definition at line 3036 of file cugl.h.

References m.

Matrix & cugl::Matrix::operator/= ( GLfloat  s)
inline

Divide by scalar and assign.

Definition at line 2977 of file cugl.h.

References m.

Matrix cugl::Matrix::operator~ ( ) const
inline

Return the inverse of this matrix. This provides an alternative syntax for inv().

Returns
the inverse of this matrix.

Definition at line 2961 of file cugl.h.

References inv().

Quaternion cugl::Matrix::quaternion ( ) const

Return the quaternion corresponding to this matrix. This function may report BAD_ROTATION_MATRIX.

Note
The result may be imprecise if the rotation angle is close to 180 degrees.
Precondition
The matrix must be a rotation matrix.
void cugl::Matrix::reflect ( const Plane p)

Set the matrix so that it reflects a point in the plane p. The matrix can be used to simulate a mirror in an OpenGL program. See also constructors for class Matrix.

Parameters
pis the plane of reflection.

Referenced by Matrix().

void cugl::Matrix::shadow ( const Point lightPos,
const Plane plane 
)

Set the matrix so that it creates a shadow on the plane p from a light source lightPos. The matrix transforms an object into its shadow on the given plane. It is your job to ensure that the shadow has the appropriate colour, transparency, etc. The point p may be either a local point (w > 0) or a point at infinity (w = 0). See also constructors for class Matrix.

Parameters
lightPosis the position of the light source causing the shadow.
planeis the plane upon which the shadow is cast.

Referenced by Matrix().

GLfloat cugl::Matrix::trace ( )
inline

Return the trace of this matrix. The trace will include the bottom right element, m[3][3].

Definition at line 974 of file cugl.h.

References m.

Matrix cugl::Matrix::transpose ( ) const

Return the transpose of this matrix.

Friends And Related Function Documentation

bool operator!= ( const Matrix x,
const Matrix y 
)
friend

Compare two matrices. This function returns false only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 3088 of file cugl.h.

Matrix operator* ( const Matrix m,
const Matrix n 
)
friend

Multiply two matrices.

Definition at line 3057 of file cugl.h.

Matrix operator* ( GLfloat  s,
const Matrix m 
)
friend

Multiply scalar and matrix.

Definition at line 3097 of file cugl.h.

Matrix operator* ( const Matrix m,
GLfloat  s 
)
friend

Multiply matrix and scalar.

Definition at line 3106 of file cugl.h.

Matrix operator+ ( const Matrix m,
const Matrix n 
)
friend

Add two matrices.

Definition at line 3029 of file cugl.h.

Matrix operator- ( const Matrix m,
const Matrix n 
)
friend

Subtract two matrices.

Definition at line 3044 of file cugl.h.

Matrix operator/ ( const Matrix m,
GLfloat  s 
)
friend

Divide by scalar.

Definition at line 3115 of file cugl.h.

std::ostream& operator<< ( std::ostream &  os,
const Matrix m 
)
friend

Write a four-line image of the matrix to the output stream. The current settings of the stream formatting parameters are used. If a width is specified with setw(), it is applied to each element of the matrix, not the matrix as a whole.

bool operator== ( const Matrix x,
const Matrix y 
)
friend

Compare two matrices. This function returns true only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 3079 of file cugl.h.

Member Data Documentation

GL_Matrix cugl::Matrix::m
private

The elements of the matrix.

Definition at line 1121 of file cugl.h.

Referenced by apply(), get(), Matrix(), operator()(), operator*=(), operator+=(), operator-=(), operator/=(), and trace().


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