Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is.

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
Modeling Objects by Polygonal Approximations
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
OpenGL and Projections
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 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
InteractionHofstra University1 Graphics Programming Input and Interaction.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
Hierarchical Modeling II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
Hierarchical ModelingHofstra University1 Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Geometric Transformations Jehee Lee Seoul National University.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Week 4 Lecture 1: Hierarchical Modeling Part 1 Based on Interactive Computer Graphics (Angel) - Chapter 10 1 Angel: Interactive Computer Graphics 5E ©
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.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
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.
MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists.
Transformations Tutorial
Computer Graphics I, Fall 2010 OpenGL Transformations.
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.
NoufNaief.net TA: Nouf Al-harbi.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
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.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 17 Animations, Loops.
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
OpenGL Transformations
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
OpenGL Transformations
Computer Graphics OpenGL Transformations
Better Interactive Programs
OpenGL API 2D Graphic Primitives
Computer Graphics - Hierarchical Models-
Hierarchical and Object-Oriented Graphics
גרפיקה ממוחשבת: מבוא ל-OpenGL
Unit-5 Geometric Objects and Transformations-II
Better Interactive Programs
Fundamentals of Computer Graphics Part 3
Hierarchical and Object-Oriented Graphics
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
OpenGL program.
OpenGL Transformations
OpenGL Transformations
Presentation transcript:

Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is approximated set of polygons Each polygon is specified by a set of vertices To pass the object through the graphics pipeline, pass the vertices of all polygons through a number of transformations using homogeneous coordinates All transformation are linear in homogeneous coordinates, thus a implemented as matrix multiplications

Hierarchical ModelingHofstra University2 Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Hierarchical ModelingHofstra University3 Hierarchical Modeling and Structures Motivation: complex modeling, multiple instances, modularity To model a complex object or a scene: use a tree to model the hierarchy primitives that can be drawn directly, at leaves internal node become instances transformations that position instances of objects label the edges Traverse in pre-order to generate code for the scene

Hierarchical ModelingHofstra University4 Example: simple 2D drawing

Hierarchical ModelingHofstra University5 Hierarchical modeling: tree of transformations Final picture, obtained by traversing in pre-order the tree T1.T2.T5.T7.T9(LINE)

Hierarchical ModelingHofstra University6 Compress the tree If an edge (A,B) is labeled with identity transformation, remove it, and move any drawings from node B into A If edges (A,B) and (A,C) have the same labels, merge the nodes B and C Example: in the previous tree T8 will be removed, and the unit square moved to the parent node

Hierarchical ModelingHofstra University7 From the tree model to OpenGL code Start from the root, traverse tree in pre-order When visiting a node, if there is a primitive at the node that can be drawn, draw it If going down from a node which has more then one unvisited child, store(push) CTM and attributes before continuing down If coming back up an edge to a node which has unvisited children, pop CTM and attributes

Hierarchical ModelingHofstra University8 Stack implementation of the compressed tree glScalef(1.0,-1.0,1.0); //T1 glPushMatrix(); glTranslatef(1.5, 3.0, 0.0); //T2 glScalef(1.0, 2.0, 1.0); //T5 glBegin(GL_LINE_LOOP); //BOX glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,0.0,0.0); glVertex3f(1.0,1.0,0.0); glVertex3f(0.0,1.0,0.0); glEnd(); glTranslatef(0.5,0.0, 0.0); //T7 glRotatef(90.0,0.0,0.0,1.0); //T9 glBegin(GL_LINES); //LINE glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,0.0,0.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslatef(2.0,1.0,0.0); //T3 glScalef(0.5, 0.5, 1.0); //T6 drawUnitCircle(NUM_SLICES); glPopMatrix(); glScalef(4.0,5.0,1.0); // T4 glBegin(GL_LINE_LOOP); // BOX glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,0.0,0.0); glVertex3f(1.0,1.0,0.0); glVertex3f(0.0,1.0,0.0); glEnd(); glFlush();

Hierarchical ModelingHofstra University9 Examples Model a 2D cart consisting of a rod and 2 wheels positioned symmetricly wrt to the rod’s middle point. Spin the wheels (Animation, Double Buffering) Animate 2D robot HW: Model hierarchically a 3D scene consisting of a circular road, a car, and a at least 2 trees along the road. Each component has a different color than the rest. Feel free to expand. A car has a rectangular body and 4 wheels A tree has a trunk (cylinder) and a crown (sphere) The road is a circular loop or a narrow rectangular strip Model each object (object part) in its own local coordinate system; use transformations to position all objects in the scene Use functions or display lists to model the components HW is due after we come back from Spring break: submit the source code, in the report in addition to the usual things (I.e. what you did; How you did it, etc.), draw by hand the tree of transformations you used to model the scene hierarchy.

