Transformation Example. Order of Transformation Matters Scale, translate Scale, translate Translate scale Translate scale Rotate, Translate Rotate, Translate.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Computer Graphics 2D & 3D 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?
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?
3-D Transformations Kurt Akeley CS248 Lecture 8 18 October 2007
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
Hierarchical Transformations Hierarchical Models Scene Graphs
Lecture 3: Transforms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
COMP 175: Computer Graphics March 10, 2015
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
2D Transformations.
Geometric transformations The Pipeline
Day 4 Transformation and 2D
Week 4 Lecture 1: Hierarchical Modeling Part 1 Based on Interactive Computer Graphics (Angel) - Chapter 10 1 Angel: Interactive Computer Graphics 5E ©
Hierarchical Modeling. Instance Transformation Start with a prototype object (a symbol) Each appearance of the object in the model is an instance – Must.
Hierarchical Modeling CS418 Computer Graphics John C. Hart.
Geometry: 2-D Transformations Course web page: Chapter #3.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Modeling with OpenGL Practice with OpenGL transformations.
OpenGL: Modeling void DrawPyramid(){ glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.1, 0.0, 0.0); glVertex3f(0.0,
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
Transformations Tutorial
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.
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.
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Rotation Around a Point. A Rotation is… A rotation is a transformation that turns a figure around a fixed point called the center of rotation. A rotation.
Transformations on the Coordinate Plane: Translations and Rotations.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Chapter 9 - Transformations. 90 degree rotation (x 1, y 1 ) 180 degree rotation (x 2, y 2 ) 270 degree rotation (x 3, y 3 )
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.
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
1 Geometric Transformations-II 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.
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
2D Imaging and Transformation
Summary of Properties of 3D Affine Transformations
OpenGL Transformations
Computer Graphics OpenGL Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Transformation and Viewing
Computer Graphics - Hierarchical Models-
Geometric Transformations
CSCE 441: Computer Graphics: Hierarchical Models
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
A movement of a figure in a plane.
Geometric Transformations
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Transformations
OpenGL Transformations
Watch out!! OpenGL post-multiplies each new transformation matrix
Dilations NOT an isometry.
Geometric Transformations
OpenGL Transformations
Rotation Around a Point
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

Transformation Example

Order of Transformation Matters Scale, translate Scale, translate Translate scale Translate scale Rotate, Translate Rotate, Translate Translate, Rotate Translate, Rotate

An Example Line (A,B), A=(0,0,0) B=(1,0,0) Line (A,B), A=(0,0,0) B=(1,0,0) S=(2,2,1) S=(2,2,1) T=(2,3,0) T=(2,3,0) First Scale, then Translate First Scale, then Translate A’=(0,0,0) B’=(2,0,0); A’’=(2,3,0); B’’=(4,3,0) A’=(0,0,0) B’=(2,0,0); A’’=(2,3,0); B’’=(4,3,0) First Translate, then Scale First Translate, then Scale A’=(2,3,0) B’=(3,3,0); A’’=(4,6,0); B’’=(6,6,0) A’=(2,3,0) B’=(3,3,0); A’’=(4,6,0); B’’=(6,6,0)

A house example

Transformation helps Assume drawHouse( ) draws house #1 Assume drawHouse( ) draws house #1 How can we draw house #2 How can we draw house #2 Rotate first or translate first? Rotate first or translate first? Rotate first Rotate first How can we draw both? How can we draw both? DrawHouse( ); DrawHouse( ); glTranslate.. glTranslate.. glRotate… glRotate… DrawHouse( ); DrawHouse( );

More Houses? House 1 House 1 House1 M2 --  House2 House1 M2 --  House2 House1 M3 --  House3 House1 M3 --  House3

The Matrix Stack glPushMatrix( ) glPushMatrix( ) glPopMatrix( ) glPopMatrix( )

drawHouse( ); drawHouse( ); glPushMatrix( ); //remember the matrix for //drawing house 1 glPushMatrix( ); //remember the matrix for //drawing house 1 …//Apply m2; …//Apply m2; drawHouse( ); //draw house2 drawHouse( ); //draw house2 glPopMatrix( ); //pop the matrix for house 1 glPopMatrix( ); //pop the matrix for house 1 …//Apply m3; …//Apply m3; drawHouse( ); //draw house 3; drawHouse( ); //draw house 3;

for(int i = 0; i < 12; i++){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(320,240,0); glRotated(i*30, 0,0,1); glTranslated(0, radius, 0); drawPolyLineFile("dino.dat1"); } Correct?

This is the result

Looking at the first two //first //first glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadIdentity(); glTranslated(320,240,0); glTranslated(320,240,0); glTranslated(radius,0, 0); glTranslated(radius,0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1"); //second //second glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadIdentity(); glTranslated(320,240,0); glTranslated(320,240,0); glRotated(36,0,0,1); glRotated(36,0,0,1); glTranslated(radius, 0, 0); glTranslated(radius, 0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1");

The Ring for(int i = 0; i < 12; i++){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(320,240,0); glRotated(i*30, 0,0,1); glTranslated(0, radius, 0); drawPolyLineFile("dino.dat1"); }

The Ring Again: Make Use of Matrix Stack //method 2 //method 2 //use push and pop //use push and popglMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadIdentity(); for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++){ glPushMatrix(); glPushMatrix(); glTranslated(320,240,0); glTranslated(320,240,0); glRotated(i*36, 0,0,1); glRotated(i*36, 0,0,1); glTranslated(0, radius, 0); glTranslated(0, radius, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1"); glPopMatrix(); glPopMatrix(); }

Transformations can be thought of as a change in coordinate system if we specify a sequence of transformations always in terms of a fixed (world) coordinate system, they should be ordered from right-to- left. if we specify a sequence of transformations always in terms of a fixed (world) coordinate system, they should be ordered from right-to- left. But if we think of all transformations in terms of a local (object) coordinate system, they should be ordered from left-to-right. But if we think of all transformations in terms of a local (object) coordinate system, they should be ordered from left-to-right.

Relative Transformation glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadIdentity(); glTranslated(320,240,0); glTranslated(320,240,0); glTranslated(radius,0, 0); glTranslated(radius,0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1"); //from first to second, read it with coordinate transformation glTranslated(-radius,0, 0); glTranslated(-radius,0, 0); glRotated(36, 0,0,1); glRotated(36, 0,0,1); glTranslated(radius,0, 0); glTranslated(radius,0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1");

The Ring Again: Understand it with Coordinate Transformation //method 3, use relative transformation //method 3, use relative transformation glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadIdentity(); glTranslated(320,240,0); glTranslated(320,240,0); glTranslated(radius,0, 0); glTranslated(radius,0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1"); //draw the rest 9 //draw the rest 9 for(int i=0; i < 9; i++) for(int i=0; i < 9; i++) { { glTranslated(-radius,0, 0); glTranslated(-radius,0, 0); glRotated(36, 0,0,1); glRotated(36, 0,0,1); glTranslated(radius,0, 0); glTranslated(radius,0, 0); drawPolyLineFile("dino.dat1"); drawPolyLineFile("dino.dat1"); } }

How to get this with both translation and rotation?

Using Transformation to Draw

for (int count = 0; count <6; count++)…..//draw a snow flake { flakeMotif(); glScalef(1.0,-1.0,1.0);.//reflection, using scale (1,-1,1) flakeMotif(); glScalef(1,-1,1);.// glScalef(1.0,-1.0,1.0);.//reflect back glRotate(60,0,0,1); } Draw One Snow Flake

Snow Flakes While (!bored) { drawSnowFlakes(); ….//moving to a new spot }

Polyspirals

Pseudocode for( ) { forward(length,1); // draw a line in the current direction turn(angle); // turn through angle degrees length += increment; // increment the line length }