There are two matrix stacks that transform and project geometric primitives
to the screen. One matrix stack is called the EZ_MODELVIEW
. The
top matrix on this stack is used to transform the current primitive to the eye
coordinate space. The other stack is called EZ_PROJECTION
. The
top matrix on this stack is used to project the transformed geometric
primitives to the normalized screen space.
To set the current matrix mode, use
void EZ_MatrixMode(int mode)
The EZ graphics library uses row vectors. If the
top matrix on the
EZ_MODELVIEW
stack is and the top
matrix on the
EZ_PROJECTION
stack is , then for any given
vector
, the transformed coordinate in the eye
coordinate space is
; and the
projected coordinate in the homogeneous screen space (unclipped) is
. This coordinate is then clipped and
scaled to the current viewport.
There are quite a few routines for manipulating matrices. We'll describe them now.
void EZ_LoadIdentity(void)
This function resets the top matrix of the currment matrix stack to Identity.
void EZ_LoadMatrix(EZ_Matrix M)
This function replace the top matrix of the current matrix stack by
matrix M
.
void EZ_MultMatrix(EZ_Matrix M)
This function left multiply the top matrix of the current matrix stack by
matrix . If the current top matrix is
, this function
replaces
with
.
void EZ_GetMatrix(EZ_Matrix M)
This function copies the top matrix of the current matrix stack to the
given matrix .
void EZ_PushMatrix(void)
This function pushes down the current matrix stack, duplicating the top matrix.
void EZ_PopMatrix(void)
This function pops the current matrix stack.
The following routines are normally used to modify the projection matrices.
void EZ_Ortho(float l, float r, float b, float t
float n, float f)
This function defines a box-shaped encloure in the eye coordinate
system. l, r,b,t,n,f
specifies the boundries of the box,
they are the clipping planes. This function multiply the current
matrix by
void EZ_Ortho2(float left, float right, float bottom, float top)
This routine sets up a 2D clipping rectangle. It is equivalent to
EZ_Ortho
with parameter n = -1.0, f= 1.0
.
void EZ_Perspective(float fov, float, asp, float n, float f)
This routine defines a perspective viewing pyramid inside the eye
coordinate system. The vertical direction is the direction in
the eye coordinate system. This function multiply the current matrix by
void EZ_Frustum(float l, float r, float b,
float t, float n, float f)
This routine defines a perspective viewing pyramid inside the eye
coordinate system. The eye is at the origin. The lower-left and
upper-right corners of the near clipping window are
and
. The parameter
specifies the
distance from the eye to the far clipping plane. This
function multiply the current matrix by
The following command is normally used to define the eye coordinate system.
void EZ_LookAt(float vx, float vy, float vz,
float px, float py, float pz,
float ux, float uy, float uz)
This routine defines a view point and a reference point on the line of sight, together with a view up vector which defines the direction of the y-axis of the eye coordinate system. This function multiply the current matrix by
Trans(-vx,-vy,-vz)M where is a matrix described below.
Let ,
and define
Then
Equivalently, let
,
,
,
,
and
.
Then
The next few routines are general purpose commands for manipulating matrices.
void EZ_Translate(float x, float y, float z)
This command multiply the current matrix by
void EZ_Scale(float x, float y, float z)
This command multiply the current matrix by
void EZ_Rotate(float angle, float x, float y, float z)
This command multiply the current matrix by
where is the matrix
where ,
and
.
void EZ_GenerateRotationMatrix(EZ_Matrix M,
float angle, float x, float y, float z)
This command generate the rotation matrix
Rot(angle, x,y,z) and copy the result to the given matrix
.