DOC PREVIEW
Brown CSCI 1480 - Meshes Modeling Objects

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1MeshesModeling ObjectsCS148: Intro to CGInstructor: Dan MorrisTA: Sean WalkerJuly 12, 2005Administrative blah-blah{ pp1 was (virtually) handed back{ Exam is coming upz What do you need to know?z Submit questions!{ Submit video-break videos{ Only one late day on pp4Outline for today{ Face culling{ Representing meshes{ Representing surfaces{ Drawing surfacesBeing stingy with our triangles{ When we draw Lego Man, we might draw lots of triangles that end up getting covered up{ It’s not useful to draw the triangles on the other side of Lego ManBackface culling{ For any closed object, it’s not useful to draw any triangles that face away from the viewer{ Often want to eliminate backwards triangles (that face away from the viewer) before rasterization{ This is ‘backface culling’, and OpenGL can do it for youWhich way does a triangle “face”?{ Intuitively, we want the side of the triangle on the outside of our object to be the front{ When I draw a triangle, OpenGL doesn’t know about inside and outside { Need a way to specify front and back of a triangle2Which way does a triangle “face”?{ The order of vertices tells OpenGL which way a triangle faces{ If I look at a triangle, the vertices appear clockwise on one side, counter-clockwise on the other { In GL, the side ordered CCW is the front132132Face normals{ Normal to a face: vector perpendicular to the face, pointing toward the frontHow do we compute the normal to this triangle? 132Which triangles “face the viewer”?In eye coordinates, how do I decide if a triangle faces the viewer (plain English answer)?-z123NReminder: dot productsA • B = |A||B|cosθA • B = 0 → vectors are perpendicularA • B > 0 → vectors “mostly” point the same wayθWhich triangles “face the viewer”?N • (z) > 0 → triangle faces cameraN • (0,0,1) > 0(Nx*0) + (Ny*0) + (Nz*1) > 0Nz> 0 -z123NCulling in OpenGL [culling.cpp]{ Default state listed first:z glDisable(GL_CULL_FACE);glEnable(GL_CULL_FACE);z glCullFace(GL_BACK);glCullFace(GL_FRONT);z glFrontFace(GL_CCW);glFrontFace(GL_CW);When would I want culling disabled?3Front-back in OpenGL{ Frontface/backface determination is also used for lighting{ Backfaces can be a different color / brightness / etc.Illegal Polygons{ Can’t define a normal for a non-planar polygon{ Illegal to send OpenGL non-planar polygons{ Even simple polygons can become non-planar after transformations{ Polygons are generally tessellated by OpenGLOutline for today{ Face culling{ Representing meshes{ Representing surfaces{ Drawing surfacesRepresenting models{ Models so far were made of triangles or simple primitives that we hard-coded in our programs{ “Real” models have too many polygons to create manually{ Need a way to store and represent objectsA mesh data structure: take onestruct vertex {float x,y,z;}struct triangle {vertex a,b,c;}struct object {unsigned int nTriangles;triangle* triangles;}What’s wrong with this approach?How many vertices in a cube?4So what?What are some disadvantages of having redundant vertices?A better mesh data structurestruct vertex {float x,y,z;}struct triangle {unsigned int a,b,c;}struct object {unsigned int nVertices;vertex* vertices;unsigned int nTriangles;triangle* triangles;}Meshes in OpenGL [meshes.cpp]{ Data structures like this are very common{ In fact, a very common way of sending meshes to OpenGL is:// Tell GL where to find verticesglVertexPointer(3,GL_FLOAT,0,myObject.vertices);// Draw “indexed triangles”glDrawElements(GL_TRIANGLES,myObject.nTriangles,GL_UNSIGNED_INT,myObject.triangles);Meshes in OpenGL{ Most mesh file formats store vertices and triangles in a format more or less like thisz Popular formats: .3ds, .obj, .stl{ Most formats add a little more data to each vertex:z Surface normalsz Color informationz Texture coordinatesz These topics make up the next few classes in CS148Outline for today{ Face culling{ Representing meshes{ Representing surfaces{ Drawing surfacesWhen aren’t meshes quite right?Which of these objects could be represented more efficiently with another approach?5Why not always store our objects as meshes?{ Space{ Level of detail{ Modeling{ Non-polygon renderers{ OpenGL (mostly) only knows about triangles and vertices, so we’re leaving the GL universe for a bit...Another approach: object primitives{ Spheres{ Cubes{ Other objects I can easily parameterizeA file format with object primitivesObject LegoMan {// numbers are arbitrarysphere head(0.2,0.3,0.4,0.1);cube body(0.2,0.5,0.3,0.2);triMesh hand {vertices 0.4,0.3,0.5,0.2...triangles 1,2,3,2,3,4...}}{ In fact, VRML – a popular model format –is not all that far from thisStill many objects we can’t compactly represent...{ In particular, we’d like to be able to efficiently represent curves in space{ ...just you can efficiently represent a parabola by writing y = x2, without writing down 100000 points on the parabola.Parametric Surfaces{ Think of an object’s “skin” as a 2D surface{ Use two variables (u,v) to tell me where I am on the surface{ A position function p(u,v) generates points in spacep(u,v) = (X(u,v), Y(u,v), Z(u,v)){ In vector notation:p(u,v) = X(u,v)i + Y(u,v)j + Z(u,v)kParametric Surfaces{ u and v mean different things for different objects{ A parametric surface gives back different points for different (u,v) values{ A cylinder might interpret (u,v) as (h,θ){ A plane might interpret (u,v) as (x,y){ What might (u,v) represent for a sphere?6Defining a Parametric Plane{ I can specify a plane with a point c and any two vectors a,b that live on the plane{ How can I put this in parametric form?{ Define (u,v) = (0,0) as the point c{ Can represent any vector in 2D as a combination of two non-collinear vectors{ So our whole plane is:p(u,v) = ua + vbPlanar Patches{ Could represent the whole plane by letting u and v range from -∞ to +∞{ Often we want to represent a specific chunk of a plane, e.g. the front of Lego Man{ We often define a and b so that letting u and v go from 0 to 1 will give us the object we want{ This restricted piece of a parametric surface is called a patchPlanar Patchesc+a+b11c+a01c+b10c00cornervuOther Patches{ A sphere might interpret (u,v) as (θ,ρ){ A cylinder might interpret (u,v) as (h,θ){ This might be represented as a spherical patch (restricted range of (θ,ρ)) and a cylindrical patch (restricted range of (h,θ) )Other surface types{ Ruled surfaces{ Surfaces of revolution{ Quadric surfacesAside: parametric Line Segment{ If we want a


View Full Document

Brown CSCI 1480 - Meshes Modeling Objects

Download Meshes Modeling Objects
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Meshes Modeling Objects and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Meshes Modeling Objects 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?