glut code demo & homework

Post Reply
angus
Posts: 43
Joined: Fri Apr 02, 2010 1:54 pm

glut code demo & homework

Post by angus » Fri Jan 21, 2011 7:39 pm

Hi, under the code directory for the course page I've added some demos

http://www.mat.ucsb.edu/594cm/2011/mat594cm/code/

There's no problem set this week, rather I want you to look at and use/modify the code in two of the demos (as described below). Also, brush up on your C programming (e.g, via http://www.cprogramming.com/tutorial.html#ctutorial).

I've added some sample code for reading an .OBJ file under the glutLoadObjFile directory. We'll go over it in class when we discuss C programming in more detail next week, but if you look at the main.c and main.h files you should be able to make more sense of how to use structs and how to use pointers and arrays in C, and how to allocate (and reallocate) memory. For your homework this week, simply create your own OBJ mesh and display it using something similar to this demo. Add lighting and a texture. The code in my demo only supports triangular faces. Try and modify it so that works with quadrilateral faces as well.

Also in the computeNormalsDemo directory I wrote a quick example of how to calculate the normals from a face. In the example, I have an array with 4 points (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4). I create 2 vectors (from p1 - p0 and p2 - p0) and then use the cross product to get the normal vector, which is then normalized to be unit length. For your homework, see if you can use this code (or your own version of it) to add correct lighting to a simple 3D shape.

After next week's class we'll start working on some more ambitious and creative projects...

-Angus

Post Reply