< Zurück | Inhalt | Weiter >

From BillboardTest.java

protected BranchGroup createSceneBranchGroup()


BranchGroup objRoot = super.createSceneBranchGroup();

TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

BoundingSphere bounds = new BoundingSphere( new Point3d(0.0,0.0,0.0), 100.0);

Transform3D yAxis = new Transform3D();

Alpha rotationAlpha = new Alpha(−1, Alpha.INCREASING_ENABLE, 0, 0,

4000, 0, 0,

0, 0, 0);

RotationInterpolator rotator = new RotationInterpolator( rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI*2.0f);

rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator);

objTrans.addChild( createBillboard( "AXIS − 0,1,0", new Point3f( −40.0f, 40.0f, 0.0f ), Billboard.ROTATE_ABOUT_AXIS,

new Point3f( 0.0f, 1.0f, 0.0f ), bounds ) );

objTrans.addChild( createBillboard( "POINT − 10,0,0", new Point3f( 40.0f, 00.0f, 0.0f ), Billboard.ROTATE_ABOUT_POINT,

new Point3f( 10.0f, 0.0f, 0.0f ), bounds ) );

objTrans.addChild( new ColorCube(20.0) ); objRoot.addChild( objTrans );

return objRoot;


//create a Text3D label at a given location and attach a

//Billboard behavior to the label to align it with the Viewer

private TransformGroup createBillboard( String szText, Point3f locationPoint, int nMode, Point3f billboardPoint, BoundingSphere bounds )


TransformGroup subTg = new TransformGroup(); subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

Font3D f3d = new Font3D( new Font( "SansSerif", Font.PLAIN, 10), new FontExtrusion() );

Text3D label3D = new Text3D( f3d, szText, locationPoint ); Shape3D sh = new Shape3D( label3D );

subTg.addChild( sh );

//attach a Billboard behavior to the TransformGroup containing

//the Text3D label

Billboard billboard = new Billboard( subTg, nMode, billboardPoint );

billboard.setSchedulingBounds( bounds ); subTg.addChild( billboard );

return subTg;



Billboard behaviors are great for orienting simple signs or shapes when the viewer is navigating in a walk−through type simulation. Unfortunately, bugs prevent these behaviors from being particularly useful for orienting geometry when faced with generalized pitch, roll, and yaw navigation (you should check this with the latest Java 3D version). Also, Billboards only control the orientation of the geometry they are attached to—they cannot guarantee that the geometry is always visible or consistently scaled. For simple labels, a Raster object positioned in 3D space may be more appropriate depending upon the application and requirements.