0% found this document useful (0 votes)
14 views90 pages

Module 3 PT

The document discusses geometric objects and transformations in OpenGL, detailing the sequence of coordinate frames from model to display, including transformations like translation, rotation, and scaling. It explains how to model a color cube using vertex arrays and affine transformations, emphasizing the importance of vertex order for face visibility and color interpolation methods. The content is structured into sections covering frames, modeling, and transformations, providing practical examples and code snippets for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views90 pages

Module 3 PT

The document discusses geometric objects and transformations in OpenGL, detailing the sequence of coordinate frames from model to display, including transformations like translation, rotation, and scaling. It explains how to model a color cube using vertex arrays and affine transformations, emphasizing the importance of vertex order for face visibility and color interpolation methods. The content is structured into sections covering frames, modeling, and transformations, providing practical examples and code snippets for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 90

Geometric Objects and

Transformation
Module 3
Table Of Contents
3.1 Frames in OpenGL
3.2 Modelling a color cube
3.3 Affine Transformations
3.4 Translation, Rotation, Scaling
3.5 Transformation in Homogeneous coordinates
3.6 Concatenation of Transformations
Frames in OpenGL
• OpenGL is based on a pipeline model, the first part of which is a
sequence of operations on vertices.
• We can characterize these geometric operations by a sequence of
transformations or, equivalently, as a sequence of changes of frames
for the objects defined by a user program.
• In a typical application, there are six frames embedded in the
pipeline, although normally the programmer will not see more than a
few of them directly.
• In each of these frames, a vertex has different coordinates.
• The following is the order that the systems occur in the
pipeline
1. Object or model coordinates
2. World coordinates
3. Eye (or camera) coordinates
4. Clip coordinates
5. Normalized device coordinates
6. Window (or screen) coordinates

Model World View Clip NDC Display


Coordinate Representation
Model Coordinate

Model World View CLIP NDC Display

Local or modeling coordinates


We tend to specify or use an object with
a convenient size, orientation, and location in its
own frame called the model or object frame.

Geometric modeling
Coordinate Representation
Model Coordinate
• As an example, we could construct a bicycle by defining each of its parts
(wheels, frame, seat, handlebars, gears, chain, pedals) in a separate model-
coordinate frame.
Model Coordinate to World Coordinate
• Then, the component parts are fitted together in world coordinates.
• If both bicycle wheels are the same size, we need to describe only one
wheel in a local-coordinate frame (model-coordinate frame).
• Then the wheel description is fitted into the world-coordinate bicycle
description in two places.
Coordinate Representation
From Model to World

Model World View CLIP NDC Display

Position cylinders in scene:

World coordinates
Coordinate Representation
World Coordinate to View Coordinate
• World-coordinate positions are first converted to viewing coordinates
corresponding to the view we want of a scene, based on the position and
orientation of a hypothetical camera.
• The transformation from model coordinates to world coordinates and from
world coordinates to eye coordinates.
• In OpenGL, these transformations are concatenated together into the
model-view transformation, which is specified by the model-view matrix.
Coordinate Representation
From World to View

Model World View CLIP NDC Display

View
• The image that is produced depends on what the camera
or viewer sees.
• Virtually all graphics systems use a frame whose origin is
the center of the camera’s lens and whose axes are
aligned with the sides of the camera.
• This frame is called the camera frame or eye frame.
Viewing coordinates
Coordinate Representation
From View to Clip
• Once objects are in eye coordinates, OpenGL must check whether
they lie within the view volume.
• If an object does not, it is clipped from the scene prior to
rasterization.
• We need to identify visible surfaces and eliminate picture parts
outside the bounds for the view we want to show on the display
device.
• OpenGL can carry out this process most efficiently if it first carries
out a projection transformation that brings all potentially visible
objects into a cube centered at the origin in clip coordinates.
Coordinate Representation
From View to Clip

Model World View Clip NDC Display

Visible surfaces, shading


