SlideShare a Scribd company logo
Chapter 5
Three-Dimensional Geometric
Transformations
Computer Graphics
C. P. Divate
Outline
⚫ 3DTranslation
⚫ 3D Rotation
⚫ 3D Scaling
⚫ Transformations between 3D Coordinate Systems
⚫ OpenGLGeometricTransformation Functions
⚫ OpenGL3D GeometricTransformation Programming Examples
2
3D Transformation
⚫Same as2D.
⚫Add z-axis and z-coordinate.
⚫Use 4X4 homogenous matrix.
(x, y
, z, w)
p

w

m
l  z 
 i
d  x 
h  y 
 a b c
f g
j k
n o

w'

 z'
 y'   e
 x'
3
Right-hand coordinate system
⚫ OpenGL: right-hand
⚫ The positive x and yaxes point right and up, and the zaxispoints to the viewer.
⚫ Positive rotation is counterclockwise about the axis of rotation when looking
alongthe positive halfof the axis toward the origin.
4
3D Translation
⚫ Aposition P=(x,y,z) in 3D space is translated to alocation
P’=(x’,y’,z’) byadding translation distances tx,ty, and tz:
z' z  tz
x' x  tx y' y  ty
FIGURE9-2 Shifting the
position of athree-dimensional
object using translationvectorT
.
  

  

1 
 1 
0 1
0 0 0
0
0 1 0
1 0 0
t  y
z'
 
y'
x'
tz
 z 
y   
tx  x
(9-1)
(9-2)
P' = TP (9-3)
Bymatrix form:
1 
or
5
3D Rotation
Positive rotations:counterclockwise when lookingalongthe positive
half of the axis toward the origin
⚫ Coordinate-AxesRotations
⚫ X-axis,Y
-axisor Z-axis rotation
⚫ Rotation about an axis that is in parallel to one of the coordinate axes
⚫ General 3D Rotations
⚫ Rotation about an arbitraryaxis
6
3D Coordinate Axis Rotation
⚫Rotation of an object about the yaxis
z' = z
⚫Rotation of an object about the zaxis
x' = x cos - ysin
y' = x sin + ycos
 
  
1 1 
 0
1 
⚫ Rotation of an object about the x axis
0 z 
  
0  y
0  x
z'  0
  
y'
Rx  
sin
x' cos sin 0
cos 0
0 1
0 0
 
  
1  1 
 0
1 
0  z 
  
0  y
0  x
y' 0
Ry  
z' sin
  
x' cos 0 sin
1 0
0 cos
0 0




 
  
 

  
  
 
1
 
1

1
1  0
0  z
0  y
0  x
 z' 0

y' 
0
 x' 0 0
  cos sin 
Rz 

    
 
sin cos
0 0
7
z x; x  y; y z.
x  y; y z;z x.
3D Rotations Parallel to Axes
⚫ Rotation an axis that is parallel to one of the coordinate axes
⚫ Translatethe object so that the rotation axis coincides with the parallel
coordinate axis
⚫ Performthe specified rotation about that axis
⚫ Translatethe object so that the rotation axisis moved back to its original
position
8
3D Rotations about Arbitrary Axis
⚫Rotate about the arbitraryaxis through P1 and P2:
1. Translate P1 to origin.
2.Rotate so that the rotation axis is alignedwith one of the
principle coordinate axes.
3. Perform the desired rotation about coordinate axis.
4. Rotate axis back (inverse rotation of 2).
5. Translate axis back(inverse translation of 1).
P1
x
y
z
Arbitraryaxis
P2
9
[T]
[R1]
[R-axis]
[R1]-1
[T]-1
3D Scaling
⚫Scaleobjects relative to the coordinate origin (0, 0, 0)
⚫All vectorsare scaledfrom the origin
Original scale all axes scale Y axis
offset from origin distance from origin also scales
10
3D Scaling
0
      P' SP
0 y
0 x