Hierarchical ModelingHofstra University10 Display Lists Need to draw the display at a rate sufficient to avoid noticeable flicker

Hierarchical ModelingHofstra University11 Display Processor Display processor – special purpose, limited instruction set, oriented toward drawing graphics primitives Display memory holds lists of instructions called display lists Display list executed repeatedly at a rate sufficient to avoid flicker

Hierarchical ModelingHofstra University12 Display Modes Immediate Mode – as soon as the program executes a statement that defines a primitive, it is sent to the server Retained Mode – define the object once, then put its description in a display list. Redisplayed with a simple function call Reduced network traffic

Hierarchical ModelingHofstra University13 OpenGL Display Lists #define BOX 1 glNewList(BOX, GL_COMPILE); glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 0.0); glVertex2f(-1.0, -1.0); glVertex2f( 1.0, -1.0); glVertex2f( 1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd( ); glEndList( ); glCallList(BOX); Send list to server but don’t display contents GL_COMPILE_AND_EXECUTE This can change the original state and leave it altered

Hierarchical ModelingHofstra University14 Definition and Execution #define BOX 1 glNewList(BOX, GL_COMPILE); glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix( ); glBegin(GL_POLYGON); glColor3f(1.0, 0.0, 0.0); glVertex2f(-1.0, -1.0); glVertex2f( 1.0, -1.0); glVertex2f( 1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd( ); glPopAttrib( ); glPopMatrix( ); glEndList( ); Push and pop attributes and coordinates to the stack

Hierarchical ModelingHofstra University15 Stack implementation of the tree of transformations glScalef(1.0,-1.0,1.0); glPushMatrix(); glTranslatef(1.5, 3.0, 0.0); glScalef(1.0, 2.0, 1.0); glCallList(BOX); glTranslatef(0.5,0.0, 0.0); glRotatef(90.0,0.0,0.0,1.0); glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(1.0,0.0,0.0); glEnd(); glPopMatrix(); glPushMatrix(); glTranslatef(2.0,1.0,0.0); glScalef(0.5, 0.5, 1.0); drawUnitCircle(NUM_SLICES); glPopMatrix(); glScalef(4.0,5.0,1.0); glCallList(BOX); glFlush();

Hierarchical ModelingHofstra University16 Example: cart with two wheels

Hierarchical ModelingHofstra University17 Example: wheel glNewList(WHEEL,GL_COMPILE); // red wheel with WHEEL_RAD glPushMatrix(); glPushAttrib(GL_COLOR); glColor3f(1.0,0.0,0.0); // red glScalef(WHEEL_RAD, WHEEL_RAD, 1.0); // scale the unit wheel glBegin(GL_LINES); // unit cross glVertex2f( -1.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f( 0.0, -1.0); glVertex2f( 0.0, 1.0); glEnd(); drawUnitCircle(NUM_SLICES); // unit circle glPopAttrib(); glPopMatrix(); glEndList(); Model a red wheel of radius WHEEL_RAD, consisting of a circle and two crossed spikes. Primitive components are unit circle and crossed orthogonal spikes of length 2.

Hierarchical ModelingHofstra University18 Example: rod with 2 fixed wheels glNewList(CART,GL_COMPILE); glPushMatrix(); glPushAttrib(GL_COLOR); glColor3f(0.0,1.0,0.0); // green glBegin(GL_LINES); // rod glVertex2f(-HALF_AXIS_LENGTH, 0.0); glVertex2f( HALF_AXIS_LENGTH, 0.0); glEnd(); glPushMatrix(); glTranslatef(-HALF_AXIS_LENGTH, 0.0, 0.0); //position front WHEEL at axis glRotatef(TH, 0.0,0.0,1.0); // rotate a WHEEL by TH glCallList(WHEEL); glPopMatrix(); glPushMatrix(); glTranslatef(HALF_AXIS_LENGTH, 0.0, 0.0); //position back WHEEL at axis glRotatef(TH+INCR, 0.0,0.0,1.0); // rotate a WHEEL by TH+INCR glCallList(WHEEL); glPopAttrib(); glPopMatrix(); glEndList(); Model the cart consisting of two red wheels of radius WHEEL_RAD, positioned at the ends of a green rod of length 2*HALF_AXIS_LENGTH. The two wheels are rotated at different angles.