Coordinate Representation
Clip to Normalized Device Coordinates (NDC)
• Then object locations are transformed to a two-dimensional (2D) projection of the
scene, which corresponds to what we will see on the output device.
• The scene is then stored in normalized coordinates, where each coordinate value
is in the range from −1 to 1 or in the range from 0 to 1, depending on the system.
• Normalized coordinates are also referred to as normalized device coordinates,
since using this representation makes a graphics package independent of the
coordinate range for any specific output device.
Coordinate Representation
From Clip to NDC

Model World View Clip NDC Display

Display:
1
Normalized Device Coordinates

0 1
Coordinate Representation
Normal to Screen Coordinates
• Finally, the picture is scan-converted into the refresh buffer of a raster
system for display.
• The coordinate systems for display devices are generally called device
coordinates, or screen coordinates in the case of a video monitor.
• Often, both normalised coordinates and screen coordinates are
specified in the left handed coordinate reference frame.
Coordinate Representation
• An initial modeling-coordinate position (xmc , ymc , zmc ) in this
illustration is transferred to world coordinates, then to viewing and
projection coordinates, then to left-handed normalized coordinates,
and finally to a device-coordinate position (xdc , ydc ) with the
sequence:
Coordinate Representation
Normal to Screen Coordinates

Model World View Clip NDC Display

Display on screen:
0
1024 Device Coordinates

768
Interaction
3.2 Modelling A Colored Cube

• A program that draws a rotating cube. One frame of an animation might be


as shown in Figure 4.28.
• However, before we can rotate the cube, we will consider how we can
model it efficiently.
• Vertices will flow through a number of transformations in the pipeline, all
of which will use our homogeneous-coordinate representation.
• At the end of the pipeline awaits the rasterizer.
• At this point, we can assume it will do its job automatically, provided we
perform the preliminary steps correctly.
3.2.1 Modelling the Faces
• The cube as an object defined by eight vertices.
• Hence decision to use surface-based models implies that we regard a cube
either as the intersection of six planes or as the six polygons, called facets, that
define its faces.
• We start by assuming that the vertices of the cube are available through an
array of vertices;
• for example, we could use the following:
GLfloat vertices[8][3] = { {-1.0 , -1.0 , -1.0} , {-1.0 , 1.0 , -1.0} , {1.0 , 1.0 , -1.0},
{1.0 , -1.0 , -1.0} , {-1.0 , -1.0 , 1.0} , {-1.0 , 1.0 , 1.0},
{1.0 , 1.0 , 1.0} , {1.0 , -1.0 , 1.0} };
• OpenGL represents all vertices internally in four-dimensional
homogeneous coordinates.
• Function calls using a three-dimensional type, such as glVertex3fv,
have the values placed into a four-dimensional form within the
graphics system.
• We can then use the list of points to specify the faces of the cube.
• For example, one face is
glBegin(GL_POLYGON);
glVertex3fv(vertices[0]);
glVertex3fv(vertices[3]);
glVertex3fv(vertices[2]);
glVertex3fv(vertices[1]);
glEnd();
and we can define the other five faces similarly.
3.2.2 Inward and Outward- Pointing Faces
• We have to be careful about the order in which we specify our vertices when
we are defining a three-dimensional polygon.
• The edges of the polygon are traversed in the reverse order—0, 3, 2, 1—as
shown in Figure 4.29.
• The order is important because each polygon has two sides.
• We call a face outward facing if the vertices are traversed in a
counterclockwise order when the face is viewed from the
outside.
• This method is also known as the right-hand rule because if you
orient the fingers of your right hand in the direction the vertices
are traversed, the thumb points outward.
• In our example, the order 0, 3, 2, 1 specifies an outward face of
the cube whereas the order 0, 1, 2, 3 specifies the back face of
the same polygon.
• By specifying front and back carefully, we will be able to
eliminate (or cull) faces that are not visible
3.2.3 Data Structures for Object Representation
• We could now describe our cube through a set of vertex specifications. For
example, we could use

glBegin(GL_POLYGON)