z
 
 0
y  s y   0 s
x
 
sz 

z

y
sx 0

sz z

y
sx x
or in 3D homogeneous coordinates
 
      
     11
 1   1   0
 
0z
0y
0x
y s y  0
0 0
s 0
0 sz
0 0
y
z sz z  0
y
x sx x sx
(9-41)
11
3D Scaling
⚫Scaling objects relative to aselected fixed point (xf, yf, zf)
Translate fixed point to origin Scale Translate fixed point back
12
3D Scaling
⚫Scaling objects relative to aselected fixed point (xf, yf, zf)
(cont.)

0 z f


y f 
y
f f f x y z f f f

0 sz (1 s )z
0 0 0 1
s 0 (1 s )y

sx 0 0 (1 sx )xf 

0
T(x , y , z )  S(s ,s ,s ) T(x ,y ,z )  


1
00
01
1  0
1
0
f

f 
z
y
f

f 
f f f x y z f f f
xf 
0 0 0 0 0 0
1 0 s 0  1 0  y 
0 0 1 z  0 0 s 00 0 1  z 
0 0 0 0 0 10 0 0

y  0
xf sx
T(x , y , z )S(s ,s ,s )T(x ,y ,z )  
13
Matrix Composition
⚫ Transformations can be combined bymatrix multiplication


  
  


 
 
 

1 w
0  z 
0  y 
0 0 0  x 
sy 0
0 sz
0 0
0 0
0sx
1 
 0

w'
  0
 z' 
 0
 y'
 x'
p’ = T(tx,ty)
 1 0 0 tx cos   sin  0
1 0 ty sin  cos  0
 
0 1 tz  0 0 1 0 0
0 0 0 0 0 1 0
R(Q) S(sx,sy) p
p’= (T * (R * (S*p) ) )
p’= (T*R*S ) * p
⚫ Order of transformations
⚫Matrix multiplication is not commutative
p’= T * R* S* p
“Global” “Local”
14
Transformations Between 3D Coordinate Systems
Mxyz, x'y'z' = R˙T(-x0, -y0, -z0)
 If different scalesare used in the two coordinate systems, the scalingtransformation
mayalso be needed.


(P313) 0 
0 
0
y1 y2 y3
u'z1 u'z2 u'z3

0 0 1
u' u' u'
u'x1 u'x2 u'x3 0
R  
FIGURE9-21 Anew x’y’z’coordinate system
defined within an xyzsystem.Ascene description
istransferred to the new coordinate reference
usinga transformationsequencethat
superimposes the x’y’z’frame on the xyzaxes.
 Totransfer the xyz coordinate descriptions -> x’y’z’coordinate system
 Translation: bring the x’y’z’coordinate origin to the position of the xyz origin.
 Transform x’y’z’ onto the corresponding axes xyz: the coordinate-axis rotation
