Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.

Slides:



Advertisements
Similar presentations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Advertisements

Computer Graphics Lecture 4 Geometry & Transformations.
University of North Carolina at Greensboro
Geometric Transformations
1 Computer Graphics Chapter 6 2D Transformations.
CMPE 466 COMPUTER GRAPHICS
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
Transformations II Week 2, Wed Jan 17
University of North Carolina at Greensboro
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
Modeling Objects by Polygonal Approximations
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
Hierarchical Transformations Hierarchical Models Scene Graphs
COMP 175: Computer Graphics March 10, 2015
C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.
Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformations Dr. Amy Zhang.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Transformation & Projection Feng Yu Proseminar Computer Graphics :
Lecture Notes: Computer Graphics.
Geometric Transforms Changing coordinate systems.
Geometric Transformations Jehee Lee Seoul National University.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric Transformations
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Geometric Transformations Hearn & Baker Chapter 5 Some slides are taken from Robert Thomsons notes.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Transformations of objects
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.
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.
Computer Graphics I, Fall 2010 Transformations.
1 Geometric Transformations Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Computer Graphics 2D Transformations
Geometric Transformations Hearn & Baker Chapter 5
Computer Graphics Transformations.
Summary of Properties of 3D Affine Transformations
Computer Graphics Transformations.
Lecture 2 Transformations
CSCE 441: Computer Graphics: Hierarchical Models
Unit-5 Geometric Objects and Transformations-II
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Objects and Transformations (II)
TWO DIMENSIONAL TRANSFORMATION
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

Transformations

Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs and hierarchical composition of transformations Get familiar with transformations in OpenGL and DirectX

Transformations Transformations change 2D or 3D points and vectors, or change coordinate systems. An object transformation alters the coordinates of each point on the object according to the same rule, leaving the underlying coordinate system fixed. A coordinate transformation defines a new coordinate system in terms of the old one, then represents all of the object’s points in this new system. Object transformations are easier to understand, so we will do them first.

Transformations (2) A (2D or 3D) transformation T( ) alters each point P into a new point Q using a specific formula or algorithm: Q= T(P).

Transformations (3) An arbitrary point P in the plane is mapped to Q. Q is the image of P under the mapping T. We transform an object by transforming each of its points, using the same function T() for each point. The image of line L under T, for instance, consists of the images of all the individual points of L.

Transformations (4) Most mappings of interest are continuous, so the image of a straight line is still a connected curve of some shape, although it’s not necessarily a straight line. Affine transformations, however, do preserve lines: the image under T of a straight line is also a straight line.

Geometric Effects of Affine Transformations Combinations of four elementary transformations: (a) a translation, (b) a scaling, (c) a rotation, and (d) a shear (all shown below).

2D Translations P P’

2D Scaling from the origin P P’

2D Rotation about the origin y x r r P’(x’,y’) P(x,y)  Recall the right-hand rule!

2D Rotation about the origin y x r r P’(x’,y’) P(x,y)   y x

2D Rotation about the origin. Substituting for r : Given us: After all, these are just High-schools formulas!

2D Rotation about the origin. Rewriting in matrix form gives us :

Shear: Off Diagonal Elements

Example 1 S

S

T(S)

Example 2 S

S

T(S)

Summary Shear in x: Shear in y:

Sample Points: unit inverses

Geometric View of Shear in x

Another Geometric View of Shear in x 24

Another Geometric View of Shear in x 25

Geometric View of Shear in y

Another Geometric View of Shear in y h h 27

Another Geometric View of Shear in y 28

Transformations Translation. P=T + P Scale P=S  P Rotation P=R  P Shear P=H  P We would like all transformations to be multiplications so we can concatenate them  express points in homogenous coordinates.

Homogeneous coordinates Add an extra coordinate, W, to a point. P(x,y,W). Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. (2,5,3) and (4,10,6) represent the same point. At least one component must be non-zero  (0,0,0) is not allowed. If W  0, divide by it to get Cartesian coordinates of point (x/W,y/W,1). If W=0, point is said to be at infinity. P(x,y,0) can be interpreted as the vector v(x, y) Both points and vectors are represented by the same set of underlying objects

Homogeneous coordinates If we represent (x,y,W) in 3-space, all triples representing the same point describe a line passing through the origin. If we homogenize the point, we get a point of form (x,y,1) homogenised points form a plane at W=1. P X Y W W=1 plane

Translations in homogenised coordinates Transformation matrices for 2D translation are now 3x3.

Concatenation We perform 2 translations on the same point:

Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition. This single matrix is called the Coordinate Transformation Matrix or CTM.

Homogeneous form of scale Recall the (x,y) form of Scale : In homogeneous coordinates :

Concatenation of scales.

Homogeneous form of rotation

Composition of Transformations Suppose we want to rotate around an arbitrary point P Idea: Compose simple transformations 1. Translate P to origin 2. Rotate around origin 3. Translate origin back to P The order is very important!

Order!

3D Transformations Use homogeneous coordinates, just as in 2D case. Transformations are now 4x4 matrices. We will use a right-handed (world) coordinate system - ( z out of page ). z (out of page) y x Note: Convenient to think of display as Being left-handed !! ( z into the screen )

