This week's program animates the robot so that its legs move as if walking and its entire body is translated in the direction its walking. Pressing the arrow keys rotate the robot and change its direction.
I had problems setting the perspective projection. Right now the program
uses an orthographic projection, which means that more distant objects do not
appear smaller. Perspective projections, which use a pyramid-like object called
a frustum to make projections, are more realistic because distant objects look
smaller, while closer objects look bigger. When I used
gluPerspective
to set the frustum, I couldn't find values for the field-of-view angle, near distance, and far distance that would project the robot to a reasonable size.
Right now I'm still using orthographic projections, so when the robot walks toward the viewer, it doesn't look bigger as it approaches.
In last week's program, it seemed that the light followed the robot around
so that the same face was always lit. It seems that this might be because of
the way normals are set up. I used
gluSolidCube
to draw the robot's
parts, so the normals were already set in that built-in function. In the next
few days I'll try redrawing the cubes with polygons and setting my own normals
to see if that problem is fixed.
I have posted a new version of the program as week3-2.tar.gz. The robot is now drawn by using quads
to form cubes that are then scaled. The normals are set manually so that now the lighting is correct. When
the robot rotates, surfaces are lit or dimmened depending on their position. The projection used is now
an perspective projection. When the robot walks towards or away from the viewer, it now changes size depending
on the distance between it and the viewer. It turned out that earlier problems with using
gluPerspective
had been caused by reloading the identity matrix in the Robot::setup() method.
Original week 3 files
(.tar.gz format)
New week 3 files
(.tar.gz format)