cugl::Matrix Class Reference

#include <cugl.h>

List of all members.

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)
Quaternion quaternion () const
GLfloat * get ()
Matrix transpose () const
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)

Private Attributes

GL_Matrix m

Friends

Matrix operator * (const Matrix &m, const Matrix &n)
bool operator== (const Matrix &x, const Matrix &y)
bool operator!= (const Matrix &x, const Matrix &y)
std::ostream & operator<< (std::ostream &os, 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 829 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  ) 

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

Parameters:
mode should 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:
axis is the axis of rotation.
theta is the magnitude of the rotation.
Note:
The angle theta should be in radians (unlike OpenGL, which uses degrees).

cugl::Matrix::Matrix ( const Plane refl  )  [inline]

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:
refl is the plane of reflection.

Definition at line 2706 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:
lightPos is the position of the light source.
plane is the plane onto which the shadow is projected.

Definition at line 2711 of file cugl.h.

References shadow().

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

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:
u is a vector representing an initial orientation.
v is a vector representing the final orientation. The matrix, applied to u, will yield v.
Precondition:
The vectors u and v must be unit vectors.


Member Function Documentation

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.

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 2734 of file cugl.h.

References m.

Matrix cugl::Matrix::transpose (  )  const

Return the transpose of this matrix.

Matrix cugl::Matrix::inv (  )  const

Return the inverse of this matrix. The function uses Cramer's method: compute the matrix of cofactors and divide each element by the determinant. If the matrix is singular, report SINGULAR_MATRIX and return the zero matrix. The prefix operator ~ has the same effect.

Returns:
the inverse of this matrix.

Referenced by operator~().

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 2749 of file cugl.h.

References inv().

void cugl::Matrix::apply (  )  const [inline]

Multiply the current OpenGL matrix by this matrix.

Definition at line 2729 of file cugl.h.

References m.

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

Apply this matrix to a point.

Definition at line 2718 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 2754 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.

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.

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 2739 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 2744 of file cugl.h.

References m.

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:
p is 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:
lightPos is the position of the light source causing the shadow.
plane is the plane upon which the shadow is cast.

Referenced by Matrix().


Friends And Related Function Documentation

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

Multiply two matrices.

Definition at line 2767 of file cugl.h.

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 2789 of file cugl.h.

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 2798 of file cugl.h.

std::ostream& operator<< ( std::ostream &  os,
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.


Member Data Documentation

GL_Matrix cugl::Matrix::m [private]

The elements of the matrix.

Definition at line 1031 of file cugl.h.

Referenced by apply(), get(), cugl::operator *(), cugl::operator!=(), operator()(), and cugl::operator==().


The documentation for this class was generated from the following file:
Generated on Wed Sep 12 14:31:42 2007 for CUGL by  doxygen 1.5.2