< Zurück | Inhalt | Weiter >

From TextureTransformTest.java

//create a Box with an applied Texture image

//and a RotationInterpolator to rotate the box protected BranchGroup createSceneBranchGroup()


BranchGroup objRoot = super.createSceneBranchGroup();

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

Transform3D yAxis = new Transform3D();

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

4000, 0, 0,

0, 0, 0);

//create the rotation interpolator to rotate the scene RotationInterpolator rotator =

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

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

//create the box

final int nScale = 50;

Appearance app = new Appearance();

Box box = new Box( nScale, nScale, nScale,


//load the texture image

TextureLoader texLoader = new TextureLoader( "texture.gif", this ); app.setTexture( texLoader.getTexture() );

//set the texture attributes and ensure we can write

//to the Transform for the texture attributes m_TextureAttributes = new TextureAttributes(); m_TextureAttributes.setCapability(

TextureAttributes.ALLOW_TRANSFORM_WRITE ); app.setTextureAttributes( m_TextureAttributes );

//connect all the elements objTrans.addChild( box ); objRoot.addChild( objTrans ); objRoot.addChild( createRotator() );

return objRoot;


//private TransformGroup createRotator()


//create a ColorCube to illustrate the current rotation TransformGroup transTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation( new Vector3d( −70, −70, 50 ) ); transTg.setTransform( t3d );

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

subTg.addChild( new ColorCube(10.0) );

//attach a MouseRotate behavior so we can rotate

//the color cube with the left mouse button MouseRotate mouseRot = new MouseRotate( subTg ); subTg.addChild( mouseRot );

//assign a transformChanged callback, because we want

//to be notified whenever the rotation of the ColorCube changed

//("this" implements MouseBehaviorCallback );

mouseRot.setupCallback( this ); mouseRot.setSchedulingBounds( getApplicationBounds() );

transTg.addChild( subTg ); return transTg;


//this is a callback method that the MouseRotate behavior calls

//when its Transform3D has been modified (by the user)

public void transformChanged(int type, Transform3D transform)


//update the rotation of the TextureAttributes m_TextureAttributes.setTextureTransform( transform );