icon

Usetutoringspotscode to get 8% OFF on your first order!

Computer Graphics 8

Triangle mesh model
Use OpenGL to display a 3D model.
Use a vertex list and triangle list to keep track of the data. Recall that a vertex has three coordinates, (x,y,z), represented as floats. Also, a triangle has three ints, (a,b,c); each is an index into the array of vertices, since a triangle has three vertices. You probably want a class for triangles and a class for vertices.
Implement reading a .t file. The format is a pair of int values representing the number of triangles T and the number of vertices V. Following this are 3T int values representing indices into the vertex array. Finally there are 3V float values representing (x,y,z) coordinates for each vertex. Sample files are on Blackboard. See below for an example.
Once the file is loaded, loop through the triangles (in the display method) and draw them. Use different colors for the triangles so we can actually see the object. You can either use random colors like we have been using, or generate some kind of pattern. (Dont implement any lighting or shading; well save that for next week.)
The vertex locations may be completely arbitrary, so you need to make sure the model appears on the screen. You can do this using a scale and a translate. While you read in the file, calculate a bounding box by finding the min and max values for x, y, and z.
Find the center point by taking the average of the min and max. Translate by the negative of this to center the object at the world origin.
The max minus the min is the size of the object. Take the size of the biggest dimension (x, y, or z), and scale by 1 over this to make the object fit into a -1 to 1 cube.
Use the trackball interface (sample program provided) so the user can look at all sides of the model. Be sure the depth test is enabled so the user cant see through the model.
Use a model from Blackboard or one you can find online. (Ill come up with a way to translate it into .t format for you if you give me enough advance notice. I should be able to do .ply and .obj files.)
Remember that this will be graded on the basis of creativity, completeness, construction, and communication. (See course syllabus.)Computer Graphics 9
Triangle mesh model in a scene
1. Use OpenGL to display a 3D model in a scene with appropriate lighting. The goal is to have this look like a picture of a real-world scene (even it its a fantasy world).
2. Use the same model you used in Homework 8.
a. You will want to place it precisely in the scene. Use scaling and translation to put it exactly where you want.
b. If you calculate a bounding box while reading in the file, you can figure out how much to scale and translate so that the model is at the origin and within a -1 to 1 cube.
3. Calculate a normal vector at every vertex using the algorithm described in class.
a. If you have a Vertex class and a Triangle class, add instance variables to hold a normal for each of them.
b. If you dont have those classes, you have parallel arrays instead. This is fineyou will just need more arrays to hold (x,y,z) values for normal vectors for the triangles and vertices.
c. Use smooth shading.
d. Normal vectors are transformed along with vertices by the current transformation matrix. This is (usually) what we want, except for scaling. Normal vectors should always be unit length for the lighting to look right. Since you know how youre scaling you can compensate for it by setting the right length of every normal vector, or you can do it the easier (but slower) way by enabling GL_NORMALIZE (see p. 103 in the textbook).
4. Add a floor and a backdrop to the scene so that the model looks somewhat realistic, rather than floating in space.
5. Add a light (or lights) so that your model looks realistically lit. Do not use the randomly colored triangles anymore.
6. Try to use texture mapping.
a. You may use textures on the model if you want, but make sure you also use lighting.
b. You may use textures on the floor or walls or elsewhere in the environment instead of (or in addition to) on the model itself.
7. Remember that this will be graded on the basis of creativity, completeness, construction, and communication. (See course syllabus.)

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes