module2b_cg
module2b_cg
Module 2 - b
Module 2 - b
or
1
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
CODE:
typedef GLfloat Matrix4x4 [4][4];
/* Construct the 4 x 4 identity matrix. */
void matrix4x4SetIdentity (Matrix4x4 matIdent4x4)
{
GLint row, col;
for (row = 0; row < 4; row++)
for (col = 0; col < 4 ; col++)
matIdent4x4 [row][col] = (row == col);
}
void translate3D (GLfloat tx, GLfloat ty, GLfloat tz)
{
Matrix4x4 matTransl3D;
/* Initialize translation matrix to identity. */
matrix4x4SetIdentity (matTransl3D);
2
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
3
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
Transformation equations for rotations about the other two coordinate axes can be
obtained with a cyclic permutation of the coordinate parameters x, y, and z
x → y→ z→ x
Along x axis
Along y axis
1. Translate the object so that the rotation axis coincides with the parallel coordinate axis.
4
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
A coordinate position P is transformed with the sequence shown in this figure as
When an object is to be rotated about an axis that is not parallel to one of the coordinate
axes, we must perform some additional transformations we can accomplish the required
rotation in five steps:
1. Translate the object so that the rotation axis passes through the coordinate origin.
2. Rotate the object so that the axis of rotation coincides with one of the coordinate axes.
3. Perform the specified rotation about the selected coordinate axis.
4. Apply inverse rotations to bring the rotation axis back to its original orientation.
5. Apply the inverse translation to bring the rotation axis back to its original spatial position.
5
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
Where the components a, b, and c are the direction cosines for the rotation axis
The first step in the rotation sequence is to set up the translation matrix that repositions
the rotation axis so that it passes through the coordinate origin.
Translation matrix is given by
Because rotation calculations involve sine and cosine functions, we can use standard
vector operations to obtain elements of the two rotation matrices.
A vector dot product can be used to determine the cosine term, and a vector cross product
can be used to calculate the sine term.
Rotation of u around the x axis into the x z plane is accomplished by rotating u’ (the
projection of u in the y z plane) through angle α onto the z axis.
If we represent the projection of u in the yz plane as the vector u’= (0, b, c), then the
cosine of the rotation angle α can be determined from the dot product of u’ and the unit
vector uz along the z axis:
6
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
or
We have determined the values for cos α and sin α in terms of the components of vector
u, the matrix elements for rotation of this vector about the x axis and into the xz plane
Rotation of unit vector u” (vector u after rotation into the x z plane) about the y axis.
Positive rotation angle β aligns u” with vector uz .
We can determine the cosine of rotation angle β from the dot product of unit vectors u’’
and uz. Thus,
7
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
The specified rotation angle θ can now be applied as a rotation about the z axis as
follows:
The transformation matrix for rotation about an arbitrary axis can then be expressed as
the composition of these seven individual transformations:
The composite matrix for any sequence of three-dimensional rotations is of the form
8
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
Assuming that the rotation axis is not parallel to any coordinate axis, we could form the
following set of local unit vectors
If we express the elements of the unit local vectors for the rotation axis as
Then the required composite matrix, which is equal to the product Ry(β) · Rx(α), is
9
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
10
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
The three-dimensional scaling transformation for a point position can be represented as
where scaling parameters sx, sy, and sz are assigned any positive values.
Explicit expressions for the scaling transformation relative to the origin are
Because some graphics packages provide only a routine that scales relative to the
coordinate origin, we can always construct a scaling transformation with respect to any
selected fixed position (xf , yf , zf ) using the following transformation sequence:
1. Translate the fixed point to the origin.
2. Apply the scaling transformation relative to the coordinate origin
3. Translate the fixed point back to its original position.
This sequence of transformations is demonstrated
11
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
CODE:
class wcPt3D
{
private:
GLfloat x, y, z;
public:
/* Default Constructor:
12
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
13
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
The matrix representation for this reflection relative to the xy plane is
Three-Dimensional Shears
These transformations can be used to modify object shapes.
For three-dimensional we can also generate shears relative to the z axis.
A general z-axis shearing transformation relative to a selected reference position is
produced with the following matrix:
A unit cube (a) is sheared relative to the origin (b) by Matrix 46, with shzx = shzy = 1.
14
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
Affine transformations (in two dimensions, three dimensions, or higher dimensions) have
the general properties that parallel lines are transformed into parallel lines, and finite
points map to finite points.
Translation, rotation, scaling, reflection,andshear are examples of affine transformations.
Another example of an affine transformation is the conversion of coordinate descriptions
for a scene from one reference system to another because this transformation can be
described as a combination of translation and rotation
15
Computer Graphics and Fundamentals for Image Processing (21CS63)
Module 3
We have two functions available in OpenGL for processing the matrices in a stack
glPushMatrix ( );
Copy the current matrix at the top of the active stack and store that copy in the second
stack position
glPopMatrix ( );
which destroys the matrix at the top of the stack, and the second matrix in the stack
becomes the current matrix
16
Module 3
Computer Graphics and Fundamentals for Image Processing (21CS63)