• Six times, each time followed by four vertices via glVertex and a glEnd, or
we could use
glBegin(GL_QUADS)
The data specifying the location of the vertices contain the geometry and can
be stored as a simple list or array, such as in vertices[8]—the vertex list.
3.2.4 The Color Cube
• We can use the vertex list to define a color cube.
• We assign the colors of the vertices of the color solid.
• We define a function quad to draw quadrilateral polygons specified by pointers into the
vertex list.
• We assign a color for the face using the index of the first vertex.
• Finally, the colorcube specifies the six faces, taking care to make them all outward-
facing as follows:
GLfoat vertices[8][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},{1.0,1.0,1.0},
{1.0,1.0,1.0},{-1.0,-1.0,-1.0}, {-1.0,1.0,-1.0},
{1.0,1.0,-1.0}, {1.0,-1.0,-1.0}};

GLfloat colors[8][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0},


{0.0,0.0,1.0},{1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};
void quad(int a, int b, int c, int d)
{ void colorcube()
glBegin(GL_QUADS); {
glColor3fv(colors[a]); quad(0,3,2,1);
glVertex3fv(vertices[a]); quad(2,3,7,6);
glColor3fv(colors[b]); quad(0,4,7,3);
glVertex3fv(vertices[b]); quad(1,2,6,5);
glColor3fv(colors[c]); quad(4,5,6,7);
glVertex3fv(vertices[c]); quad(0,1,5,4);
glColor3fv(colors[d]); }
glVertex3fv(vertices[d]);
glEnd();
}
Bilinear Interpolation
• The graphics system must decide how to assign colors to points inside the
polygon.
• There are many ways to use the colors of the vertices to fill in, or interpolate,
colors across a polygon.
• The most common methods—ones that we use in other contexts—are based
on bilinear interpolation.
• Consider the polygon shown in Figure 4.31.
• The colors 𝑪𝟎 , 𝑪𝟏 , 𝑪𝟐 and 𝑪𝟑 are the ones
assigned to the vertices in the application
program.
• Assume that we are using RGB color and that the interpolation is applied
individually to each primary color.
• We first use linear interpolation to interpolate colors, along the edges
between vertices 0 and 1, and between 2 and 3, creating RGB colors along the
edges through the parametric equations as follows:
𝑪𝟎𝟏 𝜶 = 𝟏 − 𝜶 𝑪𝟎 + 𝜶𝑪𝟏
𝑪𝟐𝟑 𝜶 = 𝟏 − 𝜶 𝑪𝟐 + 𝜶𝑪𝟑
• As α goes from 0 to 1, we generate colors, 𝑪𝟎𝟏 𝜶 and 𝑪𝟐𝟑 𝜶 ,
along these two edges.
• For a given value of α, we obtain two colors, 𝑪𝟒 and 𝑪𝟓 , on these
edges.
• We can now interpolate colors along the line connecting the two
points on the edges corresponding to 𝑪𝟒 and 𝑪𝟓 as follows:

𝑪𝟒𝟓 𝜷 = 𝟏 − 𝜷 𝑪𝟒 + 𝜷𝑪𝟓
3.2.6Vertex Arrays
• Although we used vertex lists to model our cube,
when we draw the cube we are making many calls to
OpenGL functions.
• If we assign a color to each vertex, we make 60
OpenGL calls: six faces, each of which needs a glBegin,
a glEnd, four calls to glColor, and four calls to glVertex.
• Each call involves overhead and data transfer.
• Vertex arrays provide a method for encapsulating the
information in our data structure such that we can
draw polyhedral objects with only a few function calls.
• They allow us to define a data structure using vertices
and pass this structure to the implementation.
• When the objects defined by these arrays need to be
drawn, we can ask OpenGL to traverse the structure
with just a few function calls.
GLfoat vertices[8][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},{1.0,1.0,1.0},
{1.0,1.0,1.0},{-1.0,-1.0,-1.0}, {-1.0,1.0,-1.0},
{1.0,1.0,-1.0}, {1.0,-1.0,-1.0}};

GLfloat colors[8][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0},


{0.0,1.0,0.0},{0.0,0.0,1.0},{1.0,0.0,1.0},
{1.0,1.0,1.0}, {0.0,1.0,1.0}};
void quad(int a, int b, int c, int d)
{ void colorcube()
glBegin(GL_QUADS); {
glColor3fv(colors[a]); quad(0,3,2,1);
glVertex3fv(vertices[a]); quad(2,3,7,6);
glColor3fv(colors[b]); quad(0,4,7,3);
glVertex3fv(vertices[b]); quad(1,2,6,5);
glColor3fv(colors[c]); quad(4,5,6,7);
glVertex3fv(vertices[c]); quad(0,1,5,4);
glColor3fv(colors[d]); }
glVertex3fv(vertices[d]);
glEnd();
}
3.3 Affine Transformations
• A coordinate transformation of the form
x’ = axx x + axy y + axz z + bx
y’ = ayx x + ayy y + ayz z + by
z’ = azx x + azy y + azz z + bz
is called an affine transformation.
• Each of the transformed coordinates 𝒙′ , 𝒚′ , and 𝒛′ is a linear function
of the original coordinates x, y, and z, and parameters 𝒂𝒊𝒋 and k are
constants determined by the transformation type.
3.3 Affine Transformations
• 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, and shear are examples of


affine transformations.
Translation
2D Translations
Point P defined as P( x, y ),
translate to Point P( x, y) a distance d x parallel to x axis, d y parallel to y axis.
x = x + d x y  = y + d y P’

Define the column vec tors


 x  x  d x 
P =   , P =   , T =   P
 y  y  dy 
Now
P = P + T
2D Scaling from the origin.
Point P defined as P ( x, y ),
Perform a scale (stretch) to Point P( x, y) by a factor s x along the x axis,
and s y along the y axis.
x = s x . x, y = s y . y
Define the matrix
sx 0 P’
S=
0 s y  P

Now
 x   s x 0  x 
P = S  P  y =  0 s y   y 
or .
  
2D Rotation about the origin.


P’(x’,y’)

P(x,y)
r

r
x
2D Rotation about the origin.

P’(x’,y’)

r
P(x,y) x = r. cos 
y = r. sin 
 y
r

x
x
2D Rotation about the origin.
x = r. cos( +  ) = r. cos  . cos  − r. sin  . sin 
y y = r. sin( +  ) = r. cos  . sin  + r. sin  . cos 

P’(x’,y’)

P(x,y)
r x = r. cos 
y = r. sin 
 y
r

x
x
2D Rotation about the origin.
x = r. cos( +  ) = r. cos  . cos  − r. sin  . sin 
y = r. sin( +  ) = r. cos  . sin  + r. sin  . cos 
Substituting for r :
x = r. cos 
y = r. sin 

Gives us :
x = x. cos  − y. sin 
y = x. sin  + y. cos 
2D Rotation about the origin.
x = x. cos  − y. sin 
y  = x. sin  + y. cos 

Rewriting in matrix form gives us :


 x  cos  − sin    x 
 y =  sin  cos  . y 
    

cos  − sin  
Define the matrix R =   , P = R  P
 sin  cos  
Scaling
Transformations.
• Translation.
• P=T + P
• Scale
• P=S  P
• Rotation
• P=R  P
• We would like all transformations to be multiplications so we can
concatenate them  express points in homogenous coordinates.
General Two-Dimensional Pivot Point Rotation
3.5 Transformation in Homogeneous coordinates
• Many graphics applications involve sequences of geometric
transformations.
• An animation might require an object to be translated and rotated at
each increment of the motion.
• In design and picture construction applications, we perform
translation, rotation, and scaling to fit the picture components into
their proper positions.
Homogeneous coordinates
• Each of the three basic two-dimensional transformations (translation, rotation,
and scaling) can be expressed in the general matrix form
P’ = M1 · P + M2

• With coordinate positions P and P’ represented as column vectors.


