LookAt and Projections

Wednesday | Friday
More 3D Frames

Readings

Examples updates

Last week we configured the examples repo to work with two remotes. Let's fetch this week's upstream changes.

$ cd ~/cs40/examples
$ git fetch upstream
$ git merge -X ours upstream/master

After this step, you will need to manually edit the top level CMakeLists.txt to add the new subdirectories.

$ tail ~/cs40/examples/CMakeLists.txt

add_subdirectory(w01-intro)
add_subdirectory(w02-opengl)
add_subdirectory(w03-cube)
add_subdirectory(w04-stack-texture)
#add this w05 line
add_subdirectory(w05-projection)

Before compiling, you will need to add a symlink in your w05-projection source folder.

cd ~/cs40/examples/w05-projection
ln -s /usr/local/doc/textures data
cd ..

If everything went well, you should be able to go into your build directory and run make -j8 to compile the week 05 examples.

cd build
make -j8
cd w05-projection
./projection

The o key toggles between an orthographic and perspective projection matrix. The code also uses the lookAt method to construct a view matrix. Note the order of matrix operations in the vertex shader.

uniform mat4 model;   /* move object in world */
uniform mat4 view;    /* transform to eye coordinates */
uniform mat4 project; /* project to clip volume */
...
gl_Position = project * view * model * vPosition;