Project 4: Camera Transformations and Frustum Culling

CSE167 W06


For this assignment you will complete an implementation for some basic orthonormal and perspective camera classes. The project is divided into two parts: In Part 1 you will complete code to generate some basic camera transformations, including the inverse camera "lookat" transform and the projection transforms for both the perspective and orthographic cameras. In Part 2 you'll calculate bounding volumes. In Part 3 you will complete code to implement basic bounding sphere frustum culling.

For this assignment, we've also included our solutions to projects 1-3 in a separate zip file.


Files:matrix.h, matrix.cpp, vector.h, vector.cpp, core.h, light.h, light.cpp, geometry.h, geometry.cpp, geomtypes.h, geomtypes.cpp, objfile.h, objfile.cpp

We have also added some additional functionality to the scenegraph and renderer files, such as colors for ShapeNodes. You are free to use your own basecode from previous assignments, but be sure you have the updated (or include the updates from) scenegraph.h/.cpp, rednerer.h and openglrenderer.cpp files.

Base Code:

Files: openglrenderer.cpp, renderer.h, scenegraph.h, scenegraph.cpp, camera.h, camera.cpp, cullingsim.h, cullingsim.cpp, main.cpp.

You'll also need the teapot.obj file from Proj3.

For this assignment you will modify the following files: camera.cpp, geometry.cpp. We recommend coding this assignment in the order listed below.

The program should compile fully when executed for the first time. You shouldn't see anything that makes sense, perhaps a flashing teapot and some circular lines.

Due: Friday, February 10th

Part 1: Projection & Lookat Transformations

Begin by familiarizing yourself with the Camera class, found in camera.h. The Camera class is a base class for two other classes: PerspectiveCam and OrthographicCam, which implement a perspective camera and orthograhic camera, respectively. The functions you'll be completing are defined below:

In the Camera class:

In the PerspectiveCam class:

In the OrthographicCam class:

After filling in the above functions, you should see a teapot model moving left to right with a crude (and inaccurate) bounding sphere. Note, if the program gives you an error like str==0, it may be that the "teapot.obj" file is not in the right directory. If you continue to experience difficulty getting this obj file to load, you may substitute the teapot model for a Cube in the cullingsim.cpp constructor. Do a search for "teapot.obj" and you'll find the single line you need to alter.

At this point, you may want to look at the many keystrokes implemented in this assignment. Check out the console of the project for a description.

Part 2: Bounding Volumes

Here you'll fill in code to calculate the bounding sphere of a Geometry model. Fill in the following function:

In the Geometry class:

When completed, the teapot should now have a much tighter and more accurate bounding sphere.

Part 3: Culling

Next, you'll implement the following functions that do some frustum culling:

In the PerspectiveCam and OrthographicCam class:

In the Camera class:

For the following functions, you may assume that CalcCullingInfo has already been called and that the planes and frustum points stored are correct.

When completed, use the 'x' key to switch between the teapot model and a camera culling simulation. You should see a frustum drawn in the center of the screen. Objects which enter the frustum turn yellow or green depending upon whether they intersect or lie completely in the frustum. The lower left corner shows a view from that culling camera. If implemented correctly, all spheres that appear whole should be green colored.

Additionally, you should be able to rotate the camera with FPS style controls. a and d rotate the camera left to right. w and s move the camera up and down. You can switch between perspective and orthographic culling cameras with the c key. Further, you can also adjust a few camera parameters, like the near clipping plane distance with n and m, or the field of view with f and g for a perspective camera . Below are screenshots from the solution:

Bells & Whistles

Here are a few bells and whistles to try out: