< Zurück | Inhalt | Weiter >

NOTE

This approach would work fine if there were only a few signs in the town but would quickly become unrealistic as the number of signs increased. If the number of signs is large, instead of creating large numbers of Billboard behaviors, which will compromise performance, the orientations of the signs can be manually updated when the view direction is modified.

Alternatively aligned geometry could be used (such as Raster or OrientedShape3D). Behaviors can be computationally intensive and so must be used with care.

The most general method to create a Billboard is:


public Billboard(TransformGroup tg, int mode, Point3f point)


This allows the Billboard to be attached to a graphical object’s TransformGroup, which contains the rotation components that control the orientation of the graphical object.


In addition, two modes of rotation are supported:


ROTATE_ABOUT_AXIS—Specifies that rotation should be about the specified axis.

ROTATE_ABOUT_POINT—Specifies that rotation should be about the specified point and the children’s Y−axis should match the view object’s y axis.


Use ROTATE_ABOUT_AXIS with an axis of (0,1,0) to align billboards in a virtual environments where the user is in a world where +y is up (i.e., where the user is walking through a scene). Use ROTATE_ABOUT_POINT with the point set to the center of desired rotation. This is a useful mode for generalized 3D movement. It rotates around the center of rotation such that +z aligns with the eye and +y aligns with the +y axis of the view. This mode is useful because the text labels are always right side up.


The following code extract creates two 3D text labels and attaches a Billboard behavior to each. The first Billboard is created to ROTATE_ABOUT_AXIS, while the second is created to ROTATE_ABOUT_POINT. The whole scene is then set to rotate about the y axis, using a RotationInterpolator to simulate the scene spinning about the 0,0,0 coordinate—or the camera panning around the scene aimed at the 0,0,0 coordinate. While the RotationInterpolator strives to rotate the scene, the Billboard behaviors attempt to preserve the spatial relationship between the 3D text

labels and the viewer. The Billboard behaviors ensure that the text labels are always facing the viewer. For contrast, a simple cube is created without a Billboard behavior—the cube rotates as expected (figure 11.8).


image


Figure 11.8 Three frames rendered by BillboardTest. Note that although the entire scene is rotating, the Billboard behaviors attached to the two Text3D instances ensure that the Text3D labels are always visible. Some jitter is visible as the labels are rotated before the Billboard behavior can compensate


 

From BillboardTest.java