Skip to main content

Problem with schedullingBounds

No replies
Joined: 2009-06-07

Hi there!

I need help regarding the schedullingBounds of a custom Behavior class.

Here is the class I've written:

public class CustomBehavior extends Behavior

private TransformGroup tg;
private WakeupOnAWTEvent wakeup = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
private double move = 0.0;
Transform3D trans = new Transform3D();
public CustomBehavior(TransformGroup tg)
{ = tg;

public void initialize()

public void processStimulus(Enumeration criteria)
WakeupOnAWTEvent event = (WakeupOnAWTEvent) criteria.nextElement();
java.awt.AWTEvent[] aev = event.getAWTEvent();
if (aev[0] instanceof KeyEvent)
KeyEvent kev = (KeyEvent) aev[0];
if (kev.getKeyCode() == KeyEvent.VK_RIGHT)
move += 0.1;
System.out.println("Right key pressed : "+move);
} else if (kev.getKeyCode() == KeyEvent.VK_LEFT)
move -= 0.1;
System.out.println("Left key pressed : "+ move);
else if(kev.getKeyCode() == KeyEvent.VK_R)
move = 0.0;
System.out.println("R key pressed : " + move);

trans.setTranslation(new Vector3d(move,0, 0));


Below is the code I use to create the scene graph. I set the schedulling bounds of the custom behavior to be inside the BoundingShpere(new Point3d(),5).

public BranchGroup createSceneGraph()
BranchGroup bg = new BranchGroup();

BoundingSphere bounds = new BoundingSphere(new Point3d(),5);
TransformGroup tg = new TransformGroup();
tg.addChild(new ColorCube(0.4));
CustomBehavior cb = new CustomBehavior(tg);

return bg;

The problem is: when I use the arrow keys to move the color cube it works well, but even if the cube moves out of the bounds set by above BoundingSphere(new Point3d(), 5), the behavior is still active till the move variable is 67. It shouldn't be active after the move variable has exceeded 5, because the behavior moves with the TransformGroup and the schedulling bounds are limited by the sphere with the radius 5. I cannot see the problem.

here is the the problem at self test section of java 3D sun's tutorial:

1. Write a custom behavior application that moves visual objects to the left and right when a the left and
right arrow keys are pressed, respectively. Then use the class in an application similar to Of course, you can use as a starting point for both
the custom behavior class and the application. What happens as the ColorCube object moves out of
the view? How do you fix the problem?

If anybody could help me, I'll appreciate it very much.

Thank you in advance!

Message was edited by: mendi

Message was edited by: mendi

Message was edited by: mendi

Message was edited by: mendi