[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Using Objects

After an object has been created, there are several subroutines for using the object in a display.

callobj Subroutine

Once you create an object, use the callobj subroutine to draw it on the screen. Its object parameter takes the numeric identifier of the object you want to draw. The syntax is as follows:

void callobj(Int32 object)

You can use the callobj subroutine to call one object from inside another object. You can draw more complex pictures when you use a hierarchy of simple objects. For example, the following program uses a single callobj (pearl) call to draw the object, a string of pearls, by calling the previously defined object pearl seven times.

Int32 pearl = 1, pearls = 2
makeobj(pearl);
   color(BLUE);
   for(angle=0; angle<3600; angle=angle+300) {
      rotate(300, 'y');
      circ(0.0, 0.0, 1.0);
   }
closeobj();
makeobj(pearls);
   for(i=0; i<7; i=i+1) {
      translate(2.0, 0.0, 0.0);
      color(i);
      callobj(pearl);
    }
closeobj();

The Solarsystem figure shows another example using simple objects to build more complex ones. It defines a solar system as a hierarchical object. Calling one object solarsystem draws all the other objects named in its definition (the sun, the planets, and their orbits).

Solarsystem, a complex object, is defined hierarchically, as shown in the tree diagram. Branches in the tree represent the callobj subroutines.

The system does not save global attributes before the callobj subroutine takes effect. Thus, if an attribute, such as color, changes within an object, the change can affect the caller as well. When needed, use the pushattributes and popattributes subroutines to preserve global attributes.

When a complex object is called, the system draws the whole hierarchy of objects in its definition. For example, in the Solarsystem figure, because the system draws the whole object solarsystem, it can draw objects that are not visible in the viewport. The settings in the bbox2 subroutine determine whether an object is within the viewport and whether it is large enough to be seen.

bbox2 Subroutine

The bbox2 subroutine performs the graphical functions known as pruning and culling. Culling determines which parts of the picture are less than the minimum feature size and, thus, too small to draw on the screen. Pruning calculates whether an object is completely outside the viewport.

The bbox2 subroutine takes as its parameters an object space bounding box in coordinates (given in the x1, y1, x2, y2 parameters) and minimum horizontal and vertical feature sizes (given in the xmin, ymin parameters) in pixels. The system calculates the bounding box, transforms it to screen coordinates, and compares it with the viewport.

If the bounding box is completely outside the viewport, the routines between the bbox2 subroutine and the end of the object are ignored. If the bounding box is within the viewport, the system compares it with the minimum feature size. If it is too small in both the x and y dimensions, the rest of the routines in the object are ignored. Otherwise, the system continues to interpret the object.

The Bounding Boxes figure shows some of the objects within the complex object Solarsystem juxtaposed to specified bounding boxes. The bounding boxes can perform pruning. to determine what objects are partially in the viewport.

Bounding boxes are computed to determine which objects are outside the screen viewport. If the bounding box is entirely outside the viewport, the rest of the object display list is not traversed. The sphere in the bounding box that lies partially within the viewport is drawn and clipped to the edge of the viewport. The syntax is as follows:

void bbox2(Screencoord xmin, Screencoord ymin,
           Coord x1, Coord y1, Coord x2, Coord y2)

[ Previous | Next | Contents | Glossary | Home | Search ]