Next: Hierarchical Data Structures
Up: Hierarchical Models and
Previous: Hierarchical Models and
- How do we model complex objects and scenes?
-
- Describing everything as a single complex model is a
Bad Idea.
- Use hierarchical modeling instead...
- Start with basic set of 3D primitives:
-
Cubes, spheres, prisms ...
- Each is defined in a ``nice'' way in its own space.
- To put primitives together, use transformations.
- Each transformation embeds one space in another.
- Use a whole hierarchy of spaces to build up complex models...
- Not just one ``Model space'', but one for each model
and part of a model.
- Suppose we want two houses.
-
\
- Pictorially we have a DAG
- --a directed acyclic graph.
- We can model this procedurally:
Procedure Scene()
House(B);
House(D);
end
Procedure House(E)
Prism(E o M);
Cube(E o N);
end
Procedure Cube(F)
. . .
end
Procedure Prism(F)
. . .
end
- Implementation:
-
- Procedure calls are making depth first traversal of tree/DAG.
- Use a matrix stack--sometimes maintained in H/W.
- Each time we make an embedding,
- ``Push'' the new transformation onto the matrix stack
- ``Pop'' it on return.
- OpenGL's glPushMatrix call duplicates the top of the stack.
- OpenGL's glMultMatrix multiplies a matrix with the top of
the stack, replacing the top of the stack with the result.
- OpenGL's glPopMatrix pops the stack.
- Stack starts with identity matrix on bottom.
- OpenGL also has transformation calls, such as
glRotate, glScale, etc that perform basic
transformations.
- These transformations operate on the top of the stack.
- Put perspective and world-to-view
matrices into the stack.
- These are pushed on first, giving P V on the bottom.
- Might have more than one stack, i.e. MODEL, VIEW, and
PROJECTION stacks.
\
Code now looks like
Procedure Scene()
MultMatrix(P);
MultMatrix(V);
PushMatrix();
MultMatrix(B);
House();
PopMatrix();
PushMatrix();
MultMatrix(D);
House();
PopMatrix();
end
Procedure House()
PushMatrix();
MultMatrix(M);
Prism();
Popmatrix();
PushMatrix();
MultMatrix(N);
Cube();
Popmatrix();
end
Procedure Cube()
. . .
end
Procedure Prism()
. . .
end
Readings: Hearn and Baker, Chapter 7; IRIS GL programing guide, Chapter 7;
OpenGL Programming Guide, Chapter 3, Manipulating Matrix Stacks;
Red book, Chapter 7;
White book, Chapter 7.
Next: Hierarchical Data Structures
Up: Hierarchical Models and
Previous: Hierarchical Models and
CS488/688: Introduction to Interactive Computer Graphics
University of Waterloo
Computer Graphics Lab
cs488@cgl.uwaterloo.ca