Download presentation
Presentation is loading. Please wait.
Published byEmery Adams Modified over 9 years ago
1
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert
2
Comp 175C - Computer Graphics Dan Hebert Outline 1 v 2D transformation –Translate –Rotate –Scale
3
Comp 175C - Computer Graphics Dan Hebert Transformations A Transformation is a function that takes variable(s) in a domain and maps that into another domain y = f (x) f: x => y Ex: y = sin (x f x y
4
Comp 175C - Computer Graphics Dan Hebert Transformations in Graphics v Transformations make possible the projection of 3D objects onto 2D screen v The graphics transformation process is analogous to taking a photograph with a camera v Every transformation can be thought of as changing the representation of a vertex from one coordinate system to another
5
Comp 175C - Computer Graphics Dan Hebert 2D Transformations A special case of 3D (z = 0) Represented points (vertices) as: (x,y), or Matrix form: or Homogeneous coordinates (x, y) = xyxy xy1xy1
6
Comp 175C - Computer Graphics Dan Hebert Translation v Translation a operation that repositions points along a given straight-line path (the translation direction ) from one coordinate location to another.
7
Comp 175C - Computer Graphics Dan Hebert Translation (x, y) (x’, y’) (d x, d y ) x y dyy dxx y x ' '
8
Comp 175C - Computer Graphics Dan Hebert Translation p ' = Tp 1 0 d x 0 1 d y 0 0 1 T( d x, d y ) =Translation matrix 1 0 - d x 0 1 - d y 0 0 1 T -1 ( d x, d y ) =
9
Comp 175C - Computer Graphics Dan Hebert Applying to Objects (d x, d y ) x y
10
Comp 175C - Computer Graphics Dan Hebert Translation Remember -Translation direction -Translation distance -3 degrees of freedom (DoF) -Translation is rigid-body transformation (a transformation that does not change the shape of objects)
11
Comp 175C - Computer Graphics Dan Hebert Scaling v Scaling a operation that alters the size of an object about a fixed point
12
Comp 175C - Computer Graphics Dan Hebert Scaling (x, y) (x’, y’) x y
13
Comp 175C - Computer Graphics Dan Hebert Scaling Scaling matrix p ' = Sp s x 0 0 0 s y 0 0 0 1 S ( s x, s y ) = 1/s x 0 0 0 1/s y 0 0 0 1 S -1 ( s x, s y ) =
14
Comp 175C - Computer Graphics Dan Hebert Scaling v Scale factors – if s x, s y > 1, the objects are stretched – if 0 < s x, s y < 1, the objects are shrunk – if s x, s y < 0, the objects are flipped (reflection) v Uniform/differential scaling –if s x = s y, the scaling is uniform –if s x s y, the scaling is differential (non-uniform)
15
Comp 175C - Computer Graphics Dan Hebert Scaling Remember -Scaling factors -Fixed point -Scaling is an affine non-rigid-body transformation
16
Comp 175C - Computer Graphics Dan Hebert Rotation v Rotation a operation that repositions points along a given circular path (the rotation direction ) from one coordinate location to another. Rotation requires an and a pivot point
17
Comp 175C - Computer Graphics Dan Hebert Rotation x y (x, y) (x’, y’)
18
Comp 175C - Computer Graphics Dan Hebert Rotation p ' = Rp cos -sin 0 sin cos 0 0 0 1 R( ) = Rotation matrix cos sin 0 -sin cos 0 0 0 1 R -1 ( ) =
19
Comp 175C - Computer Graphics Dan Hebert Rotation Remember -Rotation direction -Rotation angle -Rotation center -Rotation is rigid-body transformation
20
Comp 175C - Computer Graphics Dan Hebert We Should Remember v Translation, Scaling, and Rotation all are affine transformation v Translation and Rotation are also rigid-body transformation v Scaling is non-rigid-body transformation
21
Comp 175C - Computer Graphics Dan Hebert Outline 2 v 3D transformation –Translate –Rotate –Scale v Composition of transformations v Coordinate transformations v Applications - object hierarchy
22
Comp 175C - Computer Graphics Dan Hebert Extend to 3D x y xy z
23
Comp 175C - Computer Graphics Dan Hebert Translation v Translation a operation that repositions points along a given straight-line path (the translation direction ) from one coordinate location to another.
24
Comp 175C - Computer Graphics Dan Hebert Translation (x, y) (x’, y’) (d x, d y ) x y (x’, y’, z’) (d x, d y, d z ) (x, y, z) x y z
25
Comp 175C - Computer Graphics Dan Hebert 3D Translation Matrix 1000 100 010 001 z y x d d d ,, zyx dddT Translation:
26
Comp 175C - Computer Graphics Dan Hebert Scaling v Scaling a operation that alters the size of an object about a fixed point
27
Comp 175C - Computer Graphics Dan Hebert Scaling (s x, s y, s z ) x y z (x’, y’, z’) (x, y, z) (x, y) (x’, y’) x y (s x, s y )
28
Comp 175C - Computer Graphics Dan Hebert 3D Scaling Matrix 1000 000 000 000 z y x s s s ,, zyx sssS Scaling:
29
Comp 175C - Computer Graphics Dan Hebert Rotation v Rotation a operation that repositions points along a given circular path (the rotation direction ) from one coordinate location to another.
30
Comp 175C - Computer Graphics Dan Hebert Rotation x y (x, y) (x’, y’) To specify a 2D rotation, we need an rotation angle and a pivot point. How about for 3D rotation?
31
Comp 175C - Computer Graphics Dan Hebert 3D Rotation v To specify a 3D rotation, we requires an rotation angle and a vector (rotation axis) y x z rotation axis (x’, y’, z’) (x, y, z)
32
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Z axis v 2D rotation is just a 3D rotation about the z axis x z y (x’, y’, z’) (x, y, z)
33
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Z axis 1000 0100 00cossin 00 cos ) ( RzRz Rotation matrix ) ( RzRz
34
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About X axis (x, y, z) (x’, y’, z’) x y z
35
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About X axis 1000 0cossin0 0 cos0 0001 ) ( RxRx Rotation matrix ) ( RxRx
36
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Y axis (x, y, z)(x’, y’, z’) x y z
37
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Y axis Rotation matrix ) ( RyRy ) ( Ry 1000 0cos0sin 0010 0 0cos
38
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Origin y x z (x’, y’, z’) (x, y, z)
39
Comp 175C - Computer Graphics Dan Hebert 3D Rotation About Origin v An arbitrary rotation about the origin can be composed of three successive rotations about three axes R ( R z ( z R y ( y R x ( x The order of the composed rotations is not unique Ex: R x ( x R y ( y R z ( z The three angles x, y, z are often called Euler Angles. or called Yaw ( y ), Pitch ( x ), and Roll ( z ).
40
Comp 175C - Computer Graphics Dan Hebert Summary 1000 100 010 001 z y x d d d ,, zyx dddT Translation: 1000 000 000 000 z y x s s s ,, zyx sssS Scaling: Three elementary 3D affine transformations
41
Comp 175C - Computer Graphics Dan Hebert Summary 1000 0cossin0 0 cos0 0001 ) ( RxRx ) ( Ry 1000 0cos0sin 0010 0 0cos 1000 0100 00 sin 00 cos ) ( RzRz Rotation ) ( RxRx ) ( RyRy ) ( RzRz
42
Comp 175C - Computer Graphics Dan Hebert Composition of Transformations v Composition: the process of applying several transformations in succession to form one overall transformation. v Any composition of affine transformations is still affine. v When homogeneous coordinates are used, affine transformations are composed by simple matrix multiplication. Ex: T = T 4 T 3 T 2 T 1 v Note: the matrices appear in reverse order to that in which the transformations are applied.
43
Comp 175C - Computer Graphics Dan Hebert Composition of Transformations Let’s examine an example: –2D Rotation about an arbitrary point x P(x, y) P’ (x’, y’) V = (V x, V y ) y
44
Comp 175C - Computer Graphics Dan Hebert Rotation About an Arbitrary Point Since we have known rotation about origin, we can use that and construct successive transformations to compose the rotation about an arbitrary pivot point. Three Steps: 1.Translate point P through vector V = (-V x, -V y ). 2.Rotate about the origin through angle 3.Translate P back through vector V = (V x, V y ).
45
Comp 175C - Computer Graphics Dan Hebert Rotation About an Arbitrary Point x P(x, y) P’ (x’, y’) V = (V x, V y ) y 1.Translate point P through vector -V. 2.Rotate about the origin through angle 3.Translate P back through vector V
46
Comp 175C - Computer Graphics Dan Hebert Coordinate Transformations v We can think about, alternatively, a transformation is as a change of coordinate systems. (x,y)(x,y) (x’,y’) (d x, d y ) (x, y) (d x, d y )
47
Comp 175C - Computer Graphics Dan Hebert Coordinate Transformations v Transforming points To apply a sequence of transformations T 1, T 2, T 3 (in that order) to a point, form matrix T = T 3 T 2 T 1 Then, P is transformed to TP v Transforming the coordinate system To apply a sequence of transformations T 1, T 2, T 3 (in that order) to the coordinate system, form matrix T = T 1 T 2 T 3 Then, a point P expressed in the transformed system has coordinates MP in the original system.
48
Comp 175C - Computer Graphics Dan Hebert Coordinate Transformations v Objects are usually defined in theirs own local coordinate system. v We wish to express these objects’ coordinates in a single, global coordinate. –Object Coordinates –World Coordinates –Screen Coordinates
49
Comp 175C - Computer Graphics Dan Hebert Object Coordinates Objects are usually defined in their own local coordinate system.
50
Comp 175C - Computer Graphics Dan Hebert World Coordinates Represent these objects’ coordinates in a single, global coordinate.
51
Comp 175C - Computer Graphics Dan Hebert Screen Coordinates Finally, we want to project these objects onto the screen.
52
Comp 175C - Computer Graphics Dan Hebert Coordinate Hierarchy Object #1 Object Coordinates Transformation Object #1 -> World Object #2 Object Coordinates Transformation Object #2 -> World Object #3 Object Coordinates Transformation Object #3 -> World World Coordinates Transformation World->Screen Screen Coordinates
53
Comp 175C - Computer Graphics Dan Hebert Demonstration
54
Comp 175C - Computer Graphics Dan Hebert Demonstration
55
Comp 175C - Computer Graphics Dan Hebert Outline 3 v OpenGL transformation pipeline v Modeling transformation –Translate –Rotate –Scale v Composition of transformations –Matrix stack v Applications
56
Comp 175C - Computer Graphics Dan Hebert Transformations We can think of graphics transformation as: v The process that is analogous to taking a photograph with a camera. v Changing the representation of a vertex from one coordinate system to another.
57
Comp 175C - Computer Graphics Dan Hebert Synthetic Camera Model Camera Model
58
Comp 175C - Computer Graphics Dan Hebert Transformations and Camera Analogy v Viewing transformation –Positioning and aiming camera in the world. v Modeling transformation –Positioning and moving the model. v Projection transformation –Adjusting the lens of the camera. v Viewport transformation –Enlarging or reducing the physical photograph.
59
Comp 175C - Computer Graphics Dan Hebert Transformations and Coordinate Systems v Viewing transformation –specifying camera (camera coordinates). v Modeling transformation –specifying geometry (world coordinates). v Projection transformation –projection (window coordinates). v Viewport transformation –mapping to screen (screen coordinates).
60
Comp 175C - Computer Graphics Dan Hebert Transformations in OpenGL v Transformations are specified by matrix operations. Desired transformation can be obtained by a sequence of simple transformations that can be concatenated together. v Transformation matrix is usually represented by 4x4 matrix (homogeneous coordinates). v Provides matrix stacks for each type of supported matrix to store matrices.
61
Comp 175C - Computer Graphics Dan Hebert Transformation Matrices v Model-viewing matrix v Projection matrix v Texture matrix
62
Comp 175C - Computer Graphics Dan Hebert OpenGL Transformation Pipeline
63
Comp 175C - Computer Graphics Dan Hebert Programming Transformations v In OpenGL, the transformation matrices are part of the state, they must be defined prior to any vertices to which they are to apply. v In modeling, we often have objects specified in their own coordinate systems and must use transformations to bring the objects into the scene. v OpenGL provides matrix stacks for each type of supported matrix (model-view, projection, texture) to store matrices.
64
Comp 175C - Computer Graphics Dan Hebert Steps in Programming v Prior to rendering, view, locate, and orient: –Eye/camera position –3D geometry v Manage the matrices –Including matrix stack v Composite transformations
65
Comp 175C - Computer Graphics Dan Hebert Current Transformation Matrix v Current Transformation Matrix (CTM) –The matrix that is applied to any vertex that is defined subsequent to its setting. v If change the CTM, we change the state of the system. v CTM is a 4 x 4 matrix that can be altered by a set of functions.
66
Comp 175C - Computer Graphics Dan Hebert Current Transformation Matrix The CTM can be set/reset/modify (by post- multiplication) by a matrix Ex: C <= M // set to matrix M C <= CT // post-multiply by T C <= CS // post-multiply by S C <= CR // post-multiply by R
67
Comp 175C - Computer Graphics Dan Hebert Current Transformation Matrix v Each transformation actually creates a new matrix that multiplies the CTM; the result, which becomes the new CTM. v CTM contains the cumulative product of multiplying transformation matrices. Ex: If C <= M; C <= CT; C <= CR; C <= CS Then C = M T R S
68
Comp 175C - Computer Graphics Dan Hebert Ways to Specify Transformations v In OpenGL, we usually have two styles of specifying transformations: –Specify matrices ( glLoadMatrix, glMultMatrix ) –Specify operations ( glRotate, glTranslate )
69
Comp 175C - Computer Graphics Dan Hebert Specifying Matrix v Specify current matrix mode v Modify current matrix v Load current matrix v Multiple current matrix
70
Comp 175C - Computer Graphics Dan Hebert Specifying Matrix (1) v Specify current matrix mode glMatrixMode (mode) Specified what transformation matrix is modified. mode: GL_MODELVIEW GL_PROJECTION GL_TEXTURE
71
Comp 175C - Computer Graphics Dan Hebert Specifying Matrix (2) v Modify current matrix glLoadMatrix{fd} ( Type *m ) Set the 16 values of current matrix to those specified by m. Note: m is the 1D array of 16 elements arranged by the columns of the desired matrix
72
Comp 175C - Computer Graphics Dan Hebert Specifying Matrix (3) v Modify current matrix glLoadIdentity ( void ) Set the currently modifiable matrix to the 4x4 identity matrix.
73
Comp 175C - Computer Graphics Dan Hebert Specifying Matrix (4) v Modify current matrix glMultMatrix{fd} ( Type *m ) Multiple the matrix specified by the 16 values pointed by m by the current matrix, and stores the result as current matrix. Note: m is the 1D array of 16 elements arranged by the columns of the desired matrix
74
Comp 175C - Computer Graphics Dan Hebert Specifying Operations v Three OpenGL operation routines for modeling transformations: –Translation –Scale –Rotation
75
Comp 175C - Computer Graphics Dan Hebert Recall 1000 100 010 001 z y x d d d ,, zyx dddT Translation: 1000 000 000 000 z y x s s s ,, zyx sssS Scale: Three elementary 3D transformations
76
Comp 175C - Computer Graphics Dan Hebert Recall 1000 0cossin0 0 cos0 0001 ) ( RxRx ) ( Ry 1000 0cos0sin 0010 0 0cos 1000 0100 00 sin 00 cos ) ( RzRz Rotation ) ( RxRx ) ( RyRy ) ( RzRz
77
Comp 175C - Computer Graphics Dan Hebert Problem Modify cube program to translate, scale, and rotate using glMultMatrix (changes commented out)
78
Comp 175C - Computer Graphics Dan Hebert Specifying Operations (1) v Translation glTranslate {fd} (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that translates an object by the given x, y, z.
79
Comp 175C - Computer Graphics Dan Hebert Specifying Operations (2) v Scale glScale {fd} (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that scales an object by the given x, y, z.
80
Comp 175C - Computer Graphics Dan Hebert Specifying Operations (3) v Rotate glRotate {fd} (TPE angle, TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from origin through the point by the given x, y, z. The angle parameter specifies the angle of rotation in degree.
81
Comp 175C - Computer Graphics Dan Hebert Example Let’s examine an example: – Rotation about an arbitrary point Question: Rotate a object for a 45.0-degree about the line through the origin and the point (1.0, 2.0, 3.0) with a fixed point of (4.0, 5.0, 6.0).
82
Comp 175C - Computer Graphics Dan Hebert Rotation About an Arbitrary Point 1.Translate object through vector –V. T(-4.0, -5.0, -6.0) 2.Rotate about the origin through angle R(45.0) 3.Translate back through vector V T(4.0, 5.0, 6.0) M = T(V ) R( ) T(-V )
83
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation glMatrixMode (GL_MODEVIEW); glLoadIdentity (); glTranslatef (4.0, 5.0, 6.0); glRotatef (45.0, 1.0, 2.0, 3.0); glTranslatef (-4.0, -5.0, -6.0);
84
Comp 175C - Computer Graphics Dan Hebert Order of Transformations v The transformation matrices appear in reverse order to that in which the transformations are applied. v In OpenGL, the transformation specified most recently is the one applied first.
85
Comp 175C - Computer Graphics Dan Hebert Order of Transformations v In each step: C <= I C <= CT(4.0, 5.0, 6.0) C <= CR(45, 1.0, 2.0, 3.0) C < = CT(-4.0, -5.0, -6.0) v Finally C = T(4.0, 5.0, 6.0) CR(45, 1.0, 2.0, 3.0) CT(-4.0, -5.0, -6.0) Write itRead it
86
Comp 175C - Computer Graphics Dan Hebert Matrix Multiplication is Not Commutative First rotate, then translate => First translate, then rotate =>
87
Comp 175C - Computer Graphics Dan Hebert Composition of Transformations v We can compose an overall transformation by applying several transformations in succession. v Any composition of affine transformations is still affine. v When homogeneous coordinates are used, affine transformations are composed by simple matrix multiplication.
88
Comp 175C - Computer Graphics Dan Hebert Problem 1.Draw the car body. 2.Translate to right front and draw wheel. 3.Return back to car body. 4.Translate to left front and draw wheel. 5.Return back to car body. …….. Always remember where you are!
89
Comp 175C - Computer Graphics Dan Hebert Matrix Stacks v OpenGL uses matrix stacks mechanism to manage transformation hierarchy. v OpenGL provides matrix stacks for each type of supported matrix to store matrices. –Model-view matrix stack –Projection matrix stack –Texture matrix stack
90
Comp 175C - Computer Graphics Dan Hebert Matrix Stacks Top Bottom Popping Pushing Current matrix is always the topmost matrix of the stack We manipulate the current matrix is that we actually manipulate the topmost matrix. We can control the current matrix by using push and pop operations.
91
Comp 175C - Computer Graphics Dan Hebert Manipulating Matrix Stacks (1) v Remember where you are glPushMatrix ( void ) Pushes all matrices in the current stack down one level. The topmost matrix is copied, so its contents are duplicated in both the top and second-from-the top matrix. Note: current stack is determined by glMatrixModel()
92
Comp 175C - Computer Graphics Dan Hebert Manipulating Matrix Stacks (2) v Go back to where you were glPopMatrix ( void ) Pops the top matrix off the stack, destroying the contents of the popped matrix. What was the second-from-the top matrix becomes the top matrix. Note: current stack is determined by glMatrixModel()
93
Comp 175C - Computer Graphics Dan Hebert Manipulating Matrix Stacks (3) v The depth of matrix stacks are implementation-dependent. v The Modelview matrix stack is guaranteed to be at least 32 matrices deep. v The Projection matrix stack is guaranteed to be at least 2 matrices deep. glGetIntegerv ( Glenum pname, Glint *parms ) Pname: GL_MAX_MODELVIEW_STACT_DEPTH GL_MAX_PROJECTION_STACT_DEPTH
94
Comp 175C - Computer Graphics Dan Hebert Demonstration (look at code)
95
Comp 175C - Computer Graphics Dan Hebert Demonstration (look at code)
96
Comp 175C - Computer Graphics Dan Hebert Demonstration (look at code)
97
Comp 175C - Computer Graphics Dan Hebert Let’s Examine Some Examples Question 1: Draw a simple solar system with a planet and a sun. Sun rotates around its own axis (Y axis) The planet rotates around its own axis (Y axis) The planet also rotates on its orbit around the sun.
98
Comp 175C - Computer Graphics Dan Hebert Example-1 Sun: Locates at the origin and rotates around its own axis (Y axis) M = R y ( ) Planet: 1. Rotates around its own axis. M 1 = R y ( ) 2. Translate to its orbit. M 2 = T (x, y, z) 3. Rotates around Sun. M 3 = R y ( ) M = M 3 M 2 M 1
99
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation void main (int argc, char** argv) { glutInit ( &argc, argv ); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (500, 500); glutCreateWindow ("Composite Modeling Transformation"); init (); glutDisplayFunc (display); glutReshapeFunc (reshape); glutKeyboardFunc (keyboard); glutMainLoop (); }
100
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation void init (void) { glViewport(0, 0, 500, 500); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef (0.0, 0.0, -5.0); // viewing transform glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); }
101
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glPushMatrix(); // draw sun glPushMatrix(); glRotatef ((GLfloat) ang2, 0.0, 1.0, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); // rotate it upright glutWireSphere(1.0, 20, 16); // glut routine glPopMatrix();
102
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation (con.) // draw smaller planet glRotatef ((GLfloat) ang1, 0.0, 1.0, 0.0); glTranslatef (2.0, 0.0, 0.0); glRotatef ((GLfloat) ang3, 0.0, 1.0, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); // rotate it upright glutWireSphere(0.2, 10, 8); // glut routine glPopMatrix(); glutSwapBuffers(); }
103
Comp 175C - Computer Graphics Dan Hebert Result
104
Comp 175C - Computer Graphics Dan Hebert Let’s Examine Some Examples Question 2: Draw a simple articulated robot arm with three segments. The arms should be connected with pivot points as the shoulder, elbow, or other joints. (the three segments have same length, saying 2 units) Pivot points
105
Comp 175C - Computer Graphics Dan Hebert Example-2 Red segment: 1. Translates unit 1 to its pivot point. M 1 = T (1, 0, 0) 2. Rotates around its pivot point. M 2 = R o ( ) 3. Translates –1 unit back to origin. M 3 = T (-1, 0, 0) M = M 3 M 2 M 1
106
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); // draw shoulder (red) glTranslatef (-1.0, 0.0, 0.0); glRotatef (shoulder, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 0.1); glColor3f (1.0, 0.0, 0.0); glutSolidCube (1); // glut routine glPopMatrix();
107
Comp 175C - Computer Graphics Dan Hebert Example-2 Green segment: 1. Translates unit 1 to its pivot point. M 1 = T (1, 0, 0) 2. Rotates around its pivot point. M 2 = R o ( ) 3. Translates 1 unit to the edge of the Red segment. M 3 = T (1, 0, 0) M = M 3 M 2 M 1
108
Comp 175C - Computer Graphics Dan Hebert OpenGL Implementation void display(void) { …… // draw elbow glTranslatef (1.0, 0.0, 0.0); glRotatef (elbow, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 0.1); glColor3f (0.0, 1.0, 0.0); glutSolidCube(1); // glut routine glPopMatrix();
109
Comp 175C - Computer Graphics Dan Hebert Example-2 Yellow segment: 1. Translates unit 1 to its pivot point. M 1 = T (1, 0, 0) 2. Rotates around its pivot point. M 2 = R o ( ) 3. Translates 1 unit to the edge of the Green segment. M 3 = T (1, 0, 0) M = M 3 M 2 M 1
110
Comp 175C - Computer Graphics Dan Hebert Result
111
Comp 175C - Computer Graphics Dan Hebert Problems Modify the Sailboat program, utilizing matrix multiplication, to do the following: Translate it to the middle of the window Scale it to half size Make it spin about the : X axis – left mouse button Y axis – middle mouse button Z axis - right mouse button
112
Comp 175C - Computer Graphics Dan Hebert Problems Modify the Teapot program, utilizing rotate-scale- translate, to do the following: Translate it to the bottom of the window Scale it to 1/3 size Rotate it 120 degrees about the x axis
113
Comp 175C - Computer Graphics Dan Hebert Remember v Always keep tracking your current position. Remember where you are, and go back to where you were. v Matrix multiplication is not commutative, the transformation order is very important. v In OpenGL, the transformation specified most recently is the one applied first.
114
Comp 175C - Computer Graphics Dan Hebert glu quadric Primitives v Quadric primitives – gluCylinder – gluDisk – gluPartialDisk – gluSphere v Displays at 0, 0, 0 – Translate to where you want it
115
Comp 175C - Computer Graphics Dan Hebert gluNewQuadric Create a new Quadric Object gluNewQuadric ();
116
Comp 175C - Computer Graphics Dan Hebert gluCylinder Draw a cylinder gluCylinder ( quad, base, top, height, slices, stacks ); quad – specifies the quadrics object (create with gluNewQuadric) base – specifies the radius of the cylinder at z=0 top – specifies the radius of the cylinder at z=height height - specifies the height of the cylinder slices – specifies the number of subdivisions around the z axis stacks - specifies the number of subdivisions along the z axis
117
Comp 175C - Computer Graphics Dan Hebert gluDisk Draw a disk gluDisk ( quad, inner, outer, slices, loops ); quad – specifies the quadrics object (create with gluNewQuadric) inner – specifies the inner radius of the disk (may be 0) outer – specifies the outer radius of the disk slices – specifies the number of subdivisions around the z axis loops - specifies the number of concentric rings about the origin into which the disk is subdivided
118
Comp 175C - Computer Graphics Dan Hebert gluPartialDisk Draw an arc of a disk gluPartialDisk ( quad, inner, outer, slices, loops, start, sweep ); quad – specifies the quadrics object (create with gluNewQuadric) inner – specifies the inner radius of the disk (may be 0) outer – specifies the inner radius of the disk slices – specifies the number of subdivisions around the z axis loops - specifies the number of concentric rings about the origin into which the disk is subdivided start – specifies the starting angle, in degrees, of the disk portion sweep – specifies the sweep angle, in degrees, of the disk portion
119
Comp 175C - Computer Graphics Dan Hebert gluSphere Draw a sphere gluSphere ( quad, radius, slices, stacks ); quad – specifies the quadrics object (create with gluNewQuadric) radius – specifies the radius of the sphere slices – specifies the number of subdivisions around the z axis stacks - specifies the number of subdivisions along the z axis
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.