The Modelview Stack Lecture 9 Wed, Sep 12, 2007. The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

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?
University of North Carolina at Greensboro
CMPE 466 COMPUTER GRAPHICS
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations III Week.
Viewing and Transformation
1 Lecture 7 Geometrical Transformations: 2D transformations 3D transformations Matrix representation OpenGL functions.
6/15/2015©Zachary Wartell 1 OpenGL Transforms with Object-Oriented Framework Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Transformations III Week.
#3: Hierarchical Transforms. Geometric Calculations CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006.
OpenGL (II). How to Draw a 3-D object on Screen?
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
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 Jehee Lee Seoul National University.
Geometric transformations The Pipeline
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.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
Transformations Tutorial
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.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Chap 3 Viewing and Transformation
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.
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 Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
Transformation Example. Order of Transformation Matters Scale, translate Scale, translate Translate scale Translate scale Rotate, Translate Rotate, Translate.
Computer Graphics Lecture 42 Viewing Using OpenGL II Taqdees A. Siddiqi
Transformations Introduction to Computer Graphics and Animation
Summary of Properties of 3D Affine Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Transformation and Viewing
Computer Graphics - Hierarchical Models-
Hierarchical and Object-Oriented Graphics
Geometric Transformations
CSCE 441: Computer Graphics: Hierarchical Models
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Geometric Transformations
Hierarchical and Object-Oriented Graphics
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Transformations
Geometric Objects and Transformations (II)
Advanced Graphics Algorithms Ying Zhu Georgia State University
Transformations III Week 3, Mon Jan 21
Transformations IV Week 3, Wed Jan 23
Geometric Transformations
Dr. Chih-Kuo Yeh 葉智國 Computer Graphics Dr. Chih-Kuo Yeh 葉智國
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

The Modelview Stack Lecture 9 Wed, Sep 12, 2007

The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current matrix. The function glPushMatrix() will push a copy of the current matrix onto the stack. The function glPopMatrix() will pop the top matrix off the stack.

The Modelview Stack Pushing and popping are used to “remember” previous transformations. The basic pattern is Push the current matrix onto the stack (to remember it). Perform a series of geometric transformations and draw an object. Pop the current matrix off the stack, thereby restoring the former “current matrix.”

Manipulating the Stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); drawCylinder(); // Along pos. z-axis glPushMatrix(); glRotatef(90.0, 0.0, 1.0, 0.0); drawCylinder(); glTranslatef(0.0, 0.0, 2.0); drawCylinder(); glPopMatrix(); glRotatef(90.0, 1.0, 0.0, 0.0); drawCylinder();

Manipulating the Stack Modelview StackActionDrawing ILoad identity IDraw cylinderAlong z-axis, 0 to 1 I, IPush matrix I, R y Rotate I, R y Draw cylinderAlong x-axis, 0 to 1 I, R y TTranslate I, R y TDraw cylinderAlong x-axis, 2 to 3 IPop matrix R x Rotate R x Draw cylinderAlong y-axis, 0 to -1

Manipulating the Stack The identity matrix is placed on the stack. The first cylinder is drawn along the positive z-axis. The current matrix is pushed onto the stack. The next cylinder is drawn along positive z- axis and then rotated into the positive x-axis.

Manipulating the Stack The third cylinder is drawn along the positive z-axis, shifted forward along the z-axis, then rotated into the x-axis. The current matrix is popped off the stack, The fourth cylinder is drawn along the positive z-axis and the rotated into the negative y-axis.

Using the Stack to Draw a Person Our person:

The Basic Components We see that the person is constructed of rectangles and ovals (including circles). Therefore, we will write two basic functions: drawCircle() – draws unit circle at the origin. drawSquare() – draws unit square at the origin in the first quadrant.

Drawing the Hand The hand is a circle, 6 inches in diameter.

Drawing the Hand void drawHand() { glPushMatrix(); glScalef(0.25, 0.25, 0.0); drawCircle(); glPopMatrix(); return; }

Drawing the Arm The arm is a rectangle 2 feet, 6 inches long and 3 inches wide, with the hand attached at the end.

Drawing the Arm void drawArm() { glPushMatrix(); glScalef(0.25, 2.5, 1.0); drawSquare(); glPopMatrix(); glTranslatef(0.25, 0.0, 0.0); drawHand(); glPopMatrix(); return; }

Drawing the Foot The foot is an oval, one foot long and 6 inches high.

Drawing the Foot void drawFoot() { glPushMatrix(); glScalef(0.5, 0.25, 0.0); drawCircle(); glPopMatrix(); return; }

Drawing the Leg The leg is a rectangle 2 feet, 6 inches long and 6 inches wide, with the foot attached at the end.

Drawing the Leg void drawLeg() { glPushMatrix(); glScalef(0.5, 2.5, 1.0); drawSquare(); glPopMatrix(); glTranslatef(0.5, 0.0, 0.0); drawFoot(); glPopMatrix(); return; }

Drawing the Head The head is a circle of diameter 1 foot.

Drawing the Head The head is a circle of diameter 1 foot. void drawHead() { glPushMatrix(); glScalef(0.5, 0.5, 1.0); drawCircle(); glPopMatrix(); return; }

Draw the Torso The torso is 2.5 feet high and 1.5 feet wide.

Draw the Torso void drawTorso() { glPushMatrix(); glScalef(1.25, 2.5, 1.0); drawSquare(); glPopMatrix(); return; }

Draw the Person

void drawPerson() { glPushMatrix(); glTranslatef(0.0, 2.75, 0.0); glPushMatrix(); glTranslatef(-0.625, 0.0, 0.0); drawTorso(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 3.0, 0.0); drawHead(); glPopMatrix(); :

Draw the Person : glPushMatrix(); glTranslatef(0.625, 2.5, 0.0); glRotatef(20.0, 0.0, 0.0, 1.0); glTranslatef(-0.25, -2.5, 0.0); drawArm(); // Right arm glPopMatrix(); glPushMatrix(); glScalef(-1.0, 1.0, 1.0); glTranslatef(0.625, 2.5, 0.0); glRotatef(20.0, 0.0, 0.0, 1.0); glTranslatef(-0.25, -2.5, 0.0); drawArm(); // Left arm glPopMatrix(); :

Draw the Person : glPushMatrix(); glTranslatef(0.125, 0.25, 0.0); drawLeg(); // Right leg glPopMatrix(); glPushMatrix(); glScalef(-1.0, 1.0, 1.0); glTranslatef(0.125, 0.25, 0.0); drawLeg(); // Left leg glPopMatrix(); return; }

Draw a Person Read Run

Drawing a Crowd of People Read Run

Example – An Orrery Suppose we want to draw the sun at the origin, Jupiter orbiting the sun, and four of Jupiter’s moons orbiting Jupiter. Procedure Draw the sun. Rotate by Jupiter’s angle. Translate by Jupiter’s radius. Draw Jupiter.

Example – An Orrery For each of Jupiter’s moons, Push the modelview matrix. Rotate through the moon’s angle. Translate by the moon’s radius. Draw the moon. Pop the modelview matrix.

Example – An Orrery Read Run

Specifying a Transformation Matrix OpenGL allows the programmer to specify his own transformation matrix and multiply it by the current transformation.

Specifying a Transformation Matrix Create a 4  4 matrix as a 16-member one- dimensional array of floats or doubles, in row-major order. Use glLoadMatrix*() to make it the current transformation. Use glMultMatrix*() to multiply the current transformation by it.

Example: Creating a Shear Suppose we want to create the shear transformation in 2D that sends (0, 0) to (0, 0), (1, 0) to (1, 0), (0, 1) to (1, 1), (1, 1) to (2, 1). In general, it sends (x, y) to (x + y, y).

Example: Creating a Shear The transformation matrix is

Example: Creating a Shear The following code will perform this transformation. // Store in column-major order float mat[16] = {1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; glMultMatrix(mat);

Shearing the People Read Run