# CS 184: COMPUTER GRAPHICS

PREVIOUS < - - - - > CS 184 HOME < - - - - > CURRENT < - - - - > NEXT

# Lecture #4 -- Th: 9/9, 2004.

## More on Scene Hierarchy

Last time, Example #1:
Hierarchical Scene Composition and Description
Scene tree, and representation DAG.

### Now: Logical Scene Hierarchy given by functional structure:

How should we structure the hierarchy ? How many objects should be in one group ?
Example #2: Robot
Hierarchical structure is given by kinematic functionality.
Individual pieces are kinematically linked at the joints by suitable transforms.

## 2D Transforms: Matrices, Homogeneous Transforms, Composition.

Transformations are a key element of computer graphics !

### 2D Point Transformations

One possible interpretation of transformations:
An operation on an object as seen from the world coordinate system,
or (in general) from the coordinate system that makes the instance call.
(This is referred to as "command post" or "bird's eye view.")
Demo with coordinate systems overlays on overhead:
Show basic operations;
Emphasize reference point that remains fixed;
Demonstrate effect of consecutive transformations:
Transformations are executed in the order stated !
Order of sequence is important !

### Matrix Representation of Transforms

(There are many possible representations: the SLIDE representation, the "CS 184 shorthand notation", ...).
Matrices are the mathematical representation in your graphics program.
Powerful manipulation formalism exists for automatically combining the effects of several transformations:
Matrix multiplication ! Example: Scaling.
-> Review derivation of Rotation Matrix
(We assume that you are familiar with all this -- if not, go back to your linear algebra text!)

### Homogeneous Coordinates

We also want to do Translation with Matrices.
Not straight-forward (translation is not a "linear operation"!)
Linear transforms: {T(aX + B) = a T(X) + b } always leave origin in place; T(0) = 0.
--> We need clever hack via homogeneous coordinates:
Homogenizing = introduce an extra component: w :  (x, y) ==>  (wx, wy, w)
We can recover the  regular cartesian coordinates by a division with w  (w<>0);
this corresponds to a cut of the homogeneous line with the w=1 plane.
Matrix operation is still linear in d+1 dimension (origin stays in place),
but we are only interested in (hyper-)plane  w=1,
Show the basic translation matrix, demonstrate that it works.
Show all 2D transforms for use with homogeneous column vectors.
Distinguish: Rigid-body transforms  (rotate and translate) and  Affine transforms  (scaling and shear).

#### Other issues of representation of transformations:

Ease of Composition: -- without having to separate out translation part.
Efficiency: number of arithmetic operations: -- homogeneous matrix may not be best !
Abstraction from Implementation: however it is done -- hide it from user !
(e.g., row vectors versus column vectors).

### Row Vectors versus Column Vectors

Matrix representation: for row or column vectors differs by a transposition.
Row vectors have the advantage that subsequent transformation matrices
can be concatenated on the right (post multiplication)
-- but SLIDE/assignments code/explanations use column vectors.
Be aware of what system is used, and don't get confused.
(More on this next time ...)

## Bounding Boxes

It is useful to have some simple Bounds around objects and groups in a scene,
they can serve as:
-- conservative (pessimistic) size estimates (e.g. for culling).
-- crude abstractions for that piece of the scene hierarchy
-- low-LOD (level-of-detail) representations.
-- "place-holders", "Imposters"

Bounding Boxes:
Such bounds should be easy to construct and easy to use.
We typically use axis-aligned bounding boxes: a rectangle with diagonal corners (xmin,ymin), (xmax, ymax).
These AABB's have some inefficiencies: e.g., around a diagonal needle.
Also, with every (rotated) use in a hierarchy, the AABB may grow.

Alternatives to Bounding Boxes:
Optimally oriented bounding boxes (OOBB):  are more efficient but more difficult to determine.
Bounding circles or spheres: have rotation-independent size, but are not so easy to find either.
Convex hulls: can be constructed efficiently, but may have many vertices, --> loss of efficiency.

Use of Bounding Boxes:
Reduction of the amount of computation that needs to be done, e.g.,
Visibility Culling: Is something sure to lie completely outside the viewing frustum ?
Collision detection: Are two objects overlapping ? - (Titanic vs Iceberg).
Clipping: Cut away features outside display rectangle (more next time).
Recursive Use: BBs can be used recursively, forming the BB around the BB's of all children.

Hierarchy, transformations, and bounding boxes are important components in:

## Assignment #3: Hierarchical "Cars and Trucks":

==> Fix your instructional web page -- INDIVIDUALLY -- before Sept. 16.
==> Assignment #3 will be a two-week assignment -- Nevertheless, - start NOW
It will carry twice the number of points (16 instead of 8 points max.).
It will be done WITH A PARTNER !
Pick a partner by Sept. 16.

REMEMBER: ASSIGNMENT#2 is due Monday  Sept. 13, 7:59pm ==> It will serve as the basis for my actual class list.

## Overview of Rendering Process (to provide overall context)

Now that we have a scene, -- how do we a get picture of it?

Review of the Various Coordinate Systems:
Why do we have so many coordinate systems ?
Convenience; separation of concerns; do each task in its most appropriate frame.

Master Space, Model Space, Symbol Space:
Used to define master objects or "symbols" for possible re-use.

World Space, Scene Space:
Hierarchy of (instantiated, transformed) groups and objects.

Rendering Space, Eye Space, Camera Space:
Defines from where do we want to view the scene, what is culled away.

Image Space:
This is the 2D space of the projection screen.
The drawing primitives may be clipped by the "window".

Normalized Device Coordinates:
Fit everything into a unit square for easy manipulation and mapping onto the screen
or into rectangular viewports (= `window' to the laymen) on the screen.

Screen Space:
Pixels or x,y addresses of the actual display device.
Dots, lines, filled areas, etc ... are expressed typically in integers > 0.

### Introduction to the Rendering Pipeline

A simple conceptual pipeline, enumerating the various task.
Following a simple triangle through that simple pipeline.