Java Reference
In-Depth Information
for a mouse click. Lastly, the processStimulus() method is supplied for defining the action
to be taken when the event or condition is triggered. In this simple example with only one
triggering condition, no decoding is needed and the processStimulus() method simply in-
creases the value of the TransY variable to move the cube up by a certain amount vertically
Figure 2. Adding SimpleMouseBehavior.java
BG
objRoot
B
myMovementBehavior
TG
objMove
ColorCube
1.
public BranchGroup createSceneGraph()
2.
{
3.
// Create the root of the branch graph
4.
BranchGroup objRoot = new BranchGroup();
5.
Transform3D translate = new Transform3D();
6.
7.
translate.set(new Vector3f(0.0f,-0.3f,0.0f));
8.
9.
TransformGroup objMove = new TransformGroup();
10.
TransformGroup objTrans = new TransformGroup(translate);
11.
12.
objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
13.
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
14.
objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
15.
16.
SimpleMouseMovement myMovementBehavior = new SimpleMouseMovement(objMove);
17.
myMovementBehavior.setSchedulingBounds(new BoundingSphere());
18.
19.
objRoot.addChild(objTrans);
20.
objTrans.addChild(objMove);
21.
objMove.addChild(new ColorCube(0.2));
22.
objMove.addChild(myMovementBehavior);
23.
24.
// Let Java 3D perform optimizations on this scene graph.
25.
objRoot.compile();
26.
27.
return objRoot;
28. }
Search WWH ::




Custom Search