graphicsDeploy index


phase 6:
3d viewing transformations

cs40 assignment 6 web page

overview

this assignment involved implementing 3d viewing transformations (hence the title) and making the appropriate extensions to the modeling system to work in 3d -- transformation matrices are now 4x4, points have x,y, and z, etc. Also, there is a new primitive -- the cube!!! Sadly, due to laziness on my part, circles are currently not drawn, but there's so much other cool stuff going on here that it hardly matters. As usual, documentation is available at the api.


perspective and parallel projections

The general way that both perspective and parallel projections work is to specify a view-reference point somewhere in world space, with associated up-vector and view-plane-normal vector -- this defines a point in space and an orientation from it in which to look. You then need merely transform everything into the canonical view volume, which is a space with all unit boundaries sitting in front of the view point in view coordinates (just some matrix transforms...), then project onto the image plane (either with a parallel or perspective projection), then scale to the image coordinate system in the same way we always have.


implementing view projecetions with cameras

I decided what would be really cool is to have nodes which I can actually insert in my model which act as cameras, from which the view point, up, and normal parameters can be determined. I go into this in more detail in the "using cameras" section of the model.h page of the api, where you can see the code fragment for the animations at the top of the page -- the camera is moving up and down in y, but its view-plane normal is constrained to point at the cube, which is stationary. Essentially the same code fragment was used for both, except that in the second camera_isometric() was called instead to demonstrate parallel projection.


keyable zoom for perspective cameras

In general, the size of the image captured can be manipulated by scaling the camera -- this works for both parallel and perspective projection cameras, and sets the width in u,v coordinates of the viewing window. However, with perspective cameras you get additional control by adjusting the center of projection. In my implementation, currently the system assumes that the center of the window, the view reference point, and the center of projection all sit on the same line, so the only center of projection parameter which remains needing to be set is depth, which is accomplished with the camera's zoom parameter. This is a keyable value, and works much like the keyable transformation nodes. Below is an example of a keyed zoom (refresh browser to animate):


the CUBE!!!

at long last, our first 3d primitive. the unit cube is centered on the origin and each of its edges is 1 unit long. below are two cubes -- both are untransformed unit cubes centered at the origin. in the left-hand image, the cube is viewed from the view reference point (0.0, 0.0, -2.5) with a center of projection at (0.0, 0.0, -4.5), in the right-hand image, the vrp is at (0.5, -1.0, -1.5) and the cop has the same relationship to the vrp as it did on the left. In both images, du = dv = 1.0.


lab questions




graphicsDeploy index