Due: Monday, Nov. 14, 11:59pm
SUBMISSION - zip up the CL112D-MSVS2010 runnable project and upload it using the Carmen Dropbox
FINAL VERSION - although I might add some more notes or comments as I get feedback from students
Topics: Menu, Subdividing, Illumination, Materials, and Decals
OBJECTIVE: to introduce you to more complex shading techniques as well as expanded techniques involving interaction and modeling:
|
|
Subdivide(v[3],v1[3],v2[3],n,m) pi = v dvi = v1/n dvj = v2/m n = v1 X v2 glBegin Quads glNormal3fv(n) for (i=0 to n) pj = pi for (j=0 to m) glVertex(pj) glVertex(pj+dvi) glVertex(pj+dvi+dvj) glVertex(pj+dvj) pj += dvj pi += dvi glEndReplace any quad with a call to 'subdivide'. For example, if you had a groundplane quad that went from -100 to +100 in x and z, then to subdivide it into 50x50 mini-quads, call:
Subdivide(-100,0,-100, 200.0,0.0,0.0, 0.0,0.0,200.0, 50,50);Be careful with how you write the routine and call it so that you maintain the correct orientation of the quads (CW v. CCW). To use a two-color groundplane, rewrite the subdivide code with two color commands. just keep toggling a binary variable every time at the end of the inner loop and every time at the end of the outter loop. For example, k = 1-k. If k == 0, use one of the colors; if k == 1, use the other color for that quad.
// define top flat-shaded polygon, y = 1; all vertices get the same normal glNormal(0,1,0) for theta = 2*PI to 0 by increments of -Pi/8 glVertex(cos(theta),1.0,sin(theta)) // define bottom flat-shaded polygon, y = -1; all vertices get the same normal glNormal(0,-1,0) for theta = 0 to 2*PI by increments of Pi/8 glVertex(cos(theta),-1.0,sin(theta)) // define side quadrilaterals // each vertex normal of a quadrilateral is vector from the origin to the center of the quad // alternate the color of each side panel color[0][4] = one color color[1][4] = the other color i = 0; for theta = 0 to 2*Pi by increments of Pi/8 assign color[i] i = 1-i glNormal3f(cos(theta+Pi/16), 0.0, sin(theta+Pi/16)) glVertex(cos(theta), 1.0, sin(theta)) glVertex(cos(theta+Pi/8), 1.0, sin(theta+Pi/8)) glVertex(cos(theta+Pi/8), -1.0, sin(theta+Pi/8)) glVertex(cos(theta), -1.0, sin(theta))
Because each vertex appears in 3 polygons, You can save a little computation time by precomputing all the vertices first, storying them into arrays, and then indexing into the arrays as you define the polygons. However, because this is one-time code (when it's put in the display list), the savings is not that significant.
The cylinder should be scaled, rotated, and positioned appropriately relative to the vehicle body to form the wheels.
glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS,1,1); glStencilOp(GL_KEEP,GL_ZERO,GL_REPLACE); <draw base polygon> glDisable(GL_DEPTH_TEST); glStencilFunc(GL_EQUAL,1,1); glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP); <draw decal> glEnable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST);
mode = GLUT_RGB | .... | GLUT_STENCIL; .. glutInitDisplayMode(mode);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);