|
For this assignment you will complete an implementation for a matrix stack. The project is divided into two parts: In Part 1 you will complete functions in the MatrixStack class. These code 'stubs' are indicated for you in the base code, available below. In Part 2 you will reimplement your solar system from project 1 using the matrix stack you just created.
Base Code: proj2.zip
This project will build upon the previous assignment's code. First, be sure to make a copy of your previous assignment. You'll want your solar system code from the main.cpp file. Copy your matrix and vector files into a new folder along with the provided base code.
Files from Proj 1: matrix.h, vector.h, matrix.cpp, vector.cpp, core.h
New files: matrixstack.h, matrixstack.cpp, main.cpp, color.h
For this assignment you will modify the following files: matrixstack.cpp, main.cpp.
Begin by familiarizing yourself with the matrixstack class. Take a peek at the main.cpp file for some sample code regarding the class's intended use.
Next, fill in the following functions to complete the MatrixStack class:
For MatrixStack::Translate, this is not the same as Matrix::Translate. Matrix::Translate performs an outside multiplication ( Trans*M ), whereas this translate performs a right handed multiplication (M * Trans), where Trans is a translation Matrix and M is the current Matrix.
For PushMatrix and PopMatrix, you don't have to check for an index out of bounds error.
Once you have the MatrixStack framework in place, compile and run the program. Again, you should see a spinning cube, like in project 1, except now we are using the stack to translate and rotate this cube. We've also added a Color3 class to this assignment, allowing you to specify three colors to paint each pair of opposite faces. The drawCube function has been altered. It no longer takes in a Matrix argument. Instead, it internally accesses the Matrix at the top of the global MatrixStack and applies that to the vertices before rendering.
Next, take your solar system code from project 1 and transfer it to the new main.cpp file. Make the necessary changes so that your solar system runs with the new stack interface. Do NOT perform any Matrix multiplication directly. For example, you can't use trans1*rot1. Instead, use only the MatrixStack::Translate, MatrixStack::Rotate, and MatrixStack::Scale operations you've just written for the MatrixStack class in Part 1. You're also not allowed to use MatrixStack::MultMatrix directly, although you'll need to implement it to get the telescope to work.
Make the transformation between the Moon hierarchical with respect to the earth, and the earth hierarchical with respect to the sun. When you execute the program, the solar system animation should look identical to your project1 animation.
This last part of the assignment will test your knowledge of vector math. You'll implement two functions to help you position and orient the Hubble telescope, as well as determine if the telescope is facing the sun so it can adjust for exposure.
First, at the bottom of the drawScene function, you'll notice a Point3 variable called pHubble. This represents the fixed position of the telescope in space. Feel free to alter this position, but try to put it outside the orbit somewhere.
Next, just before rendering your Earth cube, add the following line of code:
m_Earth = g_pMatrixStack->Top();
This will store the earth's LocalToWorld matrix which you'll need to position the Hubble.
Next, implement the following functions:
TrackEarth creates the LocalToWorld matrix for the Hubble Telescope. In its local coordinates, the Hubble telescope is located at (0,0,0) and the telescope points along the -Z axis. TrackEarth should extracts the world position of the earth from the m_Earth matrix, and uses this position and pHubble to generate m_Hubble so that the telescope will end up positioned in the world at pHubble, oriented so that its telescope is pointing at the world position of the earth. As a guide, the Hubble telescope model draws a line showing its line of sight (you could think of it as a laser cannon instead of a telescope, if you want). If the tracking is working, this line should always go through the origin of the earth.
Finally, if the telescope is facing the earth and the sun is also in its view, then it must adjust for exposure. We'll simulate this by painting the telescope red. The TestSun function returns a boolean which is true if the origin of the sun is within a 20 degree cone from the lens of the telescope. The telescope is modeled so that it faces down it's local -Z axis, with the lens center exactly at the local origin. If a vector from the sun to the lens is within 20 degrees, then the function returns true (Hint: What Vector-Vector operation gives you the angle between two vectors...or something close).
If 20 degrees is too wide, you may adjust your angle, but make a note of it by altering the comment and code appropriately for the TestSun function. You should position the Hubble at a location so that the telescope turns back and forth from red to black at least once during the earth's orbit.
Here's a screenshot from our solution, which you can also download here proj2.exe:
