Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.

Slides:



Advertisements
Similar presentations
OpenGL Computer Graphics
Advertisements

Computer Graphics 2D & 3D Transformation.
OPENGL.
3D Game Programming Geometric Transformations
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?
Hierarchical Modeling I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Drawing 3D Scenes in OpenGL We want to transform objects in order to orient and position them as desired in a 3D scene. OpenGL provides the necessary functions.
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.
Graphical Objects and Scene Graphs CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
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.
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:
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.
Transforms Hierarchical Modeling Scene Graphs Using hierarchical modeling techniques in 3D software design Transforms Local basis Matrix math review Matrices.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
Transformations With OpenGL Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin.
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.
Jul 25, 2014IAT 3551 Scene Graphs.  A data structure that stores information about a graphics scene –Each node has information that structures the interpretation.
111/16/ :14 UML Instance Transformation x y z x y z x y z x y z SRT Model Coordinates.
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.
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
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.
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert.
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.
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.
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.
Introduction of OpenGL - 3D Graphic and Animation
School of Computer Science
Transformations Introduction to Computer Graphics and Animation
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
Chapter 5.6 Transformations of Objects © 2007, Prentice Hall
Summary of Properties of 3D Affine Transformations
Graphical Objects and Scene Graphs
Reference1. [OpenGL course slides by Rasmus Stenholt]
Transformation and Viewing
Computer Graphics - Hierarchical Models-
Hierarchical and Object-Oriented Graphics
CSCE 441: Computer Graphics: Hierarchical Models
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Hierarchical and Object-Oriented Graphics
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Objects and Transformations (II)
Computer Graphics 3Practical Lesson
Transformations III Week 3, Mon Jan 21
Transformations IV Week 3, Wed Jan 23
Dr. Chih-Kuo Yeh 葉智國 Computer Graphics Dr. Chih-Kuo Yeh 葉智國
Hierarchical Modeling
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot

GLU/GLUT Objects Each glu/glut object has its default size, position, and orientation You need to perform modeling transformation to make it right for you glutWireCube(1.0) - ‘wire’ means wire frame Put a 1x1x1 cube with its center at world (0,0,0) To create a 2 x 0.1 x 2 table top - need to call glScalef(2, 0.1, 2) before you call glutWireCube(1.0)

gluCylinder() Three steps to create a cylinder Base y x z 1. Create a GLU quadric object GLUquadricObj *p = gluNewQuadric(); 2. Set to wire frame mode gluQuadricDrawStyle(GLU__LINE); 3. Derive a cylinder object from p gluCylinder(p, base, top, height, slice, stacks) base radius top radius height num. of vertical lines num. of horizontal lines sphere, cylinder, disk, partial disk The default position is also with base at z = 0 plane

glutWireCone() Use glutWireCone and gluCylinder to make a lamp glutWireCone(base, height, slices, stacks) - A polygon approximation of a cone. Default position: its base at Z = 0 plane base: the width of its base height: the height of the cone slices: the number of vertical lines used to make up the cone stace: the number of horizontal lines used to make up the cone Base y x z

glutWireTeapot() The famous Utah Teapot has become an unofficial computer graphics mascot glutWireTeapot(0.5) - Create a teapot with size 0.5, and position its center at (0,0,0) Again, you need to apply transformations to position it at the right spot

Transformations Two ways to specify transformations (1) Each part of the object is transformed independently relative to the origin Not the OpenGL Way! Translate the base by (5,0,0); Translate the lower arm by (5,00); Translate the upper arm by (5,00); … x z y

Relative Transformation A better (and easier) way: (2) Relative transformation: Specify the transformation for each object relative to its parent

Object Dependency A graphical scene often consists of many small objects The attributes of an object (positions, orientations) can depend on others base lower arm upper arm hammer A Robot Hammer!

Hierarchical Representation - Scene Graph We can describe the object dependency using a tree structure Base Lower arm Upper arm Hammer Root node Leaf node The position and orientation of an object can be affected by its parent, grand-parent, grand-grand-parent … nodes This hierarchical representation is referred to as Scene Graph

