Suppose you are modelling classical temples. How do you do it?
At this point you can make a temple, but it's a lot of work. To make it easier, divide and conquer
You get the idea. The result is
What does this look like?
Scene -> First temple -> Stylobate
-> First column -> Generic column -> Base
-> Shaft
-> Capital
-> Second column
-> ...
-> Entablature
-> Second temple /
-> First column /
Make a scene
proc scene
multMatrix(P)
multMatrix(V)
pushMatrix( )
multMatrix(T1)
temple( )
popMatrix( )
pushMatrix( )
multMatrix(T2)
temple( )
popMatrix( )
etc.
Make a temple
proc temple( )
pushMatrix( )
multMatrix(SB)
stylobate( )
popMatrix( )
pushMatrix( )
multMatrix(C1)
column( )
popMatrix( )
pushMatrix( )
multMatrix(C2)
column( )
popMatrix( )
...
pushMatrix( )
multMatrix(En)
entablature( )
popMatrix( )
We don't want always to write a program, so we encapsulate the program as data.
Traverse a DAG
traverse( root )
proc traverse( node ) {
if ( primitve( node ) ) {
draw( node )
} else { for each child {
traverse( child )
}
}
Build a DAG
scene = gr.transform( ) temple1 = gr.transform( ) gr.add_child( temple1, scene ) gr.set_transform( temple1, gr.translation(...)*gr.rotation(...) gr.set_material( temple1, marble ) ... stylobate1 = gr.transform( ) floor = gr.cube( ) gr.add_child( stylobate, floor ) gr.add_child( temple1, stylobate ) gr.set_transform( stylobate, gr.scaling(...) ) column1 = gr.transform( ) gr.add_child( temple1, column1 ) gr.set_transform( column1, gr.translation(...)*gr.scaling(...) ...