• Matrix M1 is a 2 × 2 array containing multiplicative factors, and M2 is a two-element
column matrix containing translational terms.
• A more efficient approach, however, is to combine the transformations so that
the final coordinate positions are obtained directly from the initial coordinates,
without calculating intermediate coordinate values.
• We can do this by reformulating the above equation to eliminate the matrix
addition operation.
Homogeneous coordinates
• Multiplicative and translational terms for a two-dimensional geometric
transformation can be combined into a single matrix if we expand the
representations to 3 × 3 matrices.
• A standard technique for accomplishing this is to expand each two-
dimensional coordinate-position representation (x, y) to a three-element
representation (Xh, Yh, h), called homogeneous coordinates, where the
homogeneous parameter h is a nonzero value such that
Homogeneous coordinates
• Add an extra coordinate, h, to a point.
• P(x,y,h).
• Two sets of homogeneous coordinates represent the same
point if they are a multiple of each other.
• (2,3,1) and (4,6,2) represent the same point.
• At least one component must be non-zero  (0,0,0) is not
defined.
• If h 0 , divide by it to get Cartesian coordinates of point
(x/h, y/h,1).
• If h=0, point is said to be at infinity.
3D Transformations.
• Use homogeneous coordinates, just as in 2D case.
• Transformations are now 4x4 matrices, represented as a four-element
column vector.
• We will use a right-handed (world) coordinate system - ( z out of page ).
y

Video

Video Note:
Convenient to think of display as
Being left-handed !!
x ( z into the screen )

z (out of page)
3D Translation
• A position P=(x,y,z) in three-dimensional space is translated to a location P' =(x',y',z') by
adding translation distances tx, ty and tz to the Cartesian coordinates of P:
x'=x+tx, y'=y+ty , z'=z+tz ,
The formula illustrates three-dimensional translation.
• We can express the 3D translation operations in matrix form.

• But now the coordinate positions, P and P' are represented in homogeneous
coordinates with four- element column matrices , and the translation operator T is a
4X4 matrix.
Inverse Transformations
TRANSLATION
• For translation, we obtain the inverse matrix by negating the translation
distances.
• Thus, if we have two-dimensional translation distances tx and ty, the inverse
translation matrix is,

• This produces a translation in the opposite direction, and the product of a


translation matrix and its inverse produces the identity matrix.
Scaling
• Change the coordinates of the object by scaling factors.

Scaling an object with this transformation will also move its position relative to the origin
- so move it to the origin, scale it, then move it back...
Inverse Transformations
SCALING
• We form the inverse matrix for any scaling transformation by replacing the
scaling parameters with their reciprocals.
• For two-dimensional scaling with parameters sx and sy applied relative to
the coordinate origin, the inverse transformation matrix is

• The inverse matrix generates an opposite scaling transformation, so the


multiplication of any scaling matrix with its inverse produces the identity
matrix
Three-Dimensional Rotation
• We can rotate an object about any axis in space, but the easiest rotation axes
to handle are those that are parallel to the Cartesian-coordinate axes.
• Also, we can use combinations of coordinate-axis rotations to specify a
rotation about any other line in space.
• Lets us first consider the operations involved in coordinate-axis rotations, then
we discuss the calculations needed for other rotation axes.
• By convention, positive rotation angles produce counter-clockwise rotations
about a coordinate axis. cos  − sin  0 0
 sin  cos  0 0
• Need to specify which axis the rotation is about.
R z ( ) =  
• z-axis rotation is the same as the 2D case.  0 0 1 0
 
 0 0 0 1
Rotation
• Rotation around the coordinate axes
Rotation Contd..,
• The two- dimensional z-axis rotation equations are easily extended
to three dimensions, as follows:
Eqn1:

Parameter Ө specifies the rotation angle about the z axis, and


z-coordinate values are unchanged by this transformation.:
Rotation Contd..,
• In homogeneous-coordinate form, the three-dimensional z-axis rotation
equations are,

• Which we can write more compactly as,


Rotation Contd..,
• Transformation equations for rotations about the other two coordinate
axes can be obtained with cyclic permutation of the coordinate
parameters x,y, and z in eqn 1;
x->y->z->x
• Thus, to obtain the x-axis and y-axis rotation transformations, we cyclically
replace x with y, y with z, and z with x, as illustrated in the figure.
• The equation for three-dimensional x-axis rotation:
Rotation Contd..,
• In homogeneous-coordinate form, the three-dimensional x-axis rotation
equations are,

