< Zurück | Inhalt | Weiter >

From LoaderTest.java


protected BranchGroup createSceneBranchGroup()

{

BranchGroup objRoot = super.createSceneBranchGroup();


//create a TransformGroup to flip the hand onto its end

//and enlarge it.

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

tr.rotX(90.0 * Math.PI / 180.0); tr.setScale( 10.0 ); objTrans1.setTransform( tr );


//create a TransformGroup to rotate the hand TransformGroup objTrans2 = new TransformGroup();

objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);


BoundingSphere bounds = new BoundingSphere(

new Point3d(0.0,0.0,0.0), 100.0);


//create a RotationInterpolator behavior to rotate the hand 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, objTrans2, yAxis, 0.0f, (float) Math.PI*2.0f);

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


//Set up the global lights

Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(−1.0f, −1.0f, −1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);


AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds);

DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds);


objRoot.addChild(aLgt); objRoot.addChild(lgt1);


//load the object file Scene scene = null; Shape3D shape = null;


//read in the geometry information from the data file

ObjectFile objFileloader = new ObjectFile( ObjectFile.RESIZE );


try

{

scene = objFileloader.load( "hand1.obj");

}

catch (Exception e)

{

scene = null;

System.err.println(e);

}


if( scene == null ) System.exit(1);


//retrieve the Shape3D object from the scene BranchGroup branchGroup = scene.getSceneGroup(); shape = (Shape3D) branchGroup.getChild(0);


//create an Appearance and Material Appearance app = new Appearance();

Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));


//assign the appearance to the Shape shape.setAppearance( app );


//connect the scenegraph

objTrans2.addChild( scene.getSceneGroup() ); objTrans1.addChild( objTrans2 ); objRoot.addChild( objTrans1 );


return objRoot;

}


image