Computer Graphics 2D & 3D Transformation.

Slides:



Advertisements
Similar presentations
Computer Graphics - Transformation -
Advertisements

SI23 Introduction to Computer Graphics
Figures based on regular polygons (lab3)
1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
Hierarchical Transformation. Summary Alternatively, OpenGL thinks: A transformation updates the coordinate system. For each change, the transformation.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
Computer Graphics Lecture 4 Geometry & Transformations.
University of North Carolina at Greensboro
Geometric Transformations
Elementary 3D Transformations - a "Graphics Engine" Transformation procedures Transformations of coordinate systems Translation Scaling Rotation.
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 8: 3D Affine transforms Emmanuel Agu.
2IV60 Computer Graphics 2D transformations
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Transformations Dr. Amy Zhang.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformations.
1 Computer Graphics Week9 -3D Geometric Transformation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
3D Transformations. Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T. P tx ty tz xyz1xyz1 x’ y’ z’ 1 x y.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Composing Transformations
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
Transformation. 3D Transformation oIn the modeling lecture we saw how to define an object in terms of its vertices in object space oWe will now see how.
1 By Dr. HANY ELSALAMONY.  We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSCE 441 Computer Graphics: 2D Transformations
학기 Chapter 5. Geometric Transformations 1.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
2D Geometric Transformations
Computer Graphics Transformations.
Summary of Properties of 3D Affine Transformations
Review: Transformations
3D Geometric Transformations
Introduction to Computer Graphics CS 445 / 645
Lecture 7 Geometric Transformations (Continued)
Transformation and Viewing
Three-Dimensional Graphics
Geometric Transformations
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Chapters 5/4 part2 understanding transformations working with matrices
Geometric Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Three-Dimensional Graphics
Transformations in OpenGL
Geometric Transformations
Geometric Objects and Transformations (II)
Geometric Transformations
Lecture #6 2D Geometric Transformations
Presentation transcript:

Computer Graphics 2D & 3D Transformation