Which we can write more compactly as,


Rotation Contd..,
• The equation for three-dimensional y-axis rotation:

• In homogeneous-coordinate form, the three-dimensional y-axis rotation


equations are,

• Which we can write more compactly as,


Rotation around coordinate axes
Inverse Transformations
ROTATION
• An inverse rotation is accomplished by replacing the rotation angle by its
negative.

• We can use the trigonometric identities

• Negative values for rotation angles generate rotations in a clockwise


direction, so the identity matrix is produced when any rotation matrix is
multiplied by its inverse.
• We can calculate the inverse of any rotation matrix R by evaluating its
transpose .
An inverse rotation matrix is
Shear
• A transformation that distorts the shape of an object such that the
transformed shape appears as if the object were composed of internal
layers that had been caused to slide over each other is called a shear.
• Two common shearing transformations are those that shift coordinate x
values and those that shift y values.
• An x-direction shear relative to the x axis is produced with the
transformation matrix

which transforms
coordinate positions as
Shear Contd…
• An y-direction shear relative to the y axis is produced with the
transformation matrix
3.6 Concatenation Of Transformation
• Multiplication of matrices is associative.
• For any three matrices, M1, M2, and M3, the matrix product M3 · M2 · M1
can be performed by first multiplying M3 and M2 or by first multiplying M2
and M1:

• The composite matrix can be constructed either by multiplying from left to


right (pre-multiplying) or by multiplying from right to left (post-multiplying).
• Transformation products, on the other hand, may not be commutative. The
matrix product M2 · M1 is not equal to M1 · M2, in general.
• Suppose that we carry out three successive transformations
on a point p, creating a new point q. Because the matrix
product is associative, we can write the sequence as
q= CBAp

• First, we calculate
M = CBA.
• Then, we use this matrix on each point
q = Mp.
3.6.1 Rotation about a Fixed Point
Rotation around a pivot point
• Translate the object so that the pivot point moves to the origin.
Rotate about origin
• Translate the object so that the pivot point is back to its original
position
Rotation around an axis parallel to x-axis
Rotation around an axis parallel to x-axis
• A rotation matrix for any axis that does not coincide with a coordinate
axis can be set up as a composite transformation involving combinations
of translations and the coordinate-axis rotations.
• We attain the desired rotation with the following transformation
sequence:
• Translate the object so that the rotation axis coincides with the parallel
coordinate axis.
• Perform the specified rotation about that axis.
• Translate the object so that the rotation axis is moved back to its original position
• A coordinate position P is transformed with the sequence as ,
Rotation about an arbitrary axis
• 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.
• The below figure shows the five transformation steps for obtaining a composite matrix
for rotation about an arbitrary axis, with the rotation axis projected onto the z-axis
Rotation about an arbitrary axis
• Given the specifications for the rotation axis and the rotation angle, we
can accomplish the required rotation in 5 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.
• We can transform the rotation axis onto any one of the three coordinate
axes. The z axis is often a convenient choice.
Rotation about an arbitrary axis
• A rotation axis can be defined with two coordinate positions or with one
coordinate point and direction cosines between the rotation axis and
two of the coordinate axes.
• We assume that the rotation axis is defined by two point, as illustrated
in the figure -initial position, and that the direction of rotation is to be
counter-clockwise when looking along the axis from P2 to P1.
Rotation about an arbitrary axis
• The components of the rotation –axis vector are then computed as:

• Where the components a, b, and c are the direction cosines for the
rotation axis:
Rotation about an arbitrary 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.
• The translation matrix is:

• Next, we formulate the transformations that will put the rotation axis(i.e., u
vector) onto the z-axis.
Rotation about an arbitrary axis
FIRST STEP OF ROTATION:
Rotation about ‘x’ by ‘α’. Now we have to determine ‘α’
Project the unit vector u‫׳‬, along OP, into the YZ plane.
The y and z components, b and c are the direction cosines of the unit vector along the arbitrary
axis.
Rotation about an arbitrary axis. Contd..,
• It can be seen from the diagram, by using Right Angle triangle formula we get,

We also need angle ‘α’ to be calculated,

Hence we establish the transformation matrix for rotation around the x-axis by determining
the values for the sine and cosine of the rotation angle necessary to get OP (the vector u)
onto the ‘xz’ plane.
Rotation about an arbitrary axis. Contd..
• Now that we have determined the values for cosα and sineα in terms of the
components of vector ‘u’ (OP), we can set up the matrix elements for rotation of this
vector about the x-axis and into the xz plane.
Rotation about an arbitrary axis. Contd..,
After first step rotation:
Next step in the formulation of the transformation sequence is to determine the matrix that will swing
the unit vector in the xz plane counter-clockwise around the y-axis onto the positive z-axis.

The above figure shows the orientation of the unit vector in the xz plane, resulting from the rotation about the x-
axis.
This vector, labelled u'', has the value a for its x component, because rotation about x-axis leaves the x
component unchanged. Its z component is d (the magnitude of u'),because vector u' has been rotated on to the z-
axis. Also the y component of u'' is 0.
Rotation about an arbitrary axis. Contd..,
• Rotation by ‘β’ about y-axis.
• Now we have to determine ‘β’. Steps is similar to that done for ‘α’.
• Now we need to calculate cosine and sine for the angle ‘β’.
Rotation about an arbitrary axis. Contd..,
• Therefore, the transformation matrix for rotation of u’’ about the y axis is

• With transformation matrices of , and , we have aligned the rotation axis with
the positive z axis.
Rotation about an arbitrary axis. Contd..,
• To complete the required rotation about the given axis, we need to transform the
rotation axis back to its original position.
• This is done by applying the inverse of transformations.
• The transformation matrix for rotation about an arbitrary axis can then be expressed
as the composition of these seven individual transformations:
Basic OpenGL Geometric Transformations
• In the core library of OpenGL, a separate function is available for each of the basic
geometric transformations.
• OpenGL is designed as a 3D graphics API, where all transformations are specified in
three dimensions.
• Internally all coordinate positions are represented as four-element column vectors
• All transformations are represented using 4X4 matrices.
• Performing 2D transformations within OpenGL is generally just a matter of using a
value for the transformations in the third(z) dimension that cause no change in that
dimension.
Basic OpenGL Geometric Transformations:
glTranslate*()
A 4 × 4 translation matrix is constructed with the following routine:
*-> f(float) or d(double)
Translate over [tx, ty, tz]:
glTranslate*(tx, ty, tz);
1.tx,ty and tz -> can be assigned with any real number values
2.For two-dimensional applications,we set tz=0.0;
3.Two-dimensional position is represented as a four-element
column matrix with the z-component equal to 0.0.
Example: glTranslatef(25.0,-10.0,0.0)
Basic OpenGL Geometric Transformations:
glRotate*()
• Similarly, a 4 × 4 rotation matrix is generated with
glRotate*(theta, vx, vy, vz);
v=(vx,vy,vz)-> Defines the orientation for a rotation axis
Theta-> Rotation angle in degrees,which the routine converts to
radians for the trignometric calculations.
V is the unit vector

• Rotation in 2D system is rotation about the z-axis, specified as a unit


vector with x and y components as zero, and a z component as 1.0
For example., glRotatef(90.0, 0.0, 0.0, 1.0);
Basic OpenGL Geometric Transformations:
glScale*()

Scale axes with factors sx, sy, sz:


glScale*(sx, sy, sz);
• sx,sy,sz-> can assign any real-number values
• Scaling in 2D system involves changes in the x and
y dimensions, and a z scaling factor of 1.0(which
causes no change in the z-coordinate positions)
Example: glScalef(2.0, 3.0, 1.0);

A zero value for any scaling parameter can cause a


processing error, because an inverse matrix cannot be
calculated

You might also like