Hierarchical ModelingHofstra University19 Example: cart with 2 wheels void display() { glClear(GL_COLOR_BUFFER_BIT); glCallList(CART); glFlush(); } void myinit() { glClearColor(1.0,1.0,1.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-225.0, 225.0, -225, 225.0); glMatrixMode(GL_MODELVIEW); defineParts(); // WHEEL and CART are display lists defined here, } main() …. As usual, negotiate with Windows Sys, register callbacks, run loop to process events

Hierarchical ModelingHofstra University20 Example: spin the wheels Limitations of display lists Use of functions in drawing instances of objects at tree nodes Continuously keep changing the value of rotation angle for turning a wheel Need of double buffering

Hierarchical ModelingHofstra University21 Example: spin the wheels,2 void draw_cart() { glPushMatrix(); glPushAttrib(GL_COLOR); glColor3f(0.0,1.0,0.0); // draw axis in green glBegin(GL_LINES); glVertex2f(-HALF_AXIS_LENGTH,0.0); glVertex2f(HALF_AXIS_LENGTH,0.0); glEnd(); glPushMatrix(); glTranslatef(-HALF_AXIS_LENGTH,0.0, 0.0); // position front wheel at axis, T1 glRotatef(theta,0.0,0.0,1.0); // spin front WHEEL by theta glCallList(WHEEL); // draw wheel glPopMatrix(); glTranslatef(HALF_AXIS_LENGTH,0.0, 0.0); // position back wheel at axis, T2 glRotatef(theta, 0.0,0.0,1.0); // spin back WHEEL by theta glCallList(WHEEL); // draw wheel glPopAttrib(); glPopMatrix(); }

Hierarchical ModelingHofstra University22 Open GL interactive program structure int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutCreateWindow(”generic example"); myinit (); glutReshapeFunc (myReshape); glutMouseFunc (mouse); glutMotionFunc(do_on_motion); glutIdleFunction(idle); glutDisplayFunc(display); glutMainLoop(); }

Hierarchical ModelingHofstra University23 Example: spin the wheels,3, the Idle Function void idle(void) // IDLE callback function updates { // rotation angle that spins a wheel theta += INCR_ANGLE; glutPostRedisplay(); } void mouseMotion(int x, int y) // MOTION callback function updates { // translation vector that moves whole transx = x; transy = y; glutPostRedisplay(); } void display() // DISPLAY callback draws whole object { // in back buffer then swaps buffers glClear(GL_COLOR_BUFFER_BIT); // translate whole object axis with spinning wheels glTranslatef( (float)transx, (float)(WINDOWH-transy), 0.0); draw_cart(); glutSwapBuffers(); // SWAP BUFFERS }

Hierarchical ModelingHofstra University24 Example: spin the wheels, 4, the Idle Function int main(…) { glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); // double buffering... glutDisplayFunc(display); glutMotionFunc(mouseMotion); glutIdleFunc(idle); glutMainLoop(); … }

Hierarchical ModelingHofstra University25 Example: model circular road // ROAD_RAD1, ROAD_RAD2, ROAD_SL, ROAD_RINGS defined globally void draw_road() { GLUquadric* q; // dynamic array to hold vertices of road q = gluNewQuadric(); // creates and returns a ptr to new quadric object glPushMatrix(); glPushAttrib(GL_ALL_ATTRIB_BITS); glColor3f(0.5,0.5,0.5); // road is gray gluDisk(q, ROAD_RAD1, ROAD_RAD2, ROAD_SL, ROAD_RINGS); glPopMatrix(); glPopAttrib(); gluDeleteQuadric(q); }

Hierarchical ModelingHofstra University26 Example: model circular road void display() { glClear(GL_COLOR_BUFFER_BIT); // glRotatef(45,1.0,0.0,0.0); //gluLookAt(0.0,0.0,0.0, -1.0,-1.0,-1.0, 0.0,0.0,1.0); draw_road(); glFlush(); }

Hierarchical ModelingHofstra University27 Modeling complex objects/motion Decompose object hierarchically into parts Model each part in local frame, and use affine transformations to position it at its proper place in the part above it in the hierarchy