Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.

Slides:



Advertisements
Similar presentations
Computer Graphics - Geometry & Representation -
Advertisements

Today Composing transformations 3D Transformations
1Computer Graphics Building Models John Shearer Culture Lab – space 2
Demetriou/Loizidou – ACSC330 – Chapter 4 Geometric Objects and Transformations Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Geometry Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Representation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Transformations. 2 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple geometry, most of us.
Representation CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Vectors.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
Geometry CSC 2141 Introduction to Computer Graphics.
1 Geometry. 2 Objectives Introduce the elements of geometry ­Scalars ­Vectors ­Points Develop mathematical operations among them in a coordinate-free.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Mathematics for Graphics. 1 Objectives Introduce the elements of geometry  Scalars  Vectors  Points Develop mathematical operations among them in a.
State Management and Drawing Geometry Objects
Geometric Objects and Transformation
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Viewing and Projection. 2 3 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009  Introduce the classical views  Compare and contrast image.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 Computer Graphics Three-Dimensional Graphics I.
Computer Graphics Bing-Yu Chen National Taiwan University.
Objectives Introduce simple data structures for building polygonal models -- Vertex lists and Edge lists Introduce simple data structures for building.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
1 Building Models Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
1 Graphics CSCI 343, Fall 2015 Lecture 9 Geometric Objects.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSC461: Lecture 13 Coordinates Objectives Introduce concepts such as dimension and basis Introduce concepts such as dimension and basis Introduce coordinate.
1 Representation. 2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
Computer Graphics I, Fall 2010 Building Models.
Computer Graphics I, Fall 2010 Geometry.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Geometry.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Graphics Graphics Korea University kucg.korea.ac.kr Geometric Primitives 고려대학교 컴퓨터 그래픽스 연구실.
4. Geometric Objects and Transformations
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Unit-4 Geometric Objects and Transformations- I
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Math Fundamentals Maths revisit.
Coordinate Change.
Representation Ed Angel Professor Emeritus of Computer Science,
CSC461: Lecture 12 Geometry Objectives
Building Models Ed Angel
Isaac Gang University of Mary Hardin-Baylor
Isaac Gang University of Mary Hardin-Baylor
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Representation Ed Angel Professor Emeritus of Computer Science,
PPT&Programs
Geometric Objects and Transformations (I)
Representation Ed Angel
Presentation transcript:

Modeling

Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture  Composite objects  Other objects and their relationships to each other 2

The basic idea  Describe objects using surfaces, which are polygons  Triangles, quadrilaterals, etc.  Important thing is that they are flat and convex  Convex : A line segment connecting any two points on the polygon is contained in the polygon.  Provide points in counterclock-wise order from the visible side 3 P Q P convex concave

Outline 4  OpenGL Elementary Rendering (codes)  Representation  Appendix: Vector Operations *

OpenGL Elementary Rendering  Geometric Primitives  Building Models  Managing OpenGL State 5

OpenGL Geometric Primitives  All geometric primitives are specified by vertices GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOPGL_LINE_STRIP GL_TRIANGLES GL_QUADS 6

Simple Example void drawRhombus( GLfloat color[] ) { glBegin( GL_QUADS ); glColor3fv( color ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.5, ); glVertex2f( 0.5, ); glEnd(); } 7

OpenGL Command Formats glVertex3fv( v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data Type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector omit “ v ” for scalar form glVertex2f( x, y ) 8

Specifying Geometric Primitives  Primitives are specified using glBegin( primType ); glEnd();  primType determines how vertices are combined GLfloat red, greed, blue; Glfloat coords[3]; glBegin( primType ); for ( i = 0; i < nVerts; ++i ) { glColor3f( red, green, blue ); glColor3f( red, green, blue ); glVertex3fv( coords ); glVertex3fv( coords );}glEnd(); 9

Shapes Tutorial 10

OpenGL Color Models *  RGBA or Color Index color index mode Display  RedGreenBlue  RGBA mode 11

Building models  Consider a mesh  There are 8 nodes and 12 edges  5 interior polygons  6 interior (shared) edges  Each vertex has a location v i = (x i y i z i ) v1v1 v2v2 v7v7 v6v6 v8v8 v5v5 v4v4 v3v3 e1e1 e8e8 e3e3 e2e2 e 11 e6e6 e7e7 e 10 e5e5 e4e4 e9e9 e 12

Simple Representation  Each polygon is defined by the geometric locations of its vertices, which leads to OpenGL code such as  Inefficient and unstructured glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x7, y7, z7); glVertex3f(x8, y8, z8); glVertex3f(x6, y6, z6); glEnd();

