< Zurück | Inhalt | Weiter >

Example usage of the new behaviors, from MouseNavigateTest.java


//Note that we are creating a TG above the TG that is being

//controlled by the mouse behaviors. The Sun mouse translate behavior

//would fail in this instance because all movement would be in the

//x−y plane irrespective of any TG above the object. The

//TornadoMouseTranslate behavior always moves an object parallel

//to the image plane

TransformGroup objTrans1 = new TransformGroup(); Transform3D t3d = new Transform3D(); objTrans1.getTransform( t3d );

t3d.setEuler( new Vector3d(0.9,0.8,0.3) ); objTrans1.setTransform( t3d );


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


//create the mouse scale behavior and set limits TornadoMouseScale mouseScale = new TornadoMouseScale( 5, 0.1f );

mouseScale.setMinScale( new Point3d( 0.5,0.5,0.5 ) ); mouseScale.setMaxScale( new Point3d( 2,2,2 ) ); mouseScale.setObject( objTrans ); mouseScale.setChangeListener( this ); mouseScale.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseScale );


//create the mouse rotate behavior TornadoMouseRotate mouseRotate =

new TornadoMouseRotate( 0.001, 0.001 ); mouseRotate.setObject( objTrans ); mouseRotate.setChangeListener( this ); mouseRotate.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseRotate );


//create the mouse translate behavior and set limits TornadoMouseTranslate mouseTrans =

new TornadoMouseTranslate( 0.005f ); mouseTrans.setObject( objTrans ); mouseTrans.setChangeListener( this ); mouseTrans.setMinTranslate( new Point3d( −4,−4,−4 ) ); mouseTrans.setMaxTranslate( new Point3d( 4,4,4 ) ); mouseTrans.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseTrans );


//add the small cube

objTrans.addChild( new ColorCube(0.5) );


//create some axes for the world to show it has been rotated,

//and just use a larger wireframe ColorCube ColorCube axis = new ColorCube(5.0); Appearance app = new Appearance();

app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0 ) );

axis.setAppearance( app ); objTrans1.addChild( axis );


//add the TransformGroup we are controlling with the mouse to

//the parent TransformGroup objTrans1.addChild( objTrans );


image