This assignment required us to set up the classic ray tracer scene in a graphics API of our choice. We chose to do it in OpenGL within C++. The code was assembled and compiled in linux. You can download the source code and the makefile. You can click on the thumbnail to the right to see a larger image.
The following code describes the location of our camera and the layout of the scene.
void draw()
{
// camera coordinates
gluLookAt(
0,0,-5, // eye
0,0,0, // target
0,1,0 // up axis
);
// the plane
glBegin(GL_QUADS);
glVertex3f(3,-1,6);
glVertex3f(3,-1,-3);
glVertex3f(-1.5,-1,-3);
glVertex3f(-2,-1,6);
glEnd();
// the front sphere
glTranslatef(0, .25, 0);
glutSolidSphere (1.0, 64, 64);
// the rear sphere
glTranslatef(1,-.5,.5);
glutSolidSphere (.75, 64, 64);
}
And we placed the light accordingly.
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
GLfloat light_position[] = { .2, 1.0, 1.0, 0.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
Leaf Corcoran, Adam Damiano
Home