matrix formed bythe unit axisvectors.
which transforms unit vector u’x,
u’y,u’z onto the x,yand z axes.
15
OpenGL Geometric Transformation Functions
⚫Becareful of manipulating the matrix in OpenGL
⚫OpenGLuses 4X4 matrix for transformation.
⚫The 16 elements are stored as1D in column-majororder
OpenGLtransformmatrix
⚫C and C++ store matrices in row-majororder
⚫Ifyou declare amatrix to be used in OpenGLas
GLfloat M[4][4];to accessthe element in row i and column j, you
need to refer to it byM[j][i];or, as
GLfloat M[16];and then you need to convert it to conventional row-
majororder.
16
OpenGL Transformations
⚫All the transformations done byOpenGLcan be
described asamultiplication of two or more
matrices.
⚫The mathematicsbehind these transformations are greatly
simplifiedbythe mathematicalnotation of the matrix.
⚫Eachof the transformations can be achieved bymultiplying a
matrix that contains the vertices,bya matrix that describes
the transformation.
17
OpenGL Geometric Transformation Functions
⚫ BasicOpenGLgeometrictransformations on the matrix:
glT
ranslate* (tx, ty
, tz);
[ glTranslatef(25.0,-10.0,10.0);
- Post-multiplies the current matrix byamatrix that moves the object bythe given x-,
y-, and z-values
glScale* (sx, sy
, sz);
[glScalef (2.0, -3.0, 1.0); ]
- Post-multiplies the current matrix byamatrix that scalesan object about the origin.
None of sx, syor sziszero.
glRotate* (theta,vx, vy
, vz);
[ glRotatef (90.0, 0.0, 0.0, 1.0); ]
- Post-multiplies the current matrix byamatrix that rotates the object in a
counterclockwise direction. vector v=(vx, vy,vz) defines the orientation for the
rotation axis that passesthrough the coordinate origin.( the rotation center is (0, 0, 0) )
18
OpenGL: Order in Matrix Multiplication
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ( ); //Set current matrix to the identity
.
glMultMatrixf (elemsM2);//P ost-multiplyidentity bymatrix M2.
glMultMatrixf (elemsM1);//P ost-multiplyM2bymatrix M1.
glBegin (GL_POINTS)
glV
ertex3f (vertex);
glEnd( );
Modelview matrix successivelycontains:
I(identity),M2, M2 M1
The concatenated matrix is:
M=M2 M1
The transformed vertex is:
M2(M1 vertex)
In OpenGL, atransformation sequence is applied in reverse
order of which it isspecified.
19
OpenGL: Order in Matrix Multiplication
⚫Example
/ / rotate object 30 degrees around X-axis
glRotatef(30.0, 1.0, 0.0, 0.0);
/ / move object to (x, y
, z)
glTranslatef(x, y
, z);
drawObject();
The object will be translated first then rotated.
20
Independent Models: Matrix Stacks
⚫How OpenGL implement the independent models?
⚫OpenGL maintains astack of matrices.
⚫ Each type of the matrix modes hasamatrix stack (modelview,projection,texture,
and color)
⚫ Initial value is identity matrix
⚫ The top matrix on the stack at anytime: the current matrix
⚫ New matrix transformation function is appliedto the current matrix
⚫ To use push or pop functions to modifyit.
21
Functions About Matrix Stack Operations
⚫ Find the maximum allowablenumber of matrices in stack
glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH,
stackSize);
glGetIntegerv (GL_MAX_PROJECTION_STACK_DEPTH,
stackSize);
⚫ Find out how manymatrices are currentlyin the stack
glGetIntegerv (GL_MODEL
VIEW_ST
ACK_DEPTH, numMats);
22
Functions About Matrix Stack Operations
glPushMatrix ( )
⚫ Push the current matrix down one
level and copythe current matrix
glPopMatrix ( )
⚫ Pop the top matrix off the stack
⚫ Matrix stack is very useful for creating hierarchical model (body,car ...).
⚫ Save the current position (modelview)
⚫ Load aprevious position or new ones
23
Matrix Stack Operations
⚫Example
glMatrixMode(GL_MODEL
VIEW);
glPushMatrix ();
glTranslatef( 0.0, 0.0, -8.0 );
glTranslatef( 1.0, 0.0, 0.0 );
DrawObj ();
glPopMatrix ();
modelview matrix stack
24
OpenGL Geometric Trans. Programming Examples
glMatrixMode (GL_MODEL
VIEW); //Identity matrix
glColor3f (0.0, 0.0, 1.0);
glRecti (50, 100, 200, 150);
/ / Set current color to blue
/ / Displayblue rectangle.
glColor3f (1.0, 0.0, 0.0); / / Red
glTranslatef (-200.0, -50.0, 0.0); / / Set translation parameters.
glRecti (50, 100, 200, 150); / / Displayred, translated rectangle.
glLoadIdentity (); / / Reset current matrix to identity
.
glRotatef (90.0, 0.0, 0.0, 1.0); / / Set 90-deg, rotation about zaxis.
glRecti (50, 100, 200, 150); / / Displayred, rotated rectangle.
glLoadIdentity ();
glScalef (-0.5, 1.0, 1.0);
/ / Reset current matrix to identity
.
/ / Set scale-reflection parameters.
glRecti (50, 100, 200, 150); / / Displayred, transformed rectangle.
25
OpenGL Geometric Trans. Programming Examples
glColor3f (0.0, 0.0, 1.0);
glRecti (50, 100, 200, 150);
/ / Set current color to blue.
/ / Displayblue rectangle.
glPushMatrix (); / / Make copyof identity (top) matrix.
glColor3f (1.0, 0.0, 0.0); / / Set current color to red.
glTranslatef (-200.0, -50.0, 0.0); / / Set translation parameters.
glRecti (50, 100, 200, 150); / / Displayred, translated rectangle.
glPopMatrix (); / / Throw awaythe translation matrix.
glPushMatrix (); / / Make copyof identity (top) matrix.
glRotatef (90.0, 0.0, 0.0, 1.0); / / Set 90-deg, rotation about zaxis.
glRecti (50, 100, 200, 150); / / Displayred, rotated rectangle.
glPopMatrix (); / / Throw awaythe rotation matrix.
glScalef (-0.5, 1.0, 1.0);
glRecti (50, 100, 200, 150);
/ / Set scale-reflection parameters.
/ / Displayred, transformed rectangle.
⚫More efficient way:glPushMatrix/glPopMatrix
glMatrixMode (GL_MODEL
VIEW);
26
Example
⚫Drawing acar’wheels with bolts
draw_wheel( );
for (j=0; j<5; j++) {
glPushMatrix ();
glRotatef(72.0*j, 0.0, 0.0, 1.0);
glTranslatef (3.0, 0.0, 0.0);
draw_bolt ( );
glPopMatrix ( );
}
R
RT
RTv
Global – Bottom Up
Start Rot
Trans
The wheels and bolt axes are coincident with z-axis;the
bolts are evenlyspaced every72 degrees,3 units fromthe
center of the wheel.
27
Summary
⚫ Basic3D geometrictransformations
⚫ Translation
⚫ Rotation
⚫ Scaling
⚫ Combination of these transformations
⚫ OpenGL3D geometric transformation functions
⚫ GL_MODEL
VIEWmatrix
⚫ Order in multiple matrix multiplication
⚫ Matrix stack
⚫ glPushMatrix ()
⚫ glPopMatrix ()
28

