ident, matmul, matmulr, determinant, adjoint, invertmat, xformpoint, xformpointd, xformplane, pushmat, popmat, rot, qrot, scale, move, xform, ixform, persp, look, viewport – Geometric transformations
void ident(Matrix m)
void matmul(Matrix a, Matrix b)
void matmulr(Matrix a, Matrix b)
double determinant(Matrix m)
void adjoint(Matrix m, Matrix madj)
double invertmat(Matrix m, Matrix inv)
Point3 xformpoint(Point3 p, Space *to, Space *from)
Point3 xformpointd(Point3 p, Space *to, Space *from)
Point3 xformplane(Point3 p, Space *to, Space *from)
Space *pushmat(Space *t)
Space *popmat(Space *t)
void rot(Space *t, double theta, int axis)
void qrot(Space *t, Quaternion q)
void scale(Space *t, double x, double y, double z)
void move(Space *t, double x, double y, double z)
void xform(Space *t, Matrix m)
void ixform(Space *t, Matrix m, Matrix inv)
int persp(Space *t, double fov, double n, double f)
void look(Space *t, Point3 eye, Point3 look, Point3 up)
void viewport(Space *t, Rectangle r, double aspect)
These routines manipulate 3-space affine and projective transformations,
represented as 4×4 matrices, thus:
typedef double Matrix;
stores an identity matrix in its argument.
returns the determinant of matrix
stores the adjoint (matrix of cofactors) of
stores the inverse of matrix
be singular (determinant zero),
The rest of the routines described here
is a point in three-space, represented by its
typedef struct Point3 Point3;
double x, y, z, w;
The homogeneous coordinates
represent the Euclidean point
and a “point at infinity” if
is just a data structure describing a coordinate system:
typedef struct Space Space;
It contains a pair of transformation matrices and a pointer
parent. The matrices transform points to and from the “root
coordinate system,” which is represented by a null
creates a new
Its argument is a pointer to the parent space. Its result
is a newly allocated copy of the parent, but with its
pointer pointing at the parent.
that is its argument, returning a pointer to the stack.
Nominally, these two functions define a stack of transformations,
can be called multiple times
on the same
multiple times, creating a transformation tree.
both transform points from the
pointed to by
to the space pointed to by
Either pointer may be null, indicating the root coordinate system.
The difference between the two functions is that
the Euclidean coordinates of the point.
transforms planes or normal vectors. A plane is specified by the
of its implicit equation
Since this representation is dual to the homogeneous representation of points,
represents planes by
The remaining functions transform the coordinate system represented
argument must be non-null you can’t modify the root
rotates by angle
(in radians) about the given
which must be one of
transforms by a rotation about an arbitrary axis, specified by
scales the coordinate system by the given scale factors in the directions of the three axes.
translates by the given displacement in the three axial directions.
transforms the coordinate system by the given
If the matrix’s inverse is known
will save the work of recomputing it.
does a perspective transformation.
The transformation maps the frustum with apex at the origin,
central axis down the positive
axis, and apex angle
and clipping planes
into the double-unit cube.
does a view-pointing transformation. The
point is moved to the origin.
The line through the
points is aligned with the y axis,
and the plane containing the
points is rotated into the
maps the unit-cube window into the given screen viewport.
The viewport rectangle
at the top left-hand corner, and
just outside the lower right-hand corner.
is the aspect ratio
of the viewport’s pixels (not of the whole viewport).
The whole window is transformed to fit centered inside the viewport with equal
slop on either top and bottom or left and right, depending on the viewport’s
The window is viewed down the
to the left and
up. The viewport
increasing to the right and
increasing down. The window’s
coordinates are mapped, unchanged, into the viewport’s