Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.

Slides:



Advertisements
Similar presentations
1Computer Graphics Building Models John Shearer Culture Lab – space 2
Advertisements

1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
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.
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.
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 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.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
Fundamentals of Computer Graphics Part 4
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.
1 Chapter 4 Geometric Objects and Transformation.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Speeding Up Rendering After Deciding What to Draw.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Objects and Transformation
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.
Objectives Introduce simple data structures for building polygonal models -- Vertex lists and Edge lists Introduce simple data structures for building.
Geometric Objects and Transformations
CAP 4730 Computer Graphic Methods Prof. Roy Levow Chapter 4.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
Affine Geometry Jehee Lee Seoul National University.
1 Building Models Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley.
1 Graphics CSCI 343, Fall 2015 Lecture 10 Coordinate Transformations.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Affine Geometry Jehee Lee Seoul National University.
Affine Geometry.
Computer Graphics Matrices
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.
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 Transformations.
Graphics Graphics Korea University kucg.korea.ac.kr Geometric Primitives 고려대학교 컴퓨터 그래픽스 연구실.
4. Geometric Objects and Transformations
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
Unit-4 Geometric Objects and Transformations- I
Introduction to Computer Graphics with WebGL
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Coordinate Change.
Representation Ed Angel Professor Emeritus of Computer Science,
Building Models Ed Angel
Isaac Gang University of Mary Hardin-Baylor
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Introduction to Computer Graphics with WebGL
Building Models Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
CSC461: Lecture 14 Representations
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Building Models Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
Representation Ed Angel Professor Emeritus of Computer Science,
PPT&Programs
Geometric Objects and Transformations (I)
Viewing and Projection
Representation Ed Angel
Viewing and Projection
Presentation transcript:

Representation

Objectives Introduce concepts such as 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

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

Representation Until now we have been able to work with geometric entities without using any frame of reference, such as a coordinate system Need a frame of reference to relate points and objects to our physical world.  For example, where is a point? Can’t answer without a reference system  World coordinates  Camera coordinates

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 We can write the representation as a row or column array of scalars a=[  1  2 ….  n ] T =

Example v=2v 1 +3v 2 -4v 3 a=[2 3 –4] T Note that this representation is with respect to a particular basis For example, in OpenGL we start by representing vectors using the object basis but later the system needs a representation in terms of the camera or eye basis

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 A vector has no position 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 = [  1  2  3 0 ] [v 1 v 2 v 3 P 0 ] T P = P 0 +  1 v 1 +  2 v 2 +  3 v 3 = [  1  2  3 1 ] [v 1 v 2 v 3 P 0 ] 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 Note that homogeneous coordinates replaces points in three dimensions by lines through the origin in four dimensions For w=1, the representation of a point is [x y z 1] T

Homogeneous Coordinates and Computer Graphics 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 v=  1 v 1 +  2 v 2 +  3 v 3 = [  1  2  3 ] [v 1 v 2 v 3 ] T =  1 u 1 +  2 u 2 +  3 u 3 = [  1  2  3 ] [u 1 u 2 u 3 ] T a=[  1  2  3 ] T b=[  1  2  3 ] T where

Representing second basis in terms of first Each of the basis vectors, u1,u2, u3, 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

Matrix Form The coefficients define a 3 x 3 matrix and the bases 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 One Frame in Terms of the Other 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

Affine Transformations Every linear transformation is equivalent to a change in frames Every affine transformation preserves lines However, an affine transformation has only 12 degrees of freedom because 4 of the elements in the matrix are fixed and are a subset of all possible 4 x 4 linear transformations

The World and Camera Frames When we work with representations, we work with n-tuples or arrays of scalars Changes in frame are then defined by 4 x 4 matrices In OpenGL, the base frame that we start with is the world frame Eventually we represent entities in the camera frame by changing the world representation using the model-view matrix Initially these frames are the same ( M=I )

Moving the Camera If objects are on both sides of z=0, we must move camera frame M =

Building Models

Objectives Introduce simple data structures for building polygonal models  Vertex lists  Edge lists OpenGL vertex arrays

Representing a Mesh 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 Define each polygon by the geometric locations of its vertices Leads to OpenGL code such as Inefficient and unstructured  Consider moving a vertex to a new location  Must search for all occurrences glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x6, y6, z6); glVertex3f(x8, y8, z8); glVertex3f(x7, y7, z7); glEnd();

Inward and Outward Facing Polygons The order {v 1, v 6, v 7 } and {v 6, v 7, v 1 } are equivalent in that the same polygon will be rendered by OpenGL but the order {v 1, v 7, v 6 } is different The first two describe outwardly facing polygons Use the right-hand rule = counter-clockwise encirclement of outward-pointing normal OpenGL can treat inward and outward facing polygons differently

Geometry vs Topology Generally it is a good idea to look for data structures that separate the geometry from the topology  Geometry: locations of the vertices  Topology: organization of the vertices and edges  Example: a polygon is an ordered list of vertices with an edge connecting successive pairs of vertices and the last to the first  Topology holds even if geometry changes

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

Shared Edges Vertex lists will draw filled polygons correctly but if we draw the polygon by its edges, shared edges are drawn twice Can store mesh by edge list

Edge List v1v1 v2v2 v7v7 v6v6 v8v8 v5v5 v3v3 e1e1 e8e8 e3e3 e2e2 e 11 e6e6 e7e7 e 10 e5e5 e4e4 e9e9 e 12 e1 e2 e3 e4 e5 e6 e7 e8 e9 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 v1 v6 Note polygons are not represented

Modeling a Cube 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}}; Model a color cube for rotating cube program Define global arrays for vertices and colors

Drawing a polygon from a list of indices 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 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); } Note that vertices are ordered so that we obtain correct outward facing normals

Efficiency The weakness of our approach is that we are building the model in the application and must do many function calls to draw the cube Drawing a cube by its faces in the most straight forward way requires  6 glBegin, 6 glEnd  6 glColor  24 glVertex  More if we use texture and lighting

Vertex Arrays OpenGL provides a facility called vertex arrays that allows us to store array data in the implementation Six types of arrays supported  Vertices  Colors  Color indices  Normals  Texture coordinates  Edge flags 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

Mapping indices to faces Form an array of face indices Each successive four indices describe a face of the cube Draw through glDrawElements which replaces all glVertex and glColor calls in the display callback 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!!

Summary Dimension, Basis Vectors spaces vs. affine spaces Coordinate systems vs. frames Representation of points vs. vectors Homogeneous coordinates Change of frames with matrix, e.g., moving the camera