1 / 17

Project 6

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.

mwolff
Download Presentation

Project 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003

  2. Tumbling Cube • Read the handout. • Run Tumbling Cube.exe.

  3. 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.

  4. 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.

  5. 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();

  6. 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.

  7. Animation • New position = old position + direction * elapsed time. • New angle = old angle + spin rate * elapsed time.

  8. 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.

  9. The View Frustum • The cube will bounce around inside the view frustum.

  10. 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.

  11. 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?

  12. 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.

  13. Bouncing off the Walls • The motion is in discrete jumps, so the cube will probably pass through the wall in one of its “jumps.”

  14. 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.

  15. Bouncing off the Walls • How do we calculate the new location of the cube? (x2, y2) (x1, y1) (x0, y0) x = a

  16. 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.

  17. Bouncing off the Walls • If we didn’t do that, then the cube might get stuck in a corner.

More Related