Matrix Math

class Mat4

This class implements a 4x4 real-valued matrix. Individual elements are represented with double precision floating point numbers. To use the Mat4 class you must include the header

    #include <gfx/mat4.h>

Constructor Methods

The Mat4 class defines the following set of constructors:

    // Initialize all elements to 0
    Mat4();

    // Initialize rows with given vectors
    Mat4(const Vec4& r0,const Vec4& r1,const Vec4& r2,const Vec4& r3);

    // Copy values from A
    Mat4(const Mat4& A);

Transformation Functions

Because 4x4 matrices are commonly used to represent linear homogeneous transformations in computer graphics, the matrix package provides several functions to construct transformation matrices. The operation of these functions is based directly on the definition of the corresponding transformations as used in OpenGL. The resulting matrices should be equivalent to those produced by OpenGL, to the extent allowed by limited floating point accuracy.

    // Construct translation, scaling, and rotation matrices.
    Mat4 translation_matrix(const Vec3& delta);
    Mat4 scaling_matrix(const Vec3& scale);
    Mat4 rotation_matrix_deg(double theta, const Vec3& axis);
    Mat4 rotation_matrix_rad(double theta, const Vec3& axis);

    // Construct a perspective projection matrix.
    // Direct analog of gluPerspective()
    Mat4 perspective_matrix(double fovy, double aspect,
                            double zmin=0.0, double zmax=0.0);

    // Construct a viewing transformation.
    // Direct analog of gluLookAt()
    Mat4 lookat_matrix(const Vec3& from, const Vec3& at, const Vec3& up);

    // Construct a viewport mapping.
    // Direct analog of glViewport().
    Mat4 viewport_matrix(double w, double h);
Note that the rotation_matrix() function comes in two forms, once which expects an angle in radians and one which expects an angle in degrees. The type of angle expected is made explicit in the function name (i.e., _rad and _deg suffixes) in an attempt to avoid confusion.