More on Homogeneous Coordinates To: if the object is a vector, add a 0 as the 4 th coordinate; if it is a point, add a 1. From: If the 4 th coordinate is zero, then simply remove it. If it is not, then divide the other coordinate by it and remove it. OpenGL uses 4D homogeneous coordinates for all its vertices. If you send it a 3-tuple in the form (x, y, z), it converts it immediately to (x, y, z, 1). If you send it a 2D point (x, y), it first appends a 0 for the z- component and then a 1, to form (x, y, 0, 1). All computations are done within OpenGL in 4D homogeneous coordinates.

Combinations Linear combinations of vectors and points: The difference of 2 points is a vector: the fourth component is 1 – 1 = 0 The sum of a point and a vector is a point: the fourth component is = 1 The sum of 2 vectors is a vector: = 0 A vector multiplied by a scalar is still a vector Linear combinations of vectors are vectors

Translation in 3D Simple extension to the 3D case: In OpenGL: glMatrixMode(GL_ModelView); glTranslatef(dx, dy, dz); In DirectX: device.Transform.World = Matrix.Translation(dx, dy, dz)

Scale in 3D Simple extension to the 3D case: In OpenGL: glMatrixMode(GL_ModelView); glScalef(Sx, Sy, Sz); In DirectX: device.Transform.World = Matrix.Scaling(Sx, Sy, Sz)

Rotation in 3D Need to specify which axis the rotation is about. z-axis rotation is the same as the 2D case. In OpenGL: glMatrixMode(GL_ModelView); glRotatef(theta, 0.0f, 0.0f, 1.0f); In DirectX: device.Transform.World = Matrix.RotationZ(theta)

Rotation in 3D For rotation about the x and y axes: In OpenGL: glMatrixMode(GL_ModelView); glRotatef(theta, 1.0f, 0.0f, 0.0f); //gRotatef(theta,0.0f,1.0f,0.0f) (about y) In DirectX: device.Transform.World = Matrix.RotationZ(theta); //Matrix.RotationY(theta) (about y)

3D Shear in x -direction In OpenGL: glMatrixMode(GL_ModelView); glMultMatrixf(Shx(a)); In DirectX: device.Transform.World = Matrix. Multiply(Matrix.Identity,Shx(a));

3D Shear in x -direction

Transformations of coordinate systems Alternate view: when we apply a transformation, we’re not changing the coordinates of a point within a coordinate system. Instead, we’re changing the coordinate system itself All the transformations are performed relative to the current coordinate frame origin and axes; OpenGL post-multiplies each new transformation matrix

Successive Transformations C1 C2 C3 M1 M2 Given P (a3,b3) in C3 What is P’s coordinates in C1? 1)Get P’s coordinates in C2 P_c2 = M2 x P 2)Get P_c2’s coordinates in C1 P_c1 = M1 x P_c2 P_c1 = M1 x M2 x P the answer!! C1 M1 C2 M2 (a3,b3) C3 a3 b3

Successive Transformations (2) The sequence translate cube translate cube will draw two cubes with x centres 1.5 and 10.0 respectively. We could create the same image with the sequence save state translate cube restore state save state translate cube restore state Here both cubes have an absolute translation and the order in which the two cubes are drawn does not matter.

Hierarchical composition using Push and Pop glPushMatrix(); Save the state. Push a copy of the CTM onto the stack. The CTM itself is unchanged. glPopMatrix () ; Restore the state, as it was at the last Push. Overwrite the CTM with the matrix at the top of the stack. glLoadIdentity (); Overwrite the CTM with the identity matrix.

Scene graphs 3D scenes are often stored in a directed acyclic graph (DAG) called a scene graph Open Scene Graph (used in the Cave) Sun’s Java3D™ VRML Common scene graph format: objects (cubes, spheres, cones,...) stored as leaf nodes attributes (color, texture map, etc.), and transformations are also nodes in a scene graph Very helpful in designing complex objects Allows us to know when to push and when to pop Allows to know when to use display lists/index buffers Allows us to animate different parts of a complex object

Scene graphs ROBOT upper bodylower body headtrunk arm stanchionbase 2. We transform them 3. To make sub-groups 4. Transform subgroups 5. To get final scene 1. Leaves of tree are standard size object primitives

Hierarchical transformation and scene graphs Example: - for o1, CT = m1 - for o2, CT = m2* m3 - for o3, CT = m2* m4* m5 - for a vertex v in o3, position in the world (root) coordinate system is: CT.v = (m2*m4*m5)v m1m2 m3 m4 o1 o2 o3 g1 g2 g: group nodes m: matrices of transform nodes o: object nodes

Transformations in OpenGL: Summary Important: OpenGL maintains a number of matrices: ModelView, Projection, and Texture. We switch between them with the glMatrixMode() routine The most recent call to glMatrixMode() selects OpenGL’s current transformation (CT) matrix Transformations are applied by post-multiplying CT by the desired transformation: CT = CT · M

Practice session Use glRotate and Matrix.RotationAxis to rotate around any line Use scence graphs and hierarchical composition of transformations to build a nice 3D car and nice 3D airplane