1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.

Slides:



Advertisements
Similar presentations
Computer Graphics - Transformation -
Advertisements

Computer Graphics 2D & 3D Transformation.
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?
1 Lecture 7 Geometrical Transformations: 2D transformations 3D transformations Matrix representation OpenGL functions.
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
Modeling Objects by Polygonal Approximations
Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.
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.
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
Fundamentals of Computer Graphics Part 4
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
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformations.
Geometric Transformations Jehee Lee Seoul National University.
Geometric transformations The Pipeline
Transformations With OpenGL Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
PPT&Programs&Labcourse 1.
Computer Graphics I, Fall 2010 OpenGL Transformations.
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.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
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.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
1 Geometric Transformations Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
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.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
OpenGL Transformations
Transformations Introduction to Computer Graphics and Animation
OpenGL Transformations
2D Geometric Transformations
OpenGL Transformations
Computer Graphics OpenGL Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Introduction to Computer Graphics with WebGL
OpenGL Transformations
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Geometric Transformations
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Geometric Transformations
Geometric Transformations
Lecture 6 and 7 Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Objects and Transformations (II)
Advanced Graphics Algorithms Ying Zhu Georgia State University
Transformations III Week 3, Mon Jan 21
OpenGL Transformations
Geometric Transformations
Lecture #6 2D Geometric Transformations
OpenGL Transformations
Presentation transcript:

1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon

In OpenGL matrices are part of the state Multiple types  Model-View (GL_MODELVIEW)  Projection (GL_PROJECTION)  Texture (GL_TEXTURE) (ignore for now)  Color(GL_COLOR) (ignore for now) Single set of functions for manipulation Select which to be manipulated by  glMatrixMode(GL_MODELVIEW);  glMatrixMode(GL_PROJECTION); OpenGL Matrices

Can load and multiply by matrices defined in the application program The matrix m is a one dimension array of 16 elements which are the components of the desired 4 x 4 matrix stored by columns In glMultMatrixf, m multiplies the existing matrix on the right Arbitrary Matrices glLoadMatrixf(m) glMultMatrixf(m)

glRotatef(theta, vx, vy, vz) Rotation, Translation, Scaling glTranslatef(dx, dy, dz) glScalef(sx, sy, sz) glLoadIdentity()  Load an identity matrix:  Multiply on right: theta in degrees, ( vx, vy, vz ) define axis of rotation  Each has a float (f) and double (d) format (glScaled)

See Lab6 Lab7 Example

Simple square void draw_square() { glBegin( GL_POLYGON ); glColor3f( 1, 1, 0 ); glVertex2f( -0.5, -0.5 ); glColor3f( 0, 1, 0 ); glVertex2f( -0.5, 0.5 ); glColor3f( 0, 0, 1.0 ); glVertex2f( 0.5, 0.5 ); glColor3f( 1, 1, 1 ); glVertex2f( 0.5, -0.5 ); glEnd(); }

Rotation about z axis by 30 degrees with a fixed point of (1.0, 2.0, 3.0) Remember that last matrix specified in the program is the first applied Example glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(1.0, 2.0, 3.0); glRotatef(30.0, 0.0, 0.0, 1.0); glTranslatef(-1.0, -2.0, -3.0);

Example These two fragment codes produce the same output? glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(100.0,50.0, 0.0); square(); glLoadIdentity(); glTranslatef(50.0,100.0, 0.0); square(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(100.0,50.0, 0.0); square(); glTranslatef(50.0,100.0, 0.0); square();

OpenGL Matrix Stacks (2) glPushMatrix()  copies the top of stack  this makes the top two items in the stack identical  The top item can now be altered further with addition call transformation functions glPopMatrix()  The top item is popped off the stack and discarded

glPushMatrix(void) - Pushes all matrices in the current stack down one level. glPopMatrix(void) - Pops the top matrix off the current stack, losing the topmost matrix! (The current stack is determined by glMatrixMode). Matrix Stacks M5 M4 M3 M2 M1 M5 M4 M3 M2 M1 Pop Push M4 M3 M2 M1 M4 M3 M2 M1 Current matrix level Current matrix level

Example glMatrixMode(GL_MODELVIEW) glColor3f(0.0, 0.0, 1.0); glRecti(50, 100, 200, 150)//Display blue rectangle glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0)//Set translation parameters glRecti(50, 100, 200, 150)//Display red, translated rectangle glLoadIdentity();//Reset current matrix to identity glRotatef(90.0, 0.0, 0.0, 1.0);//Set 90-deg. Rotation about z axis glRecti(50, 100, 200, 150)//Display red, rotated rectangle glLoadIdentity();//Reset current matrix to identity glScalef(-0.5, 1.0, 1.0);//Set scale-reflection parameters glRecti(50, 100, 200, 150)//Display red, transformed rectangle

Example and Draw the stack glMatrixMode(GL_MODELVIEW) glColor3f(0.0, 0.0, 1.0); glRecti(50, 100, 200, 150)//Display blue rectangle glPushMatrix();//Make copy of identity (top) matrix glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0)//Set translation parameters glRecti(50, 100, 200, 150)//Display red, translated rectangle glPopMatrix();//Throw away the translation matrix glPushMatrix();//Make copy of identity (top) matrix glRotatef(90.0, 0.0, 0.0, 1.0);//Set 90-deg. Rotation about z axis glRecti(50, 100, 200, 150)//Display red, rotated rectangle glPopMatrix();//Throw away the rotation matrix glScalef(-0.5, 1.0, 1.0);//Set scale-reflection parameters glRecti(50, 100, 200, 150)//Display red, transformed rectangle

OpenGL supports two stacks of matrices –Modelview matrix stack (32 4x4 matrices) –Projection matrix stack (2 4x4 matrices) These stacks are useful for constructing hierarchical models. For example a car made of its body and the four wheels: Rotate wheels + Rotate body Matrix Stacks

Example code: void drawCar() { glMatrixMode(GL_MODELVIEW) ; glTranslatef(x,y,z) ; /*/ glRotatef(car_ang, 0, 1, 0) ; /*/ draw_car_body() ; glPushMatrix() ; glTranslate(-1,0,1) ; glRotatef(wheels_ang, 0, 1, 0) ; draw_car_wheel() ; glPopMatrix() ; glPushMatrix() ; glTranslate(1,0,1) ; glRotatef(wheels_ang, 0, 1, 0) ; draw_car_wheel() ; glPopMatrix() ; } First we move and rotate the car (body + wheels) - as it is the top level in the hierarchy. Next we push the stack - and therefore store a copy. Then we draw the right and left wheels in their appropriate position and orientation. Note that on each wheel the transformation /*/ will operate. The last pop will retrieve the matrix containing only the /*/ transformations. Matrix Stacks