Transformations Tutorial

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.
Hierarchical Modeling I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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.
Hierarchical Modeling II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is.
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?
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
Hierarchical Transformations and Models CSE 3541 Matt Boggus.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology 3D Engines and Scene Graphs Spring 2012.
Hierarchical Transformations Hierarchical Models Scene Graphs
CS 4731: Computer Graphics Lecture 9: Introduction to 3D Modeling Emmanuel Agu.
Hierarchy, Modeling, and Scene Graphs Angel: Chapter 10 OpenGL Programming and Reference Guides, other sources. ppt from Angel, AW, etc. CSCI 6360/4360.
COMP 175: Computer Graphics March 10, 2015
Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9:
Chapter 10 Bresenham’s Algorithm Data Structures and Graphics or Working with Models.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Geometric transformations The Pipeline
Transforms Hierarchical Modeling Scene Graphs Using hierarchical modeling techniques in 3D software design Transforms Local basis Matrix math review Matrices.
Demetriou/Loizidou – ACSC330 – Chapter 9 Hierarchical and Object-Oriented Modeling Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science.
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.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 Computer Graphics Hierarchy I.
CS559: Computer Graphics Lecture 15: Hierarchical Modeling and Shading Li Zhang Spring 2008.
Hierarchical Modeling CS418 Computer Graphics John C. Hart.
Modeling with OpenGL Practice with OpenGL transformations.
111/16/ :14 UML Instance Transformation x y z x y z x y z x y z SRT Model Coordinates.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Hierarchical and Object-Oriented Graphics Construct complex models from a set of simple geometric objects Extend the use of transformations to include.
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.
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.
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
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
Hierarchical Modeling. 2 Objectives Build a tree-structured model of a humanoid figure. Examine various traversal strategies. Build a generalized tree-model.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 13: Hierarchical Modeling and Curves Li Zhang Spring 2010.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Computer Graphics I, Fall 2008 Hierarchical Modeling I.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
OpenGL LAB III.
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.
Hierarchical Models Chapter 9.
Transformations Introduction to Computer Graphics and Animation
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
Modeling and Hierarchy
Hierarchical Modeling II
Computer Graphics - Hierarchical Models-
Modeling and Hierarchy
Hierarchical and Object-Oriented Graphics
Introduction to Computer Graphics with WebGL
CSCE 441: Computer Graphics: Hierarchical Models
Unit-5 Geometric Objects and Transformations-II
Hierarchical and Object-Oriented Graphics
Hierarchical Modeling I
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Hierarchical Modeling & Constructive Solid Geometry
Transformations III Week 3, Mon Jan 21
Dr. Chih-Kuo Yeh 葉智國 Computer Graphics Dr. Chih-Kuo Yeh 葉智國
Hierarchical Modeling
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

Transformations Tutorial

Homogeneous Coordinates OpenGL works in 4 dimensions called Homogeneous Coordinates A 3D point is represented as (x, y, z, 1) and a 2D point is represended as (x, y, 0, 1) (no z value!) With this representation all the matrices we use for modeling, viewing and projection are represented by 4x4 matrices that act on homogeneous coordinates When we set up an OpenGL transformation such as a rotation/translation we are setting up a 4x4 matrix within OpenGL

Modeling with Transformations Instancing If we start with a collection of common objects such as spheres, cubes etc, we can build other objects by applying affine transformations to them. Base objects are sometimes called symbols and each occurance of one is called an instance The matrix that brings the object into the model with the desired position, size and orientation is called the instance transformation

Example glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); glRotatef(...); glScalef(...); glutSolidCylinder(...)’

Hierarchical Models In many applications, the parts of a model depend on one another If we move one part, it causes other parts to move Parts of such models can be arranged as a tree data structure e.g. a simple robot arm

Hierarchical Models We would like to represent such models using transformations The instance transformations are not quite right because they place each symbol in the scene independently of the others. However, if we recall that OpenGL transformations are applied to the EXISTING MATRIX, we can observe that each transformation represents a relative change from one scaling, position and orientation to another.

Example:Robot Arm Use a cylinder for the base, and scaled cubes for the upper and lower arms. Through 3 functions base(), lower_arm() and upper_arm() we can define the parts. The use of glPushMatrix() and glPopMatrix() lets us use the present model-view matrix to locate the entire figure while still preserving it for drawing other objects.

Example:Robot Arm Relationships The base can rotate independently. The lower arm is attached to the base and can rotate relative to it. However when the base rotates it also rotates the lower arm The upper arm can rotate w.r.t. the lower arm but is also affected by the rotation of the lower arm and the base! The lower arm is positioned on top of the base, so it must be translated up. The upper arme has to be translated up the height of the base and the length of the lower arm.