More Related Content

Similar to Computer Graphics Three-Dimensional Geometric Transformations

3D Transformation
3D Transformation 3D Transformation
3D Transformation
Mahmudul Hasan
 
2d transformations
2d transformations2d transformations
2d transformations
rajeshranjithsingh
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
University of Potsdam
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
Asma Tehseen
 
2D Translation.pdf
2D Translation.pdf2D Translation.pdf
2D Translation.pdf
MehulMunshi3
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
Janie Clayton
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
SHIVANI SONI
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
Mark Kilgard
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
Mani Kanth
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
Mark Kilgard
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
aravindangc
 
09transformation3d
09transformation3d09transformation3d
09transformation3d
Ketan Jani
 
transformation 3d
transformation 3dtransformation 3d
transformation 3d
HiteshJain007
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
sandeep kumbhkar
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
Patel Punit
 
Lecture 6-1543909797
Lecture 6-1543909797Lecture 6-1543909797
Lecture 6-1543909797
Canh Le
 
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeksBeginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
JinTaek Seo
 
3 d transformations
3 d transformations3 d transformations
3 d transformations
Ankit Garg
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
Ankit Garg
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 

Similar to Computer Graphics Three-Dimensional Geometric Transformations (20)

3D Transformation
3D Transformation 3D Transformation
3D Transformation
 