2D Transformation transform composition: multiple transform on the same object (same reference point or line!) p’ = T1 * T2 * T3 * …. * Tn-1 * Tn * p, where T1…Tn are transform matrices efficiency-wise, for objects with many vertices, which one is better? 1) p’ = (T1 * (T2 * (T3 * ….* (Tn-1 * (Tn * p))…) 2) p’ = (T1 * T2 * T3 * …. * Tn-1 * Tn) * p matrix multiplication is NOT commutative, in general (T1 * T2) * T3 != T1 * (T2 * T3) translate  scale may differ from scale  translate translate  rotate may differ from rotate  translate rotate  non-uniform scale may differ from non-uniform scale  rotate

2D Transformation commutative transform composition: translate 1  translate 2 == translate 2  translate 1 scale 1  scale 2 == scale 2  scale 1 rotate 1  rotate 2 == rotate 2  rotate 1 uniform scale  rotate == rotate  uniform scale matrix multiplication is NOT commutative, in general (T1 * T2) * T3 != T1 * (T2 * T3) translate  scale may differ from scale  translate translate  rotate may differ from rotate  translate rotate  non-uniform scale may differ from non-uniform scale  rotate

3D Transformation simple extension of 2D by adding a Z coordinate transformation matrix: 4 x 4 3D homogeneous coordinates: p = [x y z w]T Our textbook and OpenGL use a RIGHT-HANDED system y note: z axis comes toward the viewer from the screen x z

3D Translation 1 0 0 tx 0 1 0 ty T (tx, ty, tz) = 0 0 1 tz 0 0 0 1

3D Scale sx 0 0 0 0 sy 0 0 S (sx, sy, sz) = 0 0 sz 0 0 0 0 1

3D Rotation about x-axis 1 0 0 0 0 cos(θ) -sin(θ) 0 Rx (θ) = 0 sin(θ) cos(θ) 0 0 0 0 1 note: x-coordinate does not change

3D Rotation about x-axis suppose we have a unit cube at the origin blue vertex (0, 1, 0)  Rx(90)  (0, 0, -1) green vertex (0, 1, 1)  Rx(90)  (0, 1, -1) yellow vertex (1, 1, 0)  Rx(90)  (1, 0, -1) red vertex (1, 1, 1)  Rx(90)  (1, 1, -1) rotate this cube about the x-axis by 90 degrees y y x z z

3D Rotation about y-axis cos(θ) 0 sin(θ) 0 0 1 0 0 Ry (θ) = -sin(θ) 0 cos(θ) 0 0 0 0 1 note: y-coordinate does not change, and the signs of these two are different from Rx and Rz

3D Rotation about y-axis suppose you are at (0, 10, 0) and you look down towards the Origin you will see x-z plane and the new coordinates after rotation can be found as before (2D rotation about (0, 0): vertices on x-y plane) x’ = z * sin(θ) + x * cos(θ): same z’ = z * cos(θ) – x * sin(θ): different x (x’, z’) θ (x, z) z note: y-coordinate does not change, and the signs of these two are different from Rx and Rz

3D Rotation about y-axis p (x, z) = (R * cos(a), R * sin(a)) p’(x’, z’) = (R * cos(b), R* sin(b))  b = a – θ x’ = R * cos(a - θ) = R * (cos(a)cos(θ) + sin(a)sin(θ)) = R cos(a)cos(θ) + R sin(a)sin(θ)  x = Rcos(a), z = Rsin(a) = x*cos(θ) + z*sin(θ) z’ = R * sin(a – θ) = R * (sin(a)cos(θ) – cos(a)sin(θ)) = R sin(a)cos(θ) – R cos(a)sin(θ) = z*cos(θ) – x*sin(θ) = -x*sin(θ) + z*cos(θ) x (x’, z’) θ (x, z) z

3D Rotation about y-axis cos(θ) 0 sin(θ) 0 0 1 0 0 Ry (θ) = -sin(θ) 0 cos(θ) 0 0 0 0 1 note: y-coordinate does not change, and the signs of these two are different from Rx and Rz

3D Rotation about z-axis cos(θ) -sin(θ) 0 0 sin(θ) cos(θ) 0 0 Rz (θ) = 0 0 1 0 0 0 0 1 note: z-coordinate does not change

Transform Properties translation on same axes: additive translate by (2, 0, 0), then by (3, 0, 0)  translate by (5, 0, 0) rotation on same axes: additive Rx (30), then Rx (15)  Rx(45) scale on same axes: multiplicative Sx(2), then Sx(3)  Sx(6) rotations on different axis are not commutative Rx(30) then Ry (15) != Ry(15) then Rx(30)

OpenGL Transformation keeps a 4x4 floating point transformation matrix globally user’s command (rotate, translate, scale) creates a matrix which is then multiplied to the global transformation matrix glRotate{f/d}(angle, x, y, z): rotates current transformation matrix counter-clockwise by angle about the line from the Origin to (x,y,z) glRotatef(45, 0, 0, 1): rotates 45 degrees about the z-axis glRotatef(45, 0, 1, 0): rotates 45 degrees about the y-axis glRotatef(45, 1, 0, 0): rotates 45 degrees about the x-axis glTranslate{f/d}(tx, ty, tz) glScale{f/d}(sx, sy, sz)

OpenGL Transformation OpenGL transform commands are applied in reverse order for example, glScalef(3, 1, 1);  S(3,1,1) glRotatef(45, 1, 0, 0);  Rx(45) glTranslatef(10, 20, 0);  T(10,20,0) line.draw();  line is drawn translated, rotated and scaled transformations occur in reverse order to reflect matrix multiplication from right to left S(3,1,1) * Rx(45) * T(10, 20, 0) * line = (S * (R * T)) * line user can compute S * R * T and issue glMultMatrixf(matrix); multiplies matrix with the global transformation matrix

OpenGL Transformation glMatrixMode(GL_MODELVIEW); must be called first before issuing transformation commands glMatrixMode(GL_PROJECTION); must be called to set up perspective viewing  will be discussed later individual transformations are not saved by OpenGL but users are able to save these in a stack(glPushMatrix(), glPopMatrix(), glLoadIdentity())  very useful when drawing hierarchical scenes glLoadMatrixf(matrix); replaces the global transformation matrix with matrix

OpenGL Transformation argument to glLoadMatrix, glMultMatrix is an array of 16 floating point values for example, float mat[] = { 1, 0, 0, 0, // 1st row 0, 1, 0, 0, // 2nd row 0, 0, 1, 0, // 3rd row 0, 0, 0, 1 }; // 4th row lab time: copy files in hw0a to hw0b (use this directory for lab) replace glScalef, glRotatef, glTranslatef in display() method with glMultMatrixf command with our own transformation matrix