Vertex Lists  Put the geometry in an array  Use pointers from the vertices into this array  Introduce a polygon list x 1 y 1 z 1 x 2 y 2 z 2 x 3 y 3 z 3 x 4 y 4 z 4 x 5 y 5 z 5. x 6 y 6 z 6 x 7 y 7 z 7 x 8 y 8 z 8 P1 P2 P3 P4 P5 v1v7v6v1v7v6 v8v5v6v8v5v6 topology geometry

Example: Modeling a Cube  Define global arrays for vertices and colors GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};

 Draw a quadrilateral from a list of indices into the array vertices and use color corresponding to first index void polygon(int a, int b, int c, int d) { glBegin(GL_POLYGON); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glVertex3fv(vertices[b]); glVertex3fv(vertices[c]); glVertex3fv(vertices[d]); glEnd(); }

 Draw cube from faces  Note that vertices are ordered so that we obtain correct outward facing normals void colorcube( ) { polygon(0,3,2,1); polygon(2,3,7,6); polygon(0,4,7,3); polygon(1,2,6,5); polygon(4,5,6,7); polygon(0,1,5,4); }

 Efficiency  The problem is that we must do many function calls to draw the cube  6 glBegin, 6 glEnd  6 glColor  24 glVertex  More if we use texture and lighting

*  OpenGL provides vertex arrays to store array data  Six types of arrays supported  Vertices  Colors  Color indices  Normals  Texture coordinates  Edge flags  Here we will need only colors and vertices

*  Initialization  Using the same color and vertex data, first we enable glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);  Identify location of arrays glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); 3d arraysstored as floats data contiguous data array

*  Form an array of face indices  Each successive four indices describe a face of the cube GLubyte cubeIndices[24] = {0,3,2,1,2,3,7,6 0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4};

*  Drawing the cube  Method 1:  Method 2: for(i=0; i<6; i++) glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &cubeIndices[4*i]); format of index data start of index data what to draw number of indices glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices); Draws cube with 1 function call!!

OpenGL’s State Machine  All rendering attributes are encapsulated in the OpenGL State  rendering styles  shading  lighting  texture mapping 23

Manipulating OpenGL State  Appearance is controlled by current state for each ( primitive to render ) { update OpenGL state render primitive }  Manipulating vertex attributes is most common way to manipulate state glColor*() / glIndex*() glNormal*()glTexCoord*() 24

Controlling current state  Setting State glPointSize( size ); glShadeModel( GL_SMOOTH );  Enabling Features glEnable( GL_LIGHTING ); glDisable( GL_TEXTURE_2D ); 25

Outline 26  OpenGL Elementary Rendering (codes)  Representation  Appendix: Vector Operations

Objectives  Introduce dimension and basis  Introduce coordinate systems for representing vectors spaces and frames for representing affine spaces  Discuss change of frames and bases  Introduce homogeneous coordinates

Vectors  Objects with length and direction  Examples include  Force  Velocity  Directed line segments  We will think of a vector as a displacement from one point to another  We use bold typeface to indicate vectors v 28

Vectors as Displacements 29  As a displacement, a vector has length and direction, but no inherent location  You can drive one mile East in Zhuhai  To represent vectors, we need firstly learn…