void base() { glPushMatrix(); //save where we are // draw the base /* rotate cylinder to align with y axis */ glRotatef(-90.0, 1.0, 0.0, 0.0); /* cyliner aligned with z axis, render with 5 slices for base and 5 along length */ gluCylinder(p, BASE_RADIUS, BASE_RADIUS, BASE_HEIGHT, 5, 5); glPopMatrix(); //go back up to the top! } void upper_arm() glPushMatrix(); glTranslatef(0.0, 0.5*UPPER_ARM_HEIGHT, 0.0); glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH); glutWireCube(1.0); glPopMatrix(); void lower_arm() glTranslatef(0.0, 0.5*LOWER_ARM_HEIGHT, 0.0); glScalef(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH);

Program See RobotArm.cpp for the program Examine the code which includes a small menu which can be displayed using the middle mouse button, rotations are activated using the mouse buttons.

Hierarchical Transformations The robot example didn’t require us to save anu information about the model-view matrix as we went through the display callback, because the transformations accumulated The tree structure for the robot arm is very simple, no node has more than one child Lets look at a more complex example…

Example 2: Torso This figure consists of a torso and connected part, each arm and leg has two parts, but each arm and leg depend on the location & orientation of the torso, but not each other. Lets assume we can build the individual parts head(), torso(), left_upper_arm() etc. Each part can be located w.r.t its parent by a translation and one or more rotations.

Example 2: Torso The display callback must traverse the tree i.e. visit every node, drawing the object for that node, using the correct model-view matrix A standard pre-order traversal (that travels down the left of the tree, visiting each node) is used

Example 2: Torso

First draw torso. It only has one angle associated with it that allows it to rotate about y. Then we go to the head, however note we have to come back up to the torso to get to the arms and legs Any matrix that we apply to draw the head is not required for the arms or legs. Rather than recompute the matrix that we apply to the torso node we can save it on the stack with a glPushMatrix(). We can then go to the node for the head, changing the model-view matrix as necessary to draw the head. When we come back up to the torso node, we recover the model-view matrix with a glPopMatrix() We have to come back up the the torso after dealing with the left arm so we must go to a glPushMatrix() immediately after the pop to keep a copy of the same model-view matrix

Simple! Although it appears convoluting, the rule is simple – every time we go to the left at a node with another unvisited right child we do a push; everytime we return to the node we do a pop. Note we must do a pop at the end so the total number of pushes and pops is the same

glLoadIdentity(); glColor3f(1.0, 0.0, 0.0); glRotatef(theta[0], 0.0, 1.0, 0.0); torso(); glPushMatrix(); //save current model-view matrix glTranslatef(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0); glRotatef(theta[1], 1.0, 0.0, 0.0); glRotatef(theta[2], 0.0, 1.0, 0.0); glTranslatef(0.0, -0.5*HEAD_HEIGHT, 0.0); head(); glPopMatrix(); //we have drawn the head so go back up to torso glPushMatrix(); //but now want to draw left arm so save the torso matrix again glTranslatef(-(TORSO_RADIUS+UPPER_ARM_RADIUS), 0.9*TORSO_HEIGHT, 0.0); glRotatef(theta[3], 1.0, 0.0, 0.0); left_upper_arm(); glTranslatef(0.0, UPPER_ARM_HEIGHT, 0.0); glRotatef(theta[4], 1.0, 0.0, 0.0); left_lower_arm();

glPopMatrix(); //left arm done, go back up to torso glPushMatrix(); //but we are going to draw the right arm so save the torso matrix again glTranslatef(TORSO_RADIUS+UPPER_ARM_RADIUS, 0.9*TORSO_HEIGHT, 0.0); glRotatef(theta[5], 1.0, 0.0, 0.0); right_upper_arm(); glTranslatef(0.0, UPPER_ARM_HEIGHT, 0.0); glRotatef(theta[6], 1.0, 0.0, 0.0); right_lower_arm(); glPopMatrix(); //back up to torso glPushMatrix(); //save it we are going to draw the left leg glTranslatef(-(TORSO_RADIUS+UPPER_LEG_RADIUS), 0.1*UPPER_LEG_HEIGHT, 0.0); glRotatef(theta[7], 1.0, 0.0, 0.0); left_upper_leg(); glTranslatef(0.0, UPPER_LEG_HEIGHT, 0.0); glRotatef(theta[8], 1.0, 0.0, 0.0); left_lower_leg();

glPopMatrix(); //back to torso glPushMatrix(); //save it as we are going to draw right leg glTranslatef(TORSO_RADIUS+UPPER_LEG_RADIUS, 0.1*UPPER_LEG_HEIGHT, 0.0); glRotatef(theta[9], 1.0, 0.0, 0.0); right_upper_leg(); glTranslatef(0.0, UPPER_LEG_HEIGHT, 0.0); glRotatef(theta[10], 1.0, 0.0, 0.0); right_lower_leg(); glPopMatrix(); //pop so that the total number of pushes = total number of pops! glFlush();

See the Code Figure.cpp