2d transformations
2d transformations2d transformations
2d transformations
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
2D Translation.pdf
2D Translation.pdf2D Translation.pdf
2D Translation.pdf
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
09transformation3d
09transformation3d09transformation3d
09transformation3d
 
transformation 3d
transformation 3dtransformation 3d
transformation 3d
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
 
Lecture 6-1543909797
Lecture 6-1543909797Lecture 6-1543909797
Lecture 6-1543909797
 
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeksBeginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
 
3 d transformations
3 d transformations3 d transformations
3 d transformations
 
2 d transformation
2 d transformation2 d transformation
2 d transformation
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 

More from Chandrakant Divate

Web Technology LAB MANUAL for Undergraduate Programs
Web Technology  LAB MANUAL for Undergraduate ProgramsWeb Technology  LAB MANUAL for Undergraduate Programs
Web Technology LAB MANUAL for Undergraduate Programs
Chandrakant Divate
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
Chandrakant Divate
 
Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
Chandrakant Divate
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
Chandrakant Divate
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
Chandrakant Divate
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
Chandrakant Divate
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
Chandrakant Divate
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
Chandrakant Divate
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
Chandrakant Divate
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
Chandrakant Divate
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
Chandrakant Divate
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
Chandrakant Divate
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
Chandrakant Divate
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
Chandrakant Divate
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Chandrakant Divate
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
Chandrakant Divate
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
Chandrakant Divate
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
Chandrakant Divate
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
Chandrakant Divate
 

More from Chandrakant Divate (20)

Web Technology LAB MANUAL for Undergraduate Programs
Web Technology  LAB MANUAL for Undergraduate ProgramsWeb Technology  LAB MANUAL for Undergraduate Programs
Web Technology LAB MANUAL for Undergraduate Programs
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
 
Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
 

Recently uploaded

Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 

Recently uploaded (20)

Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 

