0% found this document useful (0 votes)
30 views14 pages

CH 04 6up

Uploaded by

Anusha Anusha
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)
30 views14 pages

CH 04 6up

Uploaded by

Anusha Anusha
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/ 14

- -

■ Introduction:
- We are now ready to concentrate on three-
dimensional graphics
- Much of this chapter is concerned with
Geometric Objects and matters such as
Transformations • how to represent basic geometric types
• how to convert between various
representations
Chapter 4 • and what statements we can make about
geometric objects, independent of a particular
representation.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 2

■ 1.1 The Geometric View


1. Scalars, Points, and Vectors
- Our fundamental geometric object is a
- We need three basic types to define most point.
geometric objects • In a three-dimensional geometric system, a
• scalars point is a location in space
• points • The only attribute a point possesses is its
location in space.
• and vectors
- Our scalars are always real numbers.
• Scalars lack geometric properties,
- We can define each in many ways, so we
• but we need scalars as units of measurement.
will look at different ways and compare and
contrast them.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 3 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 4

- In computer graphics, we often connect • Directed line segments can have their lengths
points with directed line segments and directions changed by real numbers or by
combining vectors

• These line segments are our vectors.


• A vector does not have a fixed position
– hence these segments are identical because their
orientation and magnitude are identical.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 5 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 6

- -1
- -

■ 1.2 The Mathematical View: Vector and - Perhaps the most important mathematical
Affine Spaces space is the vector space
• We can regard scalars, points and vectors as • A vector space contains two distinct entities:
members of mathematical sets; vectors and scalars.
• Then look at a variety of abstract spaces for • There are rules for combining scalars through
representing and manipulating these sets of two operations: addition and multiplication, to
objets. form a scalar field
• The formal definitions of interest to us -- vector
spaces, affine spaces, and Euclidean spaces -- • Examples of scalar are:
are given in Appendix B – real numbers, complex numbers, and rational
functions
• You can combine scalars and vectors to forma
new vector through
– scalar-vector multiplication and vector-vector addition

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 7 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 8

■ 1.3 The Computer Science View


• An affine space is an extension of the vector • We prefer to see these objects as ADTs
space that includes an additional type of object:
– The point
• Def: ADT
• A Euclidean space is an extension that adds a
measure of size or distance • So, first we define our objects
• Then we look to certain abstract mathematical
• In these spaces, objects can be defined spaces to help us with the operations among
independently of any particular representation them
– But representation provides a tie between abstract
objects and their implementation
– And conversion between representations leads us to
geometric transformations

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 9 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 10

■ 1.4 Geometric ADTs • The direction of αv is the same as the direction


of v if α is positive.
• Our next step is to show how we can use our
types to perform geometrical operations and to • We have two equivalent operations that relate
form new objects. points and vectors:
– First there is the subtraction of two points P and Q.
• Notation This is an operation that yields a vector
– Scalars will be denoted α, β, γ • v=P-Q
– Points will be denoted P, Q, R, ... • or P = v + Q
– Vectors will be denoted u, v, w, ...

• The magnitude of a vector v is the real number


that is denoted by |v|

• The operation of vector-scalar multiplication


has the property that |αv| = |α||v|
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 11 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 12

- -2
- -

– Second there is the head-to-tail rule that gives us a


convenient way of visualizing vector-vector addition.
■ 1.5 Lines
- The sum of a point and a vector leads to
the notion of a line in an affine space
• Consider all points of the form
– P(α) = P0+αd
• P0 is an arbitrary point
• d is an arbitrary vector
• α is a scalar

• This form is sometimes called the parametric


form, because we generate pints by varying the
parameter α.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 13 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 14

■ 1.7 Convexity ■ 1.8 Dot and Cross Products


- Def: Convex object - Dot product
- Def: Convex Hull • the dot product of u and v is written u•v
• If u•v=0, then u and v are orthogonal
• In euclidean space, |u|2 = u•u
• The angle between two vectors is given by
– cos θ = (u•v)/(|u| |v|)

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 15 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 16

