170 likes | 192 Views
Project 6. Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003. Tumbling Cube. Read the handout . Run Tumbling Cube.exe. The Motion of the Cube. The cube should move in a specified direction at a specified speed. It should also spin on a specified axis at a specified rotation rate.
E N D
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003
Tumbling Cube • Read the handout. • Run Tumbling Cube.exe.
The Motion of the Cube • The cube should move in a specified direction at a specified speed. • It should also spin on a specified axis at a specified rotation rate.
The Motion of the Cube • You should create the following global variables. • A point to store the cube’s position. • A vector to store the direction of motion. • A vector to store the axis of rotation. • A float to store the spin angle of about the axis of rotation.
Animation • The animation will be handled in the idle() function. • This is a callback function that is called whenever nothing else is happening. • The prototype is void idle();
Animation • The function clock() returns the number of milliseconds since the computer was last turned on. • Use clock() to compute the elapsed time since the last call to idle(). • Then update the cube’s position and spin angle.
Animation • New position = old position + direction * elapsed time. • New angle = old angle + spin rate * elapsed time.
Animation • Then determine whether the cube bounced off any of the six faces of the frustum. • If it did, then update the position of the cube.
The View Frustum • The cube will bounce around inside the view frustum.
The View Frustum • Use gluPerspective() to create the projection matrix for this frustum. • You may use any angle, but I think a 90 angle will be easy to work with. • This is the angle between the top and bottom faces of the frustum. • The angle between the sides is determined by this angle and the aspect ratio.
y Top wall What is the equation? What is the intercept? 10 z The Top and Bottom Walls of the Frustum • Assume the angle is 90. • What are the equations of the top and bottom walls?
10*(aspect ratio) x Right wall What is the equation? 10 z The Left and Right Walls of the Frustum • To find the side walls, we must take the aspect ratio into account.
Bouncing off the Walls • The motion is in discrete jumps, so the cube will probably pass through the wall in one of its “jumps.”
Bouncing off the Walls • When the center of the cube “passes through” a wall, we will relocate the center to the point where the cube would be if it bounced off the wall.
Bouncing off the Walls • How do we calculate the new location of the cube? (x2, y2) (x1, y1) (x0, y0) x = a
Pretend wall Real wall Bouncing off the Walls • We will assume that the walls are parallel to the coordinate planes for the purpose of computing the reflected location, even though the wall is at an angle.
Bouncing off the Walls • If we didn’t do that, then the cube might get stuck in a corner.