Project1SP15

From Immersive Visualization Lab Wiki
Revision as of 20:59, 29 March 2015 by Jschulze (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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, April 3rd. 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 in CSB 004 on Monday, March 30th at 4pm.

1. Vector and Matrix Classes (50 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(double x, double y, double z): constructor with three parameters for the vector coordinates
  • Vector3 operator+(const Vector3&): overload operator '+' for addition
  • Vector3 operator-(const Vector3&): overload operator '-' for subtraction
  • void negate(): negation
  • void scale(double s): scale (multiplication with scalar value)
  • double dot(const Vector3&, const Vector3&): dot product, returns result
  • Vector3 cross(const Vector3&, const Vector3&): cross product, returns result and puts it in calling vector
  • double length(): length of the vector
  • void normalize(): normalize the vector (make it so that its length is equal to one)
  • void 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(double x, double y, double z, double w): constructor with four parameters for the vector coordinates
  • Vector4 operator+(const Vector4&): overload operator '+' for addition
  • Vector4 operator-(const Vector4&): overload operator '-' for subtraction
  • void dehomogenize(): dehomogenize the vector (scale it so that its fourth component is equal to one)
  • void 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 Matrix4::operator*(const Matrix4& m2): multiply matrix with matrix
  • Vector4 Matrix4::operator*(const Vector4& v): multiply matrix with vector
  • void Matrix4::identity(): make identity matrix
  • void Matrix4::transpose(): transpose the matrix
  • void Matrix4::makeRotateX(double angle): make rotation matrix about X axis with angle in degrees (note that the sin/cos functions in C++ expect radians so you need to convert to radians within the function)
  • void Matrix4::makeRotateY(double angle): make rotation matrix about Y axis with angle in degrees
  • void Matrix4::makeRotateZ(double angle): make rotation matrix about Z axis with angle in degrees
  • void Matrix4::makeRotate(double angle, const Vector3& axis): Make a rotation matrix about an arbitrary axis
  • void Matrix4::makeScale(double sx, double sy, double sz): make a non-uniform scaling matrix
  • void Matrix4::makeTranslate(double tx, double ty, double tz): make a translation matrix
  • void 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.

  • 't: 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, size and color. (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 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. Give it a velocity vector and make it reflect off the edges of the window 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)