CS 4731: Computer Graphics Lecture 9: Introduction to 3D Modeling Emmanuel Agu.

Slides:



Advertisements
Similar presentations
OpenGL Computer Graphics
Advertisements

Computer Graphics - Viewing -
SI23 Introduction to Computer Graphics
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
3D Game Programming Geometric Transformations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
University of North Carolina at Greensboro
The View Frustum and the Camera Lecture 19 Fri, Oct 10, 2003.
Based on slides created by Edward Angel
Viewing and Transformation
CS 4731: Computer Graphics Lecture 10: 3D Modeling: Polygonal Meshes
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
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
Hierarchical Transformations Hierarchical Models Scene Graphs
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
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 4 10 February Agenda Program 2 – Due 2/17 Chapter 4 – transformations GLUT solids.
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
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Transformations Tutorial
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.
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.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
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
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Chap 3 Viewing and Transformation
CS 4731: Computer Graphics Lecture 12: More 3D Viewing Emmanuel Agu.
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.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
OpenGL LAB III.
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Viewing.
Transformations Introduction to Computer Graphics and Animation
Chapter 5.6 Transformations of Objects © 2007, Prentice Hall
Summary of Properties of 3D Affine Transformations
Isaac Gang University of Mary Hardin-Baylor
Reference1. [OpenGL course slides by Rasmus Stenholt]
Introduction to Computer Graphics with WebGL
Three-Dimensional viewing
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Geometric Objects and Transformations (II)
Computer Graphics 3Practical Lesson
Presentation transcript:

CS 4731: Computer Graphics Lecture 9: Introduction to 3D Modeling Emmanuel Agu

3D Modeling Overview of OpenGL modeling (Hill 5.6) Modeling: create 3D model of scene/objects OpenGL commands Coordinate systems (left hand, right hand, openGL-way) Basic shapes (cone, cylinder, etc) Transformations/Matrices Lighting/Materials Synthetic camera basics View volume Projection GLUT models (wireframe/solid) Scene Description Language (SDL): 3D file format

Coordinate Systems Recall: x Y +z Right hand coordinate system x Left hand coordinate system Not used in this class and Not in OpenGL +z

3D Modeling: GLUT Models Two main categories: Wireframe Models Solid Models Basic Shapes Cylinder: glutWireCylinder( ), glutSolidCylinder( ) Cone: glutWireCone( ), glutSolidCone( ) Sphere: glutWireSphere( ), glutSolidSphere( ) Cube: glutWireCube( ), glutSolidCube( ) More advanced shapes: Newell Teapot: (symbolic) Dodecahedron, Torus

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

3D Modeling: GLUT Models Without GLUT models: Use generating functions More work!! Example: Look in examples bounce, gears, etc. What does it look like? Generates a list of points and polygons for simple shapes Spheres/Cubes/Sphere

Cylinder Algorithm glBegin(GL_QUADS) For each A = Angles{ glVertex3f(R*cos(A), R*sin(A), 0); glVertex3f(R*cos(A+DA), R*sin(A+DA), 0) glVertex3f(R*cos(A+DA), R*sin(A+DA), H) glVertex3f(R*cos(A), R*sin(a), H) } // Make Polygon of Top/Bottom of cylinder

3D Transforms Scale: glScaled(sx, sy, sz) - scale object by (sx, sy, sz) Translate: glTranslated(dx, dy, dz) - translate object by (dx, dy, dz) Rotate: glRotated(angle, ux, uy, uz) – rotate by angle about an axis passing through origin and (ux, uy, uz)

OpenGL Matrices

OpenGL Matrices/Pipeline OpenGL uses 3 matrices (simplified) for geometry: Modelview matrix: Projection matrix: Viewport matrix: Modelview matrix: combination of modeling matrix M and Camera transforms V Other OpenGL matrices include texture and color matrices glMatrixMode command selects matrix mode glMatrixMode parameters: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE, etc

OpenGL Matrices/Pipeline Projection matrix: Scales and shifts each vertex in a particular way. View volume lies inside cube of –1 to 1 Reverses sense of z: increasing z = increasing depth Effectively squishes view volume down to cube centered at 1 Clipping then eliminates portions outside view volume Viewport matrix: Maps surviving portion of block (cube) into a 3D viewport Retains a measure of the depth of a point

Lighting and Object Materials Light components: Diffuse, ambient, specular OpenGL: glLightfv( ), glLightf( ) Materials: OpenGL: glMaterialfv( ), glMaterialf( )