Linear Independence  A set of vectors v 1, v 2, …, v n is linearly independent if  1 v 1 +  2 v  n v n =0 iff  1 =  2 =…=0  If a set of vectors is linearly independent, we cannot represent one in terms of the others  If a set of vectors is linearly dependent, as least one can be written in terms of the others

Dimension  In a vector space, the maximum number of linearly independent vectors is fixed and is called the dimension of the space  In an n-dimensional space, any set of n linearly independent vectors form a basis for the space  Given a basis v 1, v 2,…., v n, any vector v can be written as v=  1 v 1 +  2 v 2 +….+  n v n where the {  i } are unique

Coordinate Systems  Consider a basis v 1, v 2,…., v n  A vector is written v=  1 v 1 +  2 v 2 +….+  n v n  The list of scalars {  1,  2, ….  n } is the representation of v with respect to the given basis  Scalar: here an ordinary real (e.g., float) number.  Scalars alone have no geometric properties  We can write the representation as a row or column array of scalars a=[  1  2 ….  n ] T =

Examples  v=2v 1 +3v 2 -4v 3  a=[2 3 –4] T  Note that this representation is with respect to a particular basis  v = 5 v 1 -2v 2 in a plane

Coordinate Systems  Which is correct?  Both are because vectors have no fixed location v v

Frames  A coordinate system is insufficient to represent points  If we work in an affine space we can add a single point, the origin, to the basis vectors to form a frame P0P0 v1v1 v2v2 v3v3

Representation in a Frame  Frame determined by (P 0, v 1, v 2, v 3 )  Within this frame, every vector can be written as v=  1 v 1 +  2 v 2 +….+  n v n  Every point can be written as P = P 0 +  1 v 1 +  2 v 2 +….+  n v n

Confusing Points and Vectors  Consider the point and the vector P = P 0 +  1 v 1 +  2 v 2 +….+  n v n v=  1 v 1 +  2 v 2 +….+  n v n  They appear to have the similar representations p=[  1  2  3 ] T v=[  1  2  3 ] T which confuses the point with the vector v p v Vector can be placed anywhere point: fixed

A Single Representation  If we define 0P = 0 and 1P =P then we can write v=  1 v 1 +  2 v 2 +  3 v 3 = [v 1 v 2 v 3 P 0 ] [  1  2  3 0 ] T P = P 0 +  1 v 1 +  2 v 2 +  3 v 3 = [v 1 v 2 v 3 P 0 ] [  1  2  3 1 ] T Thus we obtain the four-dimensional homogeneous coordinate representation v = [  1  2  3 0 ] T p = [  1  2  3 1 ] T

Homogeneous Coordinates  The homogeneous coordinates form for a three dimensional point [x y z] is given as p =[x’ y’ z’ w] T =[wx wy wz w] T We return to a three dimensional point (for w  0 ) by x  x’ /w y  y’/w z  z’/w  If w=0, the representation is that of a vector  For w=1, the representation of a point is [x y z 1]  Note that homogeneous coordinates replaces points in three dimensions by lines through the origin in four dimensions

 Homogeneous coordinates are key to all computer graphics systems  All standard transformations (rotation, translation, scaling) can be implemented with matrix multiplications using 4 x 4 matrices  Hardware pipeline works with 4 dimensional representations  For orthographic viewing, we can maintain w=0 for vectors and w=1 for points  For perspective we need a perspective division

Change of Coordinate Systems  Consider two representations of a same vector with respect to two different bases. The representations are a=[  1  2  3 ] T b=[  1  2  3 ] T where v=  1 v 1 +  2 v 2 +  3 v 3 = [v 1 v 2 v 3 ] [  1  2  3 ] T =  1 u 1 +  2 u 2 +  3 u 3 = [u 1 u 2 u 3 ] [  1  2  3 ] T