- Cross product ■ 1.9 Planes


• We can use two non parallel vectors u and v to - Def: Plane
determine a third vector n that is orthogonal to
them n=u x v
- Def: normal to the plane

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 17 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 18

- -3
- -

- In 2D we had objects
2. Three-Dimensional Primitives with interiors, such as
polygons,
- In a three-dimensional world, we can have - Now we have surfaces
a far greater variety of geometric objects in space
than we could in two-dimensions.
• In 2D we had curves,
• Now we can have curves in space
- In addition, now we can
have objects that have
volume

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 19 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 20

• We face two issues when moving from 2D to • We can understand why we set these
3D. conditions if we consider what most modern
– First, the mathematical definitions of these objects graphics systems do best:
becomes complex – They render triangles
– Second, we are interested in only those objects that
lead to efficient implementations in graphic systems

• Def: tesselate
• Three features characterize 3D objects that fit
well with existing graphics hardware and
software:
– 1. The objects are described by their surfaces and
can be thought of as hollow.
– 2. The objects can be specified through a s set of
vertices in 3D
– 3. The objects either are composed of or can be
approximated by flat convex polygons.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 21 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 22

• We can write the


representation of w α1 
3. Coordinate Systems and Frames with respect to this a = α 2 
basis as the column α 3 
• In a three-dimensional vector matrix
space, we can represent any
vector w uniquely in terms of any
three linearly independent
vectors v1, v2, and v3, as
– w = α1v1+α2v2+α3v3
• The scalars α1, α2, and α3 are • We usually think of
the components of w with basis vectors
respect to the basis functions defining a
coordinate system

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 23 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 24

- -4
- -

• However, vectors have no • This representation that requires both the


position, so this would also reference point and the basis vectors is called a
be appropriate frame.
– Loosely, this extension fixes the origin of the vector
coordinate system at some point P0.

– So, every vector is defined in terms of the basis


– But a little more confusing. vectors
– and every point is defined in terms of the origin and
• Once we fix a reference the basis vectors.
point (the origin), we will feel – Thus the representation of either just requires three
more comfortable, scalars, so we can use matrix representations
– because the usual convention
for drawing the coordinate
axes as emerging from the
origin

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 25 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 26

■ 3.1 Changes in Coordinate Systems • The 3x3 matrix is


• Frequently, we are required to find how the γ 11 γ 12 γ 13 
representation of a vector changes when we M = γ 21 γ 22 γ 23 
change the basis vectors.
– Suppose {v1, v2, v3} and {u1, u2, u3} are two bases
γ 31 γ 32 γ 33 
– Each basis vector in the second can be represented – is defined by the scalars and
in terms of the first basis (and vice versa)
– Hence:  u1   v1 
• u1 = γ11v1+γ12v2+γ13v3 u  = M  v 
• u2 = γ21v1+γ22v2+γ23v3  2  2
• u3 = γ31v1+γ32v2+γ33v3 u3   v3 

– and M tells us how to go one way, and the inverse of


M tells us how to go the other way.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 27 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 28

• These change in basis leave the origin ■ 3.2 Example of Change of


unchanged
Representation

• However, a simple translation of the origin, or


change of frame, cannot be represented in this
way

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 29 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 30

- -5
- -

■ 3.3 Homogeneous Coordinates ■ 3.4 Example of Change in Frames

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 31 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 32

■ 3.5 Frames and ADTs ■ 3.6 Frames in OpenGL


• Thus far, our discussion has been • In OpenGL we use two frames:
mathematical. – The camera frame
• Now we begin to address the question of what – The world frame.
this has to do with programming
• We can regard the camera frame as fixed
– (or the world frame if we wish)
– The model-view matrix positions the world frame
relative to the camera frame.

• Thus, the model-view matrix converts the


homogeneous-coordinate representations of
points and vectors to their representations in
the camera frame.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 33 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 34

• As we saw in Chapter 2, the camera is at the


