CS40 Lab 5: Cameras and Perspective Transforms

Due 2:30pm Wednesday 6 March 2013

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, create a local and remote project5 branch by following these steps.
git checkout project4
git checkout -b project5
git push -u private project5
The above commands assume that your personal remote is named private. Furthermore, your working directory must be clean (no uncommitted changes to files under version control), before checking out a new branch. If this is not the case, add and commit you changes locally before switching to a project3 branch.

Once you and your partner have pushed the project5 branches, you can each checkout a shared5 branch to follow your partner's changes

git fetch partner
git checkout -b shared5 partner/project5
Note you should not merge into either the master, shared, or shared5 branches as you will later be unable to push your changes. Make sure you are on either the working or project5 branch before merging.
Starting code
I have pushed a starting camera class camera.h to the master branch. To get this in you project5 branch, follow these steps
git fetch origin
git checkout project5
git merge origin/master
There should only be one file camera.h. It shouldn't cause conflicts, but let me know if you get merge conflicts.
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:

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 it's 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.

External links
Optional features
The following are optional extensions and are not required for full credit.
Submit
You should regularly commit your changes to the project5 branch and occasionally push to your private 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 project5 branch by the project deadline