\
\
\
Traverse (Node* ptr) { Node *child, *instance; PushMatrix(); MultMatrix(ptr->transform); if (ptr->geom_type == INSTANCE_GEOM) { instance = (Node *) ptr->geom_data; Traverse(instance); } else if (ptr->geom_type == PRIMITIVE_GEOM) { DrawPrimitive(ptr->geom_type, ptr->geom_data); } child = ptr->first_child; while (child != NULL) { Traverse(child); child = child->sibling; } PopMatrix(); }
A3/A4 House Code
gr_transform : scene gr_transform : house gr_polyhedron : prism {...} {...} gr_instance :house roof :prism gr_translate :house:roof {0 0 1} gr_cube :house frame gr_instance :scene farmhouse :house gr_surfaceproperty :scene:farmhouse farmhouse_green gr_instance :scene barn :house gr_surfaceproperty :scene:barn barn_red gr_translate :scene:barn {-2 0 3} gr_rotate :scene:barn rotate "y" 30 gr_scale :scene:barn 2 gr_instance :scene doghouse :house gr_surfaceproperty :scene:barn doghouse_blue gr_translate :scene:barn {-1.5 0 -0.2} gr_rotate :scene:barn rotate "y" -15 gr_scale :scene:barn 0.2
\
\