• Because the model-view matrix is part of the origin of its frame
state of the system there is always a camera – The three basis vectors correspond to:
frame and a present-world frame. • The up direction of the camera (y)
• The direction the camera is pointing (-z)
• and a third orthogonal direction
• OpenGL provides matrix stacks, so we can
store model-view matrices
– We obtain the other frames (in which to place
– (or equivalently, frames)
objects) by performing homogeneous coordinate
transformations
• We will learn how to do this in Section 4.5
• In Section 5.2 we use them to position the
camera relative to our objects.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 35 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 36

- -6
- -

• Let’s look at a simple example: – Thus by making d a suitably large positive number,
– In the default settings, the camera and the world we move the objets in front of the camera
frame coincide with the camera pointing in the
negative z direction – Figure 4.21
– In many applications it is natural to define objects
near the origin.

• If we regard the camera frame as fixed, then – Note that, as far as the user - who is working in world
the model-view matrix: coordinates - is concerned, they are positioning
1 0 0 0  objects as before
0 1 0 0  – The model-view matrix takes care of the relative
A= positioning of the frames
0 0 1 −d 
 
0 0 0 1 
– moves a point (x,y,z) in the world frame to the point
(x,y,z-d) in the camera frame.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 37 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 38

■ 4.1 Modeling of a Cube


4. Modeling a Colored Cube
• typedef Glfloat point3[3];
• point3 vertices[8] = {{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0},
- We now have the tools we need to build a {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}};
3D graphical application.
• glBegin(GL_POLYGON);
- Consider the problem of drawing a rotating • glVertex3fv(vertices[0]);
cube on the screen • glVertex3fv(vertices[3]);
• glVertex3fv(vertices[2]);
• glVertex3fv(vertices[1]);
• glEnd();

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 39 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 40

■ 4.2 Inward- and Outward-Pointing ■ 4.3 Data Structures for Object Representation
Faces • We could describe our cube
– glBegin(GL_POLYGON)
• We have to be careful about the order in which
• six times, each followed by four vertices
we specify our vertices when we are defining a
– glBegin(GL_QUADS)
three-dimensional polygon
• followed by 24 vertices
• We call a face outward facing if the vertices
• But these repeat data....
are traversed in a counterclockwise order when
the face is viewed from the outside. • Let’s separate the topology from the geometry.
– This is also known as the right-hand rule

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 41 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 42

- -7
- -

■ 4.4 The Color Cube ■ 4.5 Bilinear Interpolation


• typedef Glfloat point3[3]; • Although we have specified colors for the
• point3 vertices[8] = {{-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},
vertices of the cube, the graphics system must
{-1.0,1.0,1.0}}; decide how to use this information to assign
• Glfloat colors[8][3]={0.0,0.0,0.0}, {1.0,0.0,0.0}, {1.0, 1.0, 0.0}, colors to points inside the polygon.
{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}};
• Probably the most common method is bilinear
interpolation.
• void quad(int a, int b, int c, int d)
• {
• glBegin(GL_POLYGON);
• glColor3fv(colors[a]); glVertex3fv(vertices[a]);
• glColor3fv(colors[a]); glVertex3fv(vertices[b]);
• glColor3fv(colors[a]); glVertex3fv(vertices[c]);
• glColor3fv(colors[a]); glVertex3fv(vertices[d]);
• glEnd();
• }
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 43 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 44

• Another method is Scan-line interpolation ■ 4.6 Vertex Arrays


– pushes the decision off until rasterization.
• Vertex arrays provide a method for
– OpenGL uses this method for this as well as other
values. encapsulating the information in our data
– First you project the polygon structure such that we could draw polyhedral
objects with only a few function calls.
– Rather than the 60 OpenGL calls:
• six faces, each of which needs a glBegin, a
glEnd, four calls to glColor, and four calls to
glVertex.

– Then convert the colors with each scan line


• There are 3 steps in using vertex arrays
– First, enable the functionality of vertex arrays.
– Second, we tell OpenGL where and in what format
the arrays are.
– Third, we render the object

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 45 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 46

