C481 B581 Computer Graphics
Dana Vrajitoru
C481/B581 Homework 6

Due date: Thursday, February 27.

Preparation. Download the modified version of the cube programs. The Makefile has been updated to compile these programs with the commands "make cube" and "make cubeview". The executables it creates are "cube" and "cubeview" respectively. The cube program implements a spinning cube using a parallel projection while the cubeview program implements a static cube (spins only when you click the mouse) with a perspective projection and that can be translated with the keys x/X, y/Y, and z/Z. We would like to combine the three features in this homework.
cube1.cc
cubeview.cc
glheader.h
Makefile

Ex. 1. Feature merging
a. Modify the program cubeview.cc to add a function that continuously spins the cube (see glutTimerFunc from cube1.cc), or modify the cube1.cc to use a perspective projection and to add the translation movement with the keys x, y, z (from cubeview.cc).

b. Currently the translation movement uses the vector viewer that is then used in the call to the function gluLookAt in display.

Modify the program such that the gluLookAt call uses only constants (replace the viewer elements with their initial values). This will result in the camera position and the projection not changing when we move the cube.

Then add a call to glTranslatef using the viewer vector, just before the 3 rotations in the function display. This is similar to what we did in Homework 3. This way, the user can move the cube with the x, y, z keys instead of the camera. You can add this movement to the arrow keys too if you want.

Ex. 2. Hypercube

Let's turn this cube into a hypercube, like in the image below:

For this, you'll have to draw a smaller cube inside the first one, for example, with the corners (-0.5, -0.5, -0.5) and (0.5, 0.5, 0.5). Then you'll have to draw lines between the coordinates of each corresponding vertices in each cube. For example, between (-0.5, 0.5, 0.5) and (-1, 1, 1). You can use a single glBegin(GL_LINES) command, where the vertices are provided in pairs forming the lines.

To be able to view the cube inside, for now let's simply display the polygons as lines. If you want to try playing with transparency, that is up to you. The management of the color is also up to you. To make the polygons displayed as lines, you need the function call

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

You can turn it back to a solid mode before the smaller cube inside (if you prefer) with the call

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

Upload to Canvas: source code for both exercises (1 program): either cube1.cc or cubeview.cc.