For this lab, you extending project 4 By adding a perspective projection and a camera class for easier navigation.
[~]$ 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
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.
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