CS580
HW3 Overview
Transformations
HW3 API function overview
NameList and ValueList are used to send parameters to the renderer
camera params, transforms, etc…
Push/Pop matrix stack functions are needed for HW3
Stack accumulates xforms (on right side) as they are pushed
Render sequence is:
Application creates FB and Rend
renderer builds and pushes Xsp once FB size is known
Application sets camera parameters (position, lookat, up, FOV)
renderer builds Xpi and Xiw and pushes them on stack
a complete Xsw transformation is built on stack for every frame
Application will push/pop Xwm for each object model and pass model triangles to renderer
renderer transforms passed triangles with the current TOS transformation and rasterizes resulting screen-space triangles
Make sure to compute and interpolate screen-z, not model-Z !
Check for z<0 (before divide by w) and skip any triangle with a negative screen-z vertex
App3 Fragments
/* initialize the display and the renderer */
new GzRender(xres, yres);
/* set up app-defined camera if desired, else rely on camera defaults */
camera.position[X] = 13.2; camera.position[Y] = -8.7; camera.position[Z] = -14.8;
camera.lookat[X] = 0.8; camera.lookat[Y] = 0.7; camera.lookat[Z] = 4.5;
camera.worldup[X] = -0.2; camera.worldup[Y] = 1.0; camera.worldup[Z] = 0.0;
camera.FOV = 53.7; /* degrees */
GzPutCamera(camera); /* overwrite default camera (optional) */
GzBeginRender(); /* Once camera is set Renderer gets ready for drawing tris*/
/* set up model matrices as desired */
GzPushMatrix(scale);
GzPushMatrix(rotateY);
GzPushMatrix(rotateX);
/* Walk through the list of triangles, set color and render each triangle */
/* write image file */ GzFlushDisplay2File(outfile);
/* write image to screen*/ GzFlushDisplay2FrameBuffer();
/* Clean up and exit */
HW3
Add the transformation process to your HW2 rastorizer. The files in hw3.zip include:
Gz.h A few new definitions for hw3
Application3.cpp New application that calls your rend.cpp functions
rend.cpp New skeleton file with API definition and comments
tri.asc A one-triangle data file
tri.ppm The result of running app3 on tri.asc with default camera
pot4.asc The Utah teapot triangle data file (in its own model-space coords)
pot4.ppm The result of running app3 on pot4.asc with default camera
pot4.cam.ppm The result of running app3 on pot4.asc with app3 camera
/* Camera defaults are set so the app can omit camera setup if desired */
#define DEFAULT_FOV 35.0 /* use a default look-at point = 0,0,0 and world-up = 0,1,0 */
#define DEFAULT_IM_Z (-10.0) /* world coords for image plane origin (camera origin) */
#define DEFAULT_IM_Y (5.0)
#define DEFAULT_IM_X (-10.0)
You can now change the resolution of your FB image to magnify or shrink the entire image.
Your background color may be different than mine.
“Stress-test" your renderer by changing the camera and look at point with the PutCamera call.
Don't forget to interpolate screen-z, and cull (ignore) triangles that are behind the view plane (negative z vertex coord) after the transformation – test the z-sign before you do the divide by w.
Renderer API (1)
GzRender::GzRender(int xRes, int yRes)
{ /*
- create a renderer structure and allocate pixel and frame buffers
- setup Xsp and anything that is only done once
- init default camera
*/ }
GzRender::~GzRender()
{ /* clean up, free memory */ }
Renderer API (2)
int GzRender::GzBeginRender()
{ /*
- setup for start of each frame - init frame buffer color, alpha, Z
- compute Xiw and projection transform Xpi from camera definition
- init Ximage - put Xsp at base of stack, then push Xpi and Xiw
- now stack contains Xsw and app can push model Xforms when needed
*/ }
int GzRender::GzPutCamera(GzCamera camera)
{ /*
- overwrite renderer camera structure with new camera definition
*/ }
Renderer API (3)
int GzRender::GzPushMatrix(GzMatrix matrix)
{ /*
- push a matrix onto the Ximage stack
- check for stack overflow
*/ }
int GzRender::GzPopMatrix()
{ /*
- pop a matrix off the Ximage stack
- check for stack underflow
*/ }
Renderer API (4)
int GzRender::GzPutAttribute(int numAttributes,
GzToken *nameList, GzPointer *valueList)
{ /*
-- Set renderer attribute states (e.g.: GZ_RGB_COLOR flat shading color)
-- In later homeworks set shaders, interpolaters, texture maps, and lights
*/ }
int GzRender::GzPutTriangle(int numParts,
GzToken *nameList, GzPointer *valueList)
{ /*
-- Pass in a triangle description with tokens and values corresponding to
GZ_NULL_TOKEN: do nothing - no values
GZ_POSITION: 3 vert positions in model space
-- Transform vertex coordinates using current TOS matrix in stack
-- Cull - discard any triangle with verts behind view plane (z < 0)
-- Pass transformed verts to HW2 triangle rasterizer
*/ }
HW3 Results
Pot4cam.ppm pot4.ppm tri.ppm
(app sets camera) (default camera) (default camera)
HW3 Details
The lid and pot are separate parts and not airtight
There is no bottom to the teapot
Exam 1 Thurs Feb 25
No programming, No calculators, No cell phones
Questions on all slides or HW material to this point
Including, but not limited to:
HW1, HW2, HW3
FBs, rasterizers, transformations, …
Linear algebra, rendering transformations, …
Multiple choice, fill-in, draw, describe, how to, …
Emphasis is on reasoning about problems
Allow 1 full class session (most will finish sooner)
Be on time – don’t be late – BB access is limited