Project1F15

From Immersive Visualization Lab Wiki
Jump to: navigation, search

Contents

Project 1: Moving a Cube

Your project should build on the provided starter code. Before you start with this project, you will need to look through the starter code and get familiar with it.

This project has three parts, but only the first two are mandatory to get full credit (100 points). The number of points you can get for each part is indicated below. In the first part you will need to create C++ classes for vectors and matrices. You will use these classes in the remaining projects throughout the quarter. In the second part of this project you will enable the user to interactively manipulate the cube from the starter code with keyboard keys.

The third part is optional: you are going to have to make the cube bounce.

This project is due on Friday, October 2nd. You will need to present your project in the CSE basement labs starting at 1pm that day.

TA Dylan is going to introduce this homework assignment on Monday, September 28th.

1. Vector and Matrix Classes (54 points)

Start with the spinning cube from the starter code. Part of the project is a class named Matrix4. Use it as a model and implement matrix and vector classes with frequently used functionality.

1a. Vector3 Class (20 Points)

Your Vector3 class must support at least the following functions. You will get 2 points for each function.

  • Vector3::Vector3(float x, float y, float z): constructor with three parameters for the vector coordinates
  • Vector3::operator+(Vector3): overload operator '+' for addition
  • Vector3::operator-(Vector3): overload operator '-' for subtraction
  • Vector3::negate(): negation
  • Vector3::scale(float s): scale (multiplication with scalar value)
  • Vector3::dot(Vector3): dot product, returns result
  • Vector3::cross(Vector3): cross product, returns result
  • Vector3::length() or Vector3::magnitude(): length of the vector
  • Vector3::normalize(): normalize the vector (make it so that its length is equal to one)
  • Vector3::print(string comment): print x, y and z components of the vector after a comment string

1b. Vector4 Class (10 Points)

Your Vector4 class must support at least the following functions. You will get 2 points for each function.

  • Vector4::Vector4(float x, float y, float z, float w): constructor with four parameters for the vector coordinates
  • Vector4::operator+(Vector4): overload operator '+' for addition
  • Vector4::operator-(Vector4): overload operator '-' for subtraction
  • Vector4::dehomogenize(): dehomogenize the vector (scale it so that its fourth component is equal to one)
  • Vector4::print(string comment): print x,y, z and w components of the vector after a comment string

1c. Matrix4 Class (24 Points)

Your Matrix4 class must support at least the following functions. You will get 2 points for each function.

  • Matrix4::Matrix4(): constructor, initializing each matrix element with zero
  • Matrix4::operator*(Matrix4): multiply matrix with matrix
  • Matrix4::operator*(Vector4): multiply matrix with vector
  • Matrix4::identity(): make identity matrix
  • Matrix4::transpose(): transpose the matrix
  • Matrix4::makeRotateX(float angle): make rotation matrix about X axis with angle in radians
  • Matrix4::makeRotateY(float angle): make rotation matrix about Y axis with angle in radians
  • Matrix4::makeRotateZ(float angle): make rotation matrix about Z axis with angle in radians
  • Matrix4::makeRotate(float angle, Vector3 axis): Make a rotation matrix about an arbitrary axis
  • Matrix4::makeScale(float sx, float sy, float sz): make a non-uniform scaling matrix
  • Matrix4::makeTranslate(float tx, float ty, float tz): make a translation matrix
  • Matrix4::print(string comment): print the matrix (display all 16 matrix components numerically on the screen in a 4x4 array)

2. Controlling the Cube (46 points)

Using your vector math classes from part 1, control the cube in various ways with keyboard commands. During this entire time, the cube should keep spinning. The commands should be cumulative, meaning that they build on one another. Never reset the position of the cube or its size, except with the reset command.

Add support for the following keyboard commands to control the cube. You can parse key presses with the glutKeyboardFunc command, for which you can find a tutorial here.

Note that some of the below keyboard commands distinguish between upper and lower case.

  • 'c': toggle the direction of the spin between clockwise and counterclockwise. (5 points)
  • 'x'/'X': move cube left/right by a small amount. (5 points)
  • 'y'/'Y': move cube down/up by a small amount. (5 points)
  • 'z'/'Z': move cube into/out of the screen by a small amount. (5 points)
  • 'r': reset cube position, orientation, and size. (5 points)
  • With every key press, display the new cube position with your Vector3 print method in the text window. (5 points)
  • 'o'/'O': orbit cube about the OpenGL window's z axis by a small number of degrees (e.g., 10) per key press, counterclockwise ('o') or clockwise ('O'). The z axis crosses the screen in the center of the OpenGL window. This rotation should not affect the spin other than that it will rotate the spin axis with the cube. (10 points)
  • 's'/'S': scale cube down/up (about its center, not the center of the screen). To scale up means to make it bigger (6 points)

3. Optional: Bouncing Ball (10 Points)

Use the Sphere class or glutSolidSphere() function to create a ball. Switch between the ball and the cube with the 'b' key.

In "Ball" mode, you don't need to support any of the functionality from part 2. What you need to do is to make the ball bounce in all 3 dimensions. Give it an initial velocity vector which is non-zero in all three dimensions and make the ball reflect off the edges of the window and suitable, invisible walls parallel to the monitor in front and back so it looks like it bounces around the window, moving around on straight lines. (7 Points)

To make the bouncing motion more realistic, make it look like the ball is getting pulled down by gravity by adding a constant down vector to your velocity every time you update it. You could even make it lose energy at every bounce, so that it eventually stops moving. (3 Points)