Representing 2 nd basis in terms of 1 st  Each of the basis vectors, u 1,u 2, u 3, are vectors that can be represented in terms of the first basis u 1 =  11 v 1 +  12 v 2 +  13 v 3 u 2 =  21 v 1 +  22 v 2 +  23 v 3 u 3 =  31 v 1 +  32 v 2 +  33 v 3 v [u 1 u 2 u 3 ] = [v 1 v 2 v 3 ]M T

Simple example 43

Matrix Form The coefficients define a 3 x 3 matrix and the representations can be related by a=M T b M =

Change of Frames  We can apply a similar process in homogeneous coordinates to the representations of both points and vectors  Any point or vector can be represented in either frame  We can represent Q 0, u 1, u 2, u 3 in terms of P 0, v 1, v 2, v 3 Consider two frames: (P 0, v 1, v 2, v 3 ) (Q 0, u 1, u 2, u 3 ) P0P0 v1v1 v2v2 v3v3 Q0Q0 u1u1 u2u2 u3u3

Representing 2 nd Frame in the 1 st u 1 =  11 v 1 +  12 v 2 +  13 v 3 u 2 =  21 v 1 +  22 v 2 +  23 v 3 u 3 =  31 v 1 +  32 v 2 +  33 v 3 Q 0 =  41 v 1 +  42 v 2 +  43 v 3 +  44 P 0 Extending what we did with change of bases defining a 4 x 4 matrix M =

Working with Representations  Within the two frames any point or vector has a representation of the same form a=[  1  2  3  4 ] T in the first frame b=[  1  2  3  4 ] T in the second frame where  4   4  for points and  4   4  for vectors and The matrix M is 4 x 4 and specifies an affine transformation in homogeneous coordinates a=M T b

Representing geometry elements  Points  Location in space  Operations allowed between points and vectors  Point-point subtraction yields a vector  Equivalent to point-vector addition P=v+QP=v+Q v=P-Qv=P-Q 48

Lines  Consider all points of the form  P(  )=P 0 +  d  Set of all points that pass through P 0 in the direction of the vector d 49

Rays and Line Segments  If  >= 0, then P(  ) is the ray leaving P 0 in the direction d  If we use two points to define v, then P(  ) = Q+  v = Q +  (R-Q) =  R + (1-  )Q  For 0<=  <=1 we get all the points on the line segment joining R and Q 50

Planes  A plane can be defined by a point and two vectors or by three points P( ,  )=R+  u+  v P( ,  )=R+  (Q-R)+  (P-R) u v R P R Q 51

Barycentric Coordinates 52  We can reorder the terms of the equation: with:  This coordinate system is called barycentric coordinates  For any point P inside the triangle (a, b, c):  Point on an edge: one coefficient is 0  Vertex: two coefficients are 0, remaining one is 1

Outline 53  OpenGL Elementary Rendering  Representation  Appendix: Vector Operations *

Vector Operations 54  Addition and multiplication by a scalar:  a + b  s*a  Examples:

Vector Addition 55  Head to tail: At the end of a, place the start of b.  Parallelogram rule:  Components: [a 1 + b 1, a 2 + b 2 ]

Vector Subtraction 56  To draw a - b, go forward along a and then backward along b.  Components: [a 1 - b 1, a 2 - b 2 ]

The Dot Product 57  Also called the inner product of two vectors  Produces a number, not a vector  In 2D:  In 3D:  Symmetry:  Linearity:  Homogeneity:

Length of a Vector 58  The length (or norm) of a vector a is:  The dot product of a vector with itself yields the length squared:

Unit Vectors and Normalization 59  A unit vector is a vector whose length equals 1  Example: (1, 0, 0), (0, 1, 0), (0, 0, 1)  Divide any nonzero vector v by its length |v|. The result is a unit vector in the same direction as v.  This is called normalizing a vector:  Any vector can be written as its magnitude times its direction:

The Angle Between Vectors 60  The angle between vectors can be computed by:  Using normalized vectors:

The Sign of ab 61  Imagine the cosine function:  Two vectors a and b are perpendicular, orthogonal, or normal if ab= 0

The end 62  Questions and answers