CS40 Lab 5: Cameras and Perspective Transforms

Due 11:59pm Tuesday 7 October 2014

For this lab, you extending project 4 By adding a perspective projection and a camera class for easier navigation.

Getting started
Since you are extending project4, you may continue to use the same git repo as last week.
Code updates
Copy over the camera.h header file and add it to your git repo. As usual, only one partner needs to do the initial copy, add, commit, and push, while the other can pull the changes
[~]$ cd ~/cs40/projects/04
[04]$ cp ~adanner/public/cs40/projects/04/camera.h ./
[04]$ cp ~adanner/public/cs40/projects/04/Readme.txt ./
Edit your projects/04/CMakeLists.txt file to add camera.h to your library headers list
set(SHDRS sphere.h square.h matrixstack.h planet.h camera.h)
When you begin writing your camera.cpp file, you will need to add it to the SSRC line in CMakeLists.txt.
[04]$ git add CMakeLists.txt camera.h Readme.txt
[04]$ git commit -m "project 5 camera class start"
[04]$ git push
Basic Requirements
You will need to implement the Camera class as described. You can add additional methods/member variables, but do not remove the method declarations already in the header.

Use your camera class to specify the camera location for the vertex shader. Add a new uniform mat4 camera variable to your vertex shader. You may want to change the name view to projection as view is a bit more ambiguous in this lab. Your new shader can be as simple as follows

#version 130

uniform vec4 vColor;
uniform mat4 model;
uniform mat4 camera;
uniform mat4 projection;

in vec4 vPosition;
in vec2 vTexture;

out vec4 color;
out vec2 texCoord;

void main() 
{
    gl_Position = projection*camera*model*vPosition;
    color = vColor;
    texCoord = vTexture;

} 
The old rotation stuff will be handled by your camera class.

Instead of m_view being a ortho projection, modify this to be a perspective projection. Feel free to change the name m_view to m_projection or something similar

Connect the m_view/m_projection matrix and your Camera's matrix to the appropriate uniform matrices in your vertex shader.

Add keyboard, mouse, or button controls to support the following:

Document your camera controls. The method showOptions prints the keyboard controls to the screen so the user does not need to read the source to figure out how to navigate. Updating this method to reflect your changes is sufficient documentation.

Additional required feature
The following are possible extensions to the basic requirements. For full credit, you should implement one of these extensions, or get approval for an extension not on the list.
Readme
At the start of lab, you copied over a Readme.txt which contains some conceptual questions and a short survey about the lab. You must answer the conceptual questions and submit your responses along with your code. Feedback on the lab is also requested, but will not effect your grade on the lab in any way.
Hints/Tips

Work incrementally. Start by separating m_view into m_projection and m_camera. You can use QMatrix4x4::perspective to handle m_projection. You can temporarily use QMatrix4x4::lookAt to setup a basic scene and test your shader, but ultimately you want to replace this with your Camera class and its lookAt method which you implement.

Make small changes to your camera and projection matrices. They affect everything, so it is very easy to get completely lost. That's when reset comes in handy. You may want to implement that early.

You can use any of the 'basic' QMatrix4x4 methods. Methods like translate, rotate and scale, modify an existing matrix, by multiplying it on the right. You can use perspective. You cannot use lookAt. You must implement this yourself.

It may be helpful to print a 4x4 matrix. You can get an implementation from

[~]$ cd ~/cs40/projects/04
[04]$ cp ~adanner/public/cs40/projects/04/printmatrix.* ./
Don't forget to update your CMakeLists.txt file
External links
Submit
You should regularly commit your changes and occasionally push to your shared remote. Note you must push to your remote to share updates with your partner. Ideally you should commit changes at the end of every session of working on the project. You will be graded on work that appears in your remote by the project deadline.