• glEnableClientState(GL_COLOR_ARRAY);
• glEnableClientState(GL_VERTEX_ARRAY);
• glVertexPointer(3, GL_FLOAT, 0, vertices); 5. Affine Transformations
• glColorPointer(3, GL_FLOAT, 0, colors);

- A transformation is a function that takes a


• Glubyte cubeIndices[24]={0,3,2,1,2,3,7,6,0,4,7,3,1,2,6,5,
4,5,6,7,0,1,5,4}; point (or vector) and maps it into another .

• We now have a few options regarding how to draw the


arrays
– for(i=0;i<6;i++)
– glDrawElements(GL_POLYGON, 4,
GL_UNSIGNED_BYTE, &cubeIndeces[4*i]);

– glDrawElements(GL_QUADS, 24,
GL_UNSIGNED_BYTE, cubeIndeces);

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 47 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 48

- -8
- -

• We can represent this as: • Therefore,


– Q=T(P) and v=R(u) – we need only to transform the homogeneous
coordinate representation of the endpoints of a line
segment to determine completely a transformed line.
• If we write both the points and vectors in
– Thus, we can implement our graphics systems as a
homogeneous coordinates, then we can pipeline that passes endpoints through affine
represent both vectors and points in 4-D transformation units, and finally generate the line at
column matrices and define a single function rasterization stage.
– q=f(p) and v=f(u)
• Fortunately, most of the transformations that
• This is too general, but if we restrict it to linear we need in computer graphics are affine.
functions, then we can always write it as – These transformations include rotation, translation,
– v = Au and scaling.
– where v and u are column vectors (or points) and A – With slight modifications, we can also use these
is a square matrix. results to describe the standard and parallel
projections.

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 49 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 50

6. Rotation, Translation, and ■ 6.1 Translation


- Translation is an operation that displaces
Scaling points by a fixed distance in a given
- In this section, direction
• First, we show how we can describe the most
important affine transformations independently
of any representation.
• Then we find matrices that describe these
transformations
- In section 4.8 we shall see how these
transformations are implemented in
OpenGL - To specify a translation, we need only to
specify a displacement vector d
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 51 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 52

■ 6.2 Rotation • We expand this to 3D in Section 4.7


• Rotation is more difficult to specify than • Note that there are three features of this
translation, because more parameters are transformation that extend to other rotations.
involved – 1) There is one point - the origin - that is unchanged
by the rotation. This is called a fixed point.
• Let’s start with 2D rotation about the origin

– 2) We can define positive rotations about other axes

– These equations can be written in matrix form as:

 x′  cosθ − sin θ   x 
 y ′ =  sin θ cosθ   y 
   – 3) 2D rotation in the plane is equivalent to 3D
rotation about the x axis.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 53 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 54

- -9
- -

• We can use these observations to define a • Rotations and translation are known as rigid-
general 3D rotation that is independent of the body transformations.
frame. – No combination can alter the shape of an object,
– To do this we must specify: – They can alter only the object’s location and
• a fixed point: Pf orientation
• a rotation angle: θ • The transformation given in this figure are
• a line or vector about which to rotate: affine, but they are not rigid-body
transformations

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 55 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 56

■ 6.3 Scaling • Hence, to specify a scaling,


– we can specify a fixed point,
• Scaling is an affine non-rigid body
– a direction in which we wish to scale,
transformation.
– and a scale factor α.
• For α > 1, the object gets longer
• for 0 <= α < 1 the object get smaller
• Negative values of α give us reflection

• Scaling transformations have a fixed point

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 57 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 58

7. Transformations in ■ 7.1 Translation


• Translation displaces points to a new position
Homogeneous Coordinates defined by a displacement vector.
– If we move p to p’ by displacing by a distance d then
- In most graphics APIs we work with a • p’ = p + d
representation in homogeneous • or p’ = Tp
coordinates. • where 1 0 0 α x 
0 1 0 α 
T =
- And each affine transformation is y 
1
0 0 1 α 
represented by a 4x4 matrix of the form:  z

