36: public BranchGroup createSceneGraph(){
37: //create the root of our content scence graph
38: BranchGroup objRoot = new BranchGroup();
39:
40: //create a transform group to rotate the cube
41: //capability bits must be sit to allow changes
42: //once the TransformGroup is part of a live scenegraph
43: TransformGroup objRotate = new TransformGroup();
44: objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
45: objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
46:
47: //attach the transform group and then the cube
48: objRoot.addChild(objRotate);
49: objRotate.addChild(new ColorCube(0.4));
50:
51: //MouseRotate is a utilty class from Sun
52: //a subclass of Behavior
53: //this class references objRotate, so this is the Transform Group
54: //that is affected when we use the mouse
55: //MouseRotate changes the TransformGroup by a rotation
56: //when we right click and drag the mouse
57: //Notice that we must attach a Behavior class to the
58: //scenegraph. This defines a position in space that is
59: //used in conjunction with the scheduling bounds
60: //to determine whether the Behavior is active.
61: //The default constructor for BoundingSphere()
62: //has radius 1.0 centered at the origin
63: MouseRotate mR = new MouseRotate();
64: mR.setTransformGroup(objRotate);
65: mR.setSchedulingBounds(new BoundingSphere());
66: objRoot.addChild(mR);
67:
68: //MouseZoom is a scaling activated by
69: //middle clicking and dragging the mouse
70: MouseZoom mZ = new MouseZoom();
71: mZ.setTransformGroup(objRotate);
72: mZ.setSchedulingBounds(new BoundingSphere());
73: objRoot.addChild(mZ);
74:
75: objRoot.compile();
76:
77: return objRoot;
78: } //end of createSceneGraph method of Simple2
previous
start
toc
next