Synthetic Camera Define: Eye position LookAt point Up vector (if spinning: confusing) Programmer knows scene, chooses: eye lookAt Up direction usually set to (0,1,0) OpenGL: gluLookAt(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z)

Synthetic Camera

View Volume Side walls determined by window borders Other walls determined by programmer-defined Near plane Far plane Convert 3D models to 2D: Project points/vertices inside view volume unto view window using parallel lines along z-axis

Projection Different types of projections: Parallel Perspective Parallel is simple Will use for this intro, expand later

Hierarchical Transforms Using OpenGL Object dependency Graphical scene: many small objects Attributes (position, orientation, etc) depend on each other base lower arm hammer A Robot Hammer!

Hierarchical Transforms Using OpenGL Object dependency description using tree structure Base Lower arm Upper arm Hammer Root node Leaf node Object position and orientation can be affected by its parent, grand-parent, grand-grand-parent … nodes Hierarchical representation is known as Scene Graph

Transformations Two ways to specify transformations: (1) Absolute transformation: each part of the object is transformed independently relative to the origin 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 Step 1: Translate base and its descendants by (5,0,0);

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

Relative Transformation Represent relative transformation 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

Hierarchical Transforms Using 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();

Hierarchical Models Two important calls: glPushMatrix( ): load transform matrix with following matrices glPopMatrix( ): restore transform matrix to what it was before glPushMatrix( ) If matrix stack has M1 at the top, after glPushMatrix( ), positions 1 and 2 on matrix stack have M1 If M1 is at the top and M2 is second in position, glPopMatrix( ) destroys M1 and leaves M2 at the top To pop matrix without error, matrix must have depth of at least 2 Possible depth of matrices vary. Modelview matrix allows 32 matrices Other matrices have depth of at least 2

SDL SDL makes hierarchical modeling easy With openGL: a little tougher SDL data structure format

SDL Easy interface to use 3 steps: Step One #include “sdl.h” Add sdl.cpp to your make file/workspace Step Two: Instantiate a Scene Object Example: Scene scn; Step Three: scn.read(“your scene file.dat”); // reads your scene scn. makeLightsOpenGL(); // builds lighting data structure scn. drawSceneOpenGL(); // draws scene using OpenGL

Example: Table without SDL // define table leg // void hw02::tableLeg(minigl &mgl, double thick, double len){ mgl.mglPushMatrix(); mgl.mglTranslated(0, len/2, 0); mgl.mglScaled(thick, len, thick); mgl.mglutSolidCube(1.0); mgl.mglPopMatrix(); } // note how table uses tableLeg- void hw02::table(minigl &mgl, double topWid, double topThick, double legThick, double legLen){ // draw the table - a top and four legs mgl.mglPushMatrix(); mgl.mglTranslated(0, legLen, 0);

Example: Table without SDL mgl.mglScaled(topWid, topThick, topWid); mgl.mglutSolidCube(1.0); mgl.mglPopMatrix(); double dist = 0.95 * topWid/2.0 - legThick / 2.0; mgl.mglPushMatrix(); mgl.mglTranslated(dist, 0, dist); tableLeg(mgl, legThick, legLen); mgl.mglTranslated(0, 0, -2*dist); tableLeg(mgl, legThick, legLen); mgl.mglTranslated(-2*dist, 0, 2*dist); tableLeg(mgl, legThick, legLen); mgl.mglTranslated(0, 0, -2*dist); tableLeg(mgl, legThick, legLen); mgl.mglPopMatrix(); }

Example: Table without SDL // translate and then call mgl.mglTranslated(0.4, 0, 0.4); table(mgl, 0.6, 0.02, 0.02, 0.3); // draw the table

Example: Table with SDL def leg{push translate scale cube pop} def table{ push translate scale cube pop push translate use leg translate use leg translate use leg translate use leg pop } push translate use table pop

Examples Hill contains useful examples on: Drawing fireframe models (example 5.6.2) Drawing solid models and shading (example 5.6.3) Using SDL in a program (example 5.6.4) Homework 3: Will involve studying these examples Work with SDL files in miniGL Start to build your own 3D model

References Hill, 5.6, appendices 3,5 Angel, Interactive Computer Graphics using OpenGL (3 rd edition) Hearn and Baker, Computer Graphics with OpenGL (3 rd edition)