α11 α12 α13 α14   0 0 0 1 
α α 22 α 23 α 24 
M =  21 • T is called the translation matrix
α 31 α 32 α 33 α 34 
 
 0 0 0 1 
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 59 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 60

- -10
- -

■ 7.2 Scaling ■ 7.3 Rotation


• A scaling matrix with a fixed point at the origin • We first look at rotation with a fixed point at the
allows for independent scaling along the origin.
coordinate axes. – We can find the matrices for rotation about the
– X’=βxx individual axes directly from the results of the 2D
– y’=βyy rotation developed earlier.
– z’=βzz – Thus,
• x’=x cos θ - y sin θ
• These tree can be combined in homogeneous
• y’=x sin θ + y cos θ
for as
• z’ = z
– p’=Sp βx 0 0 0 
0 βy 0 0 
• of p’ = Rzp cosθ − sin θ 0 0 
S = S ( β x, β y , β z ) =  1  sin θ cosθ 0 0
0 0 βz 0  Rz = Rz (θ ) =  
   0 0 1 0
 0 0 0 1 
 
 0 0 0 1 

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 61 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 62

• We can derive the matrices for rotation about ■ 7.4 Shear


the x and y axes through an identical argument.
• Although we can construct any affine
– And we can come up with:
transformation from a sequence of rotations,
1 0 0 0 translations, and scaling, there is one more
0 cosθ − sin θ 0 affine transformation that is of such importance
Rx = Rx (θ ) =   that we regard it as a basic type, rather than
0 sin θ cosθ 0
  deriving it from others.
0 0 0 1 

 cosθ 0 sin θ 0
 0 1 0 0
R y = R y (θ ) =  
 − sin θ 0 cosθ 0
 
 0 0 0 1 

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 63 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 64

• Using simple trigonometry, we can see that


each shear is characterized by a single θ 8. Concatenation of
Transformations
- In this section, we create examples of
affine transformations by multiplying
together, or concatenating, sequences of
• The equation for this shear is: basic transformations that we just
– x’= x + y cot θ, y’= y, z’= z introduced.
1 cot θ 0 0
• Leading to the shear matrix : 0 1 0 0 • This approach fits well with our pipeline
H x (θ ) =   architectures for implementing graphics
0 0 1 0 systems.
 
 0 0 0 1 
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 65 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 66

- -11
- -

■ 8.1 Rotation About a Fixed Point ■ 8.2 General Rotation


• In order to do this: • An arbitrary rotation
about the origin can be
composed of three
successive rotations
about the tree axes.

• You do this:

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 67 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 68

■ 8.3 The Instance ■ 8.4 Rotation About an Arbitrary Axis


Transformation • In order to do this:
• Objects are usually defined in
their own frames, with the origin
at the center of mass, and the
sides aligned with the axes. • We move the fixed point to the origin

• The instance transformation is


applied as follows: • Do the rotations
– First we scale
– Then we orient it with a rotation
matrix
– Finally we translate it to the desired
orientation.
• Translate back
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 69 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 70

9. OpenGL Transformation ■ 9.1 The Current Transformation Matrix


• This is the matrix that is applied to any vertex
Matrices that is defined subsequent to its setting.
• If we change the CTM we change the state of
the system.
- In OpenGL there are three matrices that • The CTM is part of the pipeline
are part of the state.
• We shall use only the model-view matrix in this
chapter.
• All three can be manipulated by a common set – Thus, if p is a vertex, the pipeline produces Cp
of functions,
• And we use glMatrixMode to select the matrix • The functions that alter the CTM are:
to which the operations apply. – Initialization (C ← I)
– Post-Multiplication (C ← CT)
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 71 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 72

- -12
- -

■ 9.2 Rotation, Translation, and Scaling • We can load a matrix with


– glLoadMatrixf(pointer_to_matrix);
• In OpenGL,
– the matrix that is applied to all primitives is the
• or set it to the identity with
product of the model-view matrix (GL_MODELVIEW) – glLoadIdentity( );
and the projection matrix (GL_PROJECTION)
• Rotation, translation, and scaling are provided
– We can think of the CTM as the product of these two. through three functions:
– glRotate(angle, vx, vy, vz);
• angle is in degrees
• vx, vy, and vz are the components of a vector
about which we wish to rotate.
– glTranslate(dx, dy, dz);
– glScale(sx, sy, sz);

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 73 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 74

■ 9.3 Rotation About a Fixed Point in ■ 9.4 Order of Transformations


OpenGL • You might be bothered by the apparent
• In Section 4.8 we showed that we can perform reversal of the function calls.
a rotation about a fixed point other than the
origin. • The rule in OpenGL is this:
– (translate, rotate, and translate back) – The transformation specified most recently is the one
– Here is how you do it in OpenGL applied first.
• C ←I
• glMatrixMode(GL_MODELVIEW); • C ← CT
• glLoadIdentity( ); • C ← CR
• glTranslatef(4.0, 5.0, 6.0); • C ← CT
• glRotatef(45.0, 1.0, 2.0, 3.0); – each vertex that is specified after the model-view
• glTranslatef(-4.0, -5.0, -6.0); matrix has been set will be multiplied by C thus
forming the new vertex
• q = Cp
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 75 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 76

■ 9.5 Spinning of the Cube


- void mouse(int btn, int state, int x, int y)
- {
- void display(void)
- if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- {
- axis = 0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
- glLoadIdentity( );
- axis = 1;
- glRotatef(theta[0], 1.0, 0.0, 0.0);
- if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
- glRotatef(theta[1], 0.0, 1.0, 0.0);
- axis = 2;
- glRotatef(theta[2], 0.0, 0.0, 1.0);
- }
- colorcube( );
- glutSwapBuffers( );
- }

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 77 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 78

- -13
- -

■ 9.6 Loading, Pushing, and Popping


- void spinCube( )
- { Matrices
- theta[axis] += 2.0; • For most purposes, we can use rotation,
- if (theta[axis] > 360.0) theta[axis] -= 360.0’ translation , and scaling to form a desired
- glutPostRedisplay( ); transformation matrix.
- } • In some circumstances, however, such as
forming a shear matrix, it is easier to set up the
- void mkey(char key, int mousex, int mousey) matrix directly.
- { – glLoadMatrixf(myarray)
- if(key==‘q’ || key==‘Q’)
• We can also multiply on the right of the current
- exit( );
matrix by using
- }
– glMultMatrixf(myarray);

CS 480/680 Chapter 4 -- Geometric Objects and Transformations 79 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 80

• Sometimes we want to perform a


transformation and then return to the same
state as before its execution. 11. Summary
• We can push the current transformation matrix
on a stack and recover it later. - In this chapter, we have presented two different-but
ultimately complementary-points of view regarding the
• Thus we often see the sequence mathematics of Computer Graphics.
– glPushMatrix( ); • One is the mathematical abstraction of the objects with
– glTransletef( . . . ); which we work in computer graphics is necessary if we
– glRotatef( . . . ); are to understand the operations that we carry out in our
– glScalef( . . . ); programs
– // draw object here • The other is that transformations (and homogeneous
coordinates) are the basis for implementations of
– glPopMatrix( );
graphics systems
- Finally we provided the set of affine transformations
supported by OpenGL, and discussed ways that we could
concatenate them to provide all affine transformations.
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 81 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 82

12. Suggested Readings Exercises -- Due next Monday


• Homogeneous coordinates arose in Geometry(51) and - 4.5
were alter discovered by the graphics community(81)
– Their use in hardware started with the SGI Geometry - 4.8
Engine (82)
– Modern hardware architectures use Application Specific
- 4.13
Integrated Circuits (ASIC’s) that include homogeneous
coordinate transformations
- 4.17

• Quaternions were introduced to computer graphics by


Shoemaker(85) for use in animation
• Software tools such as Mathematica(91) and Matlab(95)
are excellent aids for learning to manipulate
transformation matrices
CS 480/680 Chapter 4 -- Geometric Objects and Transformations 83 CS 480/680 Chapter 4 -- Geometric Objects and Transformations 84

- -14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy