< Zurück | Inhalt | Weiter >

12.4.2 Creating the LOD behavior

//create a Switch group that contains two versions of the world:

//The first is a high resolution version, and the second is a

//lower resolution version.

public Group createLodLand( Group g )

{

Switch switchNode = new Switch(); switchNode.setCapability( Switch.ALLOW_SWITCH_WRITE );


Group hiResGroup = createLand( switchNode ); createEnvirons( switchNode );


//Create a DistanceLOD that will select the child

//of the Switch node based on distance. Here we are

//selecting child 0 (high res) if we are closer

//than 180 units to 0,0,0, and child 1 (low res) otherwise. float[] distanceArray = {180};


DistanceLOD distanceLod = new DistanceLOD( distanceArray ); distanceLod.setSchedulingBounds( getApplicationBounds() ); distanceLod.addSwitch( switchNode );


g.addChild( distanceLod ); g.addChild( switchNode );


return hiResGroup;

}