Computer Graphics Three-Dimensional Geometric Transformations

  • 2. Outline ⚫ 3DTranslation ⚫ 3D Rotation ⚫ 3D Scaling ⚫ Transformations between 3D Coordinate Systems ⚫ OpenGLGeometricTransformation Functions ⚫ OpenGL3D GeometricTransformation Programming Examples 2
  • 3. 3D Transformation ⚫Same as2D. ⚫Add z-axis and z-coordinate. ⚫Use 4X4 homogenous matrix. (x, y , z, w) p  w  m l  z   i d  x  h  y   a b c f g j k n o  w'   z'  y'   e  x' 3
  • 4. Right-hand coordinate system ⚫ OpenGL: right-hand ⚫ The positive x and yaxes point right and up, and the zaxispoints to the viewer. ⚫ Positive rotation is counterclockwise about the axis of rotation when looking alongthe positive halfof the axis toward the origin. 4
  • 5. 3D Translation ⚫ Aposition P=(x,y,z) in 3D space is translated to alocation P’=(x’,y’,z’) byadding translation distances tx,ty, and tz: z' z  tz x' x  tx y' y  ty FIGURE9-2 Shifting the position of athree-dimensional object using translationvectorT .         1   1  0 1 0 0 0 0 0 1 0 1 0 0 t  y z'   y' x' tz  z  y    tx  x (9-1) (9-2) P' = TP (9-3) Bymatrix form: 1  or 5
  • 6. 3D Rotation Positive rotations:counterclockwise when lookingalongthe positive half of the axis toward the origin ⚫ Coordinate-AxesRotations ⚫ X-axis,Y -axisor Z-axis rotation ⚫ Rotation about an axis that is in parallel to one of the coordinate axes ⚫ General 3D Rotations ⚫ Rotation about an arbitraryaxis 6
  • 7. 3D Coordinate Axis Rotation ⚫Rotation of an object about the yaxis z' = z ⚫Rotation of an object about the zaxis x' = x cos - ysin y' = x sin + ycos      1 1   0 1  ⚫ Rotation of an object about the x axis 0 z     0  y 0  x z'  0    y' Rx   sin x' cos sin 0 cos 0 0 1 0 0      1  1   0 1  0  z     0  y 0  x y' 0 Ry   z' sin    x' cos 0 sin 1 0 0 cos 0 0                     1   1  1 1  0 0  z 0  y 0  x  z' 0  y'  0  x' 0 0   cos sin  Rz          sin cos 0 0 7 z x; x  y; y z. x  y; y z;z x.
  • 8. 3D Rotations Parallel to Axes ⚫ Rotation an axis that is parallel to one of the coordinate axes ⚫ Translatethe object so that the rotation axis coincides with the parallel coordinate axis ⚫ Performthe specified rotation about that axis ⚫ Translatethe object so that the rotation axisis moved back to its original position 8
  • 9. 3D Rotations about Arbitrary Axis ⚫Rotate about the arbitraryaxis through P1 and P2: 1. Translate P1 to origin. 2.Rotate so that the rotation axis is alignedwith one of the principle coordinate axes. 3. Perform the desired rotation about coordinate axis. 4. Rotate axis back (inverse rotation of 2). 5. Translate axis back(inverse translation of 1). P1 x y z Arbitraryaxis P2 9 [T] [R1] [R-axis] [R1]-1 [T]-1
  • 10. 3D Scaling ⚫Scaleobjects relative to the coordinate origin (0, 0, 0) ⚫All vectorsare scaledfrom the origin Original scale all axes scale Y axis offset from origin distance from origin also scales 10
  • 11. 3D Scaling 0       P' SP 0 y 0 x  z    0 y  s y   0 s x   sz   z  y sx 0  sz z  y sx x or in 3D homogeneous coordinates               11  1   1   0   0z 0y 0x y s y  0 0 0 s 0 0 sz 0 0 y z sz z  0 y x sx x sx (9-41) 11
  • 12. 3D Scaling ⚫Scaling objects relative to aselected fixed point (xf, yf, zf) Translate fixed point to origin Scale Translate fixed point back 12
  • 13. 3D Scaling ⚫Scaling objects relative to aselected fixed point (xf, yf, zf) (cont.)  0 z f   y f  y f f f x y z f f f  0 sz (1 s )z 0 0 0 1 s 0 (1 s )y  sx 0 0 (1 sx )xf   0 T(x , y , z )  S(s ,s ,s ) T(x ,y ,z )     1 00 01 1  0 1 0 f  f  z y f  f  f f f x y z f f f xf  0 0 0 0 0 0 1 0 s 0  1 0  y  0 0 1 z  0 0 s 00 0 1  z  0 0 0 0 0 10 0 0  y  0 xf sx T(x , y , z )S(s ,s ,s )T(x ,y ,z )   13
  • 14. Matrix Composition ⚫ Transformations can be combined bymatrix multiplication                  1 w 0  z  0  y  0 0 0  x  sy 0 0 sz 0 0 0 0 0sx 1   0  w'   0  z'   0  y'  x' p’ = T(tx,ty)  1 0 0 tx cos   sin  0 1 0 ty sin  cos  0   0 1 tz  0 0 1 0 0 0 0 0 0 0 1 0 R(Q) S(sx,sy) p p’= (T * (R * (S*p) ) ) p’= (T*R*S ) * p ⚫ Order of transformations ⚫Matrix multiplication is not commutative p’= T * R* S* p “Global” “Local” 14
  • 15. Transformations Between 3D Coordinate Systems Mxyz, x'y'z' = R˙T(-x0, -y0, -z0)  If different scalesare used in the two coordinate systems, the scalingtransformation mayalso be needed.   (P313) 0  0  0 y1 y2 y3 u'z1 u'z2 u'z3  0 0 1 u' u' u' u'x1 u'x2 u'x3 0 R   FIGURE9-21 Anew x’y’z’coordinate system defined within an xyzsystem.Ascene description istransferred to the new coordinate reference usinga transformationsequencethat superimposes the x’y’z’frame on the xyzaxes.  Totransfer the xyz coordinate descriptions -> x’y’z’coordinate system  Translation: bring the x’y’z’coordinate origin to the position of the xyz origin.  Transform x’y’z’ onto the corresponding axes xyz: the coordinate-axis rotation matrix formed bythe unit axisvectors. which transforms unit vector u’x, u’y,u’z onto the x,yand z axes. 15
  • 16. OpenGL Geometric Transformation Functions ⚫Becareful of manipulating the matrix in OpenGL ⚫OpenGLuses 4X4 matrix for transformation. ⚫The 16 elements are stored as1D in column-majororder OpenGLtransformmatrix ⚫C and C++ store matrices in row-majororder ⚫Ifyou declare amatrix to be used in OpenGLas GLfloat M[4][4];to accessthe element in row i and column j, you need to refer to it byM[j][i];or, as GLfloat M[16];and then you need to convert it to conventional row- majororder. 16
  • 17. OpenGL Transformations ⚫All the transformations done byOpenGLcan be described asamultiplication of two or more matrices. ⚫The mathematicsbehind these transformations are greatly simplifiedbythe mathematicalnotation of the matrix. ⚫Eachof the transformations can be achieved bymultiplying a matrix that contains the vertices,bya matrix that describes the transformation. 17
  • 18. OpenGL Geometric Transformation Functions ⚫ BasicOpenGLgeometrictransformations on the matrix: glT ranslate* (tx, ty , tz); [ glTranslatef(25.0,-10.0,10.0); - Post-multiplies the current matrix byamatrix that moves the object bythe given x-, y-, and z-values glScale* (sx, sy , sz); [glScalef (2.0, -3.0, 1.0); ] - Post-multiplies the current matrix byamatrix that scalesan object about the origin. None of sx, syor sziszero. glRotate* (theta,vx, vy , vz); [ glRotatef (90.0, 0.0, 0.0, 1.0); ] - Post-multiplies the current matrix byamatrix that rotates the object in a counterclockwise direction. vector v=(vx, vy,vz) defines the orientation for the rotation axis that passesthrough the coordinate origin.( the rotation center is (0, 0, 0) ) 18
  • 19. OpenGL: Order in Matrix Multiplication glMatrixMode (GL_MODELVIEW); glLoadIdentity ( ); //Set current matrix to the identity . glMultMatrixf (elemsM2);//P ost-multiplyidentity bymatrix M2. glMultMatrixf (elemsM1);//P ost-multiplyM2bymatrix M1. glBegin (GL_POINTS) glV ertex3f (vertex); glEnd( ); Modelview matrix successivelycontains: I(identity),M2, M2 M1 The concatenated matrix is: M=M2 M1 The transformed vertex is: M2(M1 vertex) In OpenGL, atransformation sequence is applied in reverse order of which it isspecified. 19
  • 20. OpenGL: Order in Matrix Multiplication ⚫Example / / rotate object 30 degrees around X-axis glRotatef(30.0, 1.0, 0.0, 0.0); / / move object to (x, y , z) glTranslatef(x, y , z); drawObject(); The object will be translated first then rotated. 20
  • 21. Independent Models: Matrix Stacks ⚫How OpenGL implement the independent models? ⚫OpenGL maintains astack of matrices. ⚫ Each type of the matrix modes hasamatrix stack (modelview,projection,texture, and color) ⚫ Initial value is identity matrix ⚫ The top matrix on the stack at anytime: the current matrix ⚫ New matrix transformation function is appliedto the current matrix ⚫ To use push or pop functions to modifyit. 21
  • 22. Functions About Matrix Stack Operations ⚫ Find the maximum allowablenumber of matrices in stack glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, stackSize); glGetIntegerv (GL_MAX_PROJECTION_STACK_DEPTH, stackSize); ⚫ Find out how manymatrices are currentlyin the stack glGetIntegerv (GL_MODEL VIEW_ST ACK_DEPTH, numMats); 22
  • 23. Functions About Matrix Stack Operations glPushMatrix ( ) ⚫ Push the current matrix down one level and copythe current matrix glPopMatrix ( ) ⚫ Pop the top matrix off the stack ⚫ Matrix stack is very useful for creating hierarchical model (body,car ...). ⚫ Save the current position (modelview) ⚫ Load aprevious position or new ones 23
  • 24. Matrix Stack Operations ⚫Example glMatrixMode(GL_MODEL VIEW); glPushMatrix (); glTranslatef( 0.0, 0.0, -8.0 ); glTranslatef( 1.0, 0.0, 0.0 ); DrawObj (); glPopMatrix (); modelview matrix stack 24
  • 25. OpenGL Geometric Trans. Programming Examples glMatrixMode (GL_MODEL VIEW); //Identity matrix glColor3f (0.0, 0.0, 1.0); glRecti (50, 100, 200, 150); / / Set current color to blue / / Displayblue rectangle. glColor3f (1.0, 0.0, 0.0); / / Red glTranslatef (-200.0, -50.0, 0.0); / / Set translation parameters. glRecti (50, 100, 200, 150); / / Displayred, translated rectangle. glLoadIdentity (); / / Reset current matrix to identity . glRotatef (90.0, 0.0, 0.0, 1.0); / / Set 90-deg, rotation about zaxis. glRecti (50, 100, 200, 150); / / Displayred, rotated rectangle. glLoadIdentity (); glScalef (-0.5, 1.0, 1.0); / / Reset current matrix to identity . / / Set scale-reflection parameters. glRecti (50, 100, 200, 150); / / Displayred, transformed rectangle. 25
  • 26. OpenGL Geometric Trans. Programming Examples glColor3f (0.0, 0.0, 1.0); glRecti (50, 100, 200, 150); / / Set current color to blue. / / Displayblue rectangle. glPushMatrix (); / / Make copyof identity (top) matrix. glColor3f (1.0, 0.0, 0.0); / / Set current color to red. glTranslatef (-200.0, -50.0, 0.0); / / Set translation parameters. glRecti (50, 100, 200, 150); / / Displayred, translated rectangle. glPopMatrix (); / / Throw awaythe translation matrix. glPushMatrix (); / / Make copyof identity (top) matrix. glRotatef (90.0, 0.0, 0.0, 1.0); / / Set 90-deg, rotation about zaxis. glRecti (50, 100, 200, 150); / / Displayred, rotated rectangle. glPopMatrix (); / / Throw awaythe rotation matrix. glScalef (-0.5, 1.0, 1.0); glRecti (50, 100, 200, 150); / / Set scale-reflection parameters. / / Displayred, transformed rectangle. ⚫More efficient way:glPushMatrix/glPopMatrix glMatrixMode (GL_MODEL VIEW); 26
  • 27. Example ⚫Drawing acar’wheels with bolts draw_wheel( ); for (j=0; j<5; j++) { glPushMatrix (); glRotatef(72.0*j, 0.0, 0.0, 1.0); glTranslatef (3.0, 0.0, 0.0); draw_bolt ( ); glPopMatrix ( ); } R RT RTv Global – Bottom Up Start Rot Trans The wheels and bolt axes are coincident with z-axis;the bolts are evenlyspaced every72 degrees,3 units fromthe center of the wheel. 27
  • 28. Summary ⚫ Basic3D geometrictransformations ⚫ Translation ⚫ Rotation ⚫ Scaling ⚫ Combination of these transformations ⚫ OpenGL3D geometric transformation functions ⚫ GL_MODEL VIEWmatrix ⚫ Order in multiple matrix multiplication ⚫ Matrix stack ⚫ glPushMatrix () ⚫ glPopMatrix () 28