2-D Graphic groups

A complex 2D graphic consists of a number of interrelated shapes. A wagon has a body, four wheels, and a handle. When the wagon moves, the wheels rotate and the handle may change position as well. A 2D graphic group lets you create a complex 2D graphic such as a wagon that you can traverse, hit test, transform, and draw as a hierarchical unit.

For example, in the wagon shown in Figure 129, the body consists of four panels and rests on four wheels. When the wagon moves, the wheels move with it, but the wheels also rotate. To translate the body while translating and rotating the wheels, the wagon body is one group and the wheels another group. Since one set of wheels is drawn behind the wagon body away from the viewer's eye and the other set is drawn in front of the body toward the viewer's eye, the wheels are divided into two groups. When the wagon body and wheel groups are adopted into the top-level group, the wheel group that draws away from the viewer's eye is adopted first, followed by the wagon body, followed by the wheel group towards the viewer's eye so that the drawing occurs correctly.

When the TGraphicGroup::Draw function is called, it recursively calls the Draw function for each group or graphic below it in the hierarchy. Each Draw function creates an iterator that traverses one level of the group. Because the draw functions are called recursively, this results in a top-down and depth-first iteration. When a graphic is encountered during the traversal, that graphic and its attribute bundle are sent to the drawing port. The traversal continues until all of the graphics in the group hierarchy have been drawn.


A more complex version of this wagon is created in the code example for this chapter. You might want to refer to the code as you read the discussions below.

Class Architecture
Creating a group
Hit testing a group

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker