Transformations in OpenGL

Slides:



Advertisements
Similar presentations
Computer Graphics - Transformation -
Advertisements

Figures based on regular polygons (lab3)
Computer Graphics 2D & 3D Transformation.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Based on slides created by Edward Angel
CS 4731: Computer Graphics Lecture 7: Introduction to Transforms, 2D transforms Emmanuel Agu.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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.
Chapter 3: Geometric Objects and Transformations Part 2
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
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
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformations.
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
University of New Mexico
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
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.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
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.
CSCE 441 Computer Graphics: 2D Transformations
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Viewing.
OpenGL Transformations
Transformations Objectives
OpenGL Transformations
Computer Viewing.
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
Isaac Gang University of Mary Hardin-Baylor
OpenGL Transformations
Computer Graphics OpenGL Transformations
Introduction to Computer Graphics with WebGL
CSC461: Lecture 19 Computer Viewing
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
Introduction to Computer Graphics with WebGL
Geometric Transformations
Geometric Transformations
Lecture 6 and 7 Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations Ed Angel
Geometric Objects and Transformations (II)
University of New Mexico
Advanced Graphics Algorithms Ying Zhu Georgia State University
Transformations Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
OpenGL Transformations
Geometric Transformations
OpenGL Transformations
Geometry Objects and Transformation
Chapter 4: Geometry.
Geometry Objects and Transformation
Presentation transcript:

Transformations in OpenGL Angel 4.10 Angel: Interactive Computer Graphics5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Objectives Learn how to carry out transformations in OpenGL Rotation Translation Scaling Introduce OpenGL matrix modes Model-view Projection Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 CTM in OpenGL OpenGL has a model-view and a projection matrix in the pipeline which are concatenated together to form the CTM Can manipulate each by first setting the correct matrix mode Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Rotation, Translation, Scaling Load an identity matrix: glLoadIdentity() Multiply on right: glRotatef(theta, vx, vy, vz) theta in degrees, (vx, vy, vz) define axis of rotation glTranslatef(dx, dy, dz) glScalef( sx, sy, sz) Each has a float (f) and double (d) format (glScaled) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Example 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 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); Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Arbitrary 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 glLoadMatrixf(m) glMultMatrixf(m) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Matrix Stacks In many situations we want to save transformation matrices for use later Traversing hierarchical data structures (Chapter 10) Avoiding state changes when executing display lists OpenGL maintains stacks for each type of matrix Access present type (as set by glMatrixMode) by glPushMatrix() glPopMatrix() Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Reading Back Matrices Can also access matrices (and other parts of the state) by query functions For matrices, we use as glGetIntegerv glGetFloatv glGetBooleanv glGetDoublev glIsEnabled double m[16]; glGetFloatv(GL_MODELVIEW, m); Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Using Transformations Example: use idle function to rotate a cube and mouse function to change direction of rotation Start with a program that draws a cube (colorcube.c) in a standard way Centered at origin Sides aligned with axes We did this previously Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Using the Model-view Matrix In OpenGL the model-view matrix is used to Position the camera Can be done by rotations and translations but is often easier to use gluLookAt Build models of objects The projection matrix is used to define the view volume and to select a camera lens Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Model-view and Projection Matrices Although both are manipulated by the same functions, we have to be careful because incremental changes are always made by postmultiplication For example, rotating model-view and projection matrices by the same matrix are not equivalent operations. Postmultiplication of the model-view matrix is equivalent to premultiplication of the projection matrix Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009