Relative Transformation Relative transformation: Specify the transformation for each object relative to its parent Step 1: Translate base and its descendants by (5,0,0);

Relative Transformation (2) Step 2: Rotate the lower arm and all its descendants relative to its local y axis by -90 degree x z y x z y

Relative Transformation (3) Represent relative transformations using scene graph Base Lower arm Upper arm Hammer Rotate (-90) about its local y Translate (5,0,0) Apply all the way down Apply all the way down

Do it in OpenGL Translate base and all its descendants by (5,0,0) Rotate the lower arm and its descendants by -90 degree about the local y Base Lower arm Upper arm Hammer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); … // setup your camera glTranslatef(5,0,0); Draw_base(); glRotatef(-90, 0, 1, 0); Draw_lower _arm(); Draw_upper_arm(); Draw_hammer();

A more complicated example How about this model? base Right hammer left hammer Scene Graph? base Lower arm Upper arm Hammer Lower arm Upper arm Hammer (left hammer)(right hammer)

Do this … Base and everything – translate (5,0,0) Left hammer – rotate 75 degree about the local y Right hammer – rotate -75 degree about the local y

Depth-first traversal base Lower arm Upper arm Hammer Lower arm Upper arm Hammer (left hammer)(right hammer) Do transformation(s) Draw base Do transformation(s) Draw left arm Do transformation(s) Draw right arm What are they? Depth First Traversal Program this transformation by depth-first traversal

How about this? base Lower arm Upper arm Hammer Lower arm Upper arm Hammer (left hammer)(right hammer) Draw base Draw left hammer Draw right hammer Translate(5,0,0) Rotate(75, 0, 1, 0) Rotate(-75, 0, 1, 0) What’s wrong?!

Something is wrong … What’s wrong? – We want to transform the right hammer relative to the base, not to the left hammer How about this? Do Draw base Do Draw left hammer Do Draw right hammer Translate(5,0,0) Rotate(75, 0, 1, 0) Rotate(-75, 0, 1, 0) What’s wrong?! We should undo the left hammer transformation before we transform the right hammer Need to undo this first

Undo the previous transformation(s) Need to save the modelview matrix right after we draw base Initial modelView M Draw base Draw left hammer Draw right hammer Translate(5,0,0) -> M = M x T Rotate(75, 0, 1, 0) Rotate(-75, 0, 1, 0) Undo the previous transformation means we want to restore the Modelview Matrix M to what it was here i.e., save M right here … And then restore the saved Modelview Matrix

OpenGL Matrix Stack We can use OpenGL Matrix Stack to perform matrix save and restore Initial modelView M Do Draw base Do Draw left hammer Do Draw right hammer Translate(5,0,0) -> M = M x T Rotate(75, 0, 1, 0) Rotate(-75, 0, 1, 0) * Store the current modelview matrix - Make a copy of the current matrix and push into OpenGL Matrix Stack: call glPushMatrix() - continue to modify the current matrix * Restore the saved Matrix - Pop the top of the Matrix and copy it back to the current Modelview Matrix: Call glPopMatrix()

Push and Pop Matrix Stack A simple OpenGL routine: base Lower arm Upper arm Hammer Lower arm Upper arm Hammer (left hammer)(right hammer) Depth First Traversal glTranslate(5,0,0) Draw_base(); glPushMatrix(); glRotate(75, 0,1,0); Draw_left_hammer(); glPopMatrix(); glRotate(-75, 0,1,0); Draw_right_hammer(); push pop

Push and Pop Matrix Stack Nested push and pop operations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); … // Transform using M1; … // Transform using M2; glPushMatrix(); … // Transform using M3 glPushMatrix();.. // Transform using M4 glPopMatrix(); …// Transform using M5 … glPopMatrix(); Modelview matrix (M) Stack M = I M = M1 M = M1 x M2 M1xM2 M = M1 x M2 x M3 M1xM2xM3 M1 x M2 M = M1 x M2 x M3 x M4 M = M1 x M2 x M3 M1 x M2 M = M1 x M2 x M3 x M5 M = M1 x M2