Why this collision detection code don't work?

i define a viewplatform and add it to a transformGroup,and I and the tansformGroup to a branchgroup.I create a collisionBehavior class to detect the collision between view and the 3ds model,I import a 3ds model and add 3ds model to another branchgroup
the code of collisionBehavior is below:
public class collisionBehavior extends Behavior {
private MyTransformGroup collisionObject;
private WakeupOnCollisionEntry wEnter;
private WakeupOnCollisionExit wExit;
public collisionBehavior(MyTransformGroup shape,ViewPlatform viewPlat) {
// super();
collisionObject = shape;
}
public void initialize() {
wEnter = new WakeupOnCollisionEntry(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);
wExit = new WakeupOnCollisionExit(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);
wakeupOn(wEnter);
}
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnCollisionEntry) {
System.out.println(“CollisionEntry…”);
wakeupOn(wExit);/* change the wakeup condition /
} else if (wakeup instanceof WakeupOnCollisionExit) {
collisionObject.setCollision(false);
System.out.println(“CollisionExit…”);
wakeupOn(wEnter);/
change the wakeup condition */
}
}
}
}
the question is why i move the view and cross the wall,but nothing happen…

Well there maybe other problems but first and foremost you will never get notification on time by doing a wakeup on anything but WakeupOnFrame(0). The collision wake-up conditions are totally useless for what I believe you are trying to do.

Only WakeupOnFrame(0) has a guaranteed wakeup time (one call per frame.) Any other wakeup opccurs at some unspecified time AFTER the wakeup confiditon has ocurred. For anything that is timing critical you cannot wait for J3D to wakeup your behavior but must waker up every frame and manually check the critical condition yourself.

Take a look at how JNWN uses behaviors to see more examples of the kind of thing you need to do…

Thank u Jeff,But I can’t find WakeupOnFrame in java3d api,I only find WakeupOnElapsedFrames.

By the way ,could u tell me the different between WakeupOnCollisionEntry and WakeupOnCollisionMovement?

Thats it, I was writing from memory :slight_smile:

Beats me. NONE of the Java3D collision code is useful for games so I’ve never bothered to learn the details.

If you really need to know I could take a look at the docs and or ask one of the Java3D team…

Btw…

In general if you are having trouble with a behavior not seeming to run, check to make sure your activation bounds for the behavior encompass your current camera position. Incorrect activation bounds (or totally missing activation bounds) are a common cause of behavior problems.

I change the code like this:
public class collisionBehavior extends Behavior {
private MyTransformGroup collisionObject;
private WakeupOnCollisionEntry wEnter;
private private WakeupOnElapsedFrames frame;
private WakeupCriterion criterionArray[] = new WakeupCriterion[3];
private WakeupCondition wakeupCondition = null;
public collisionBehavior(MyTransformGroup shape) {
super();
collisionObject = shape;
}
public void initialize() {
wEnter = new WakeupOnCollisionEntry(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);
frame = new WakeupOnElapsedFrames(0);
criterionArray[0] = wEnter;
criterionArray[1] = frame;
wakeupCondition = new WakeupOr(criterionArray);
wakeupOn(wakeupCondition);
}
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnCollisionEntry) {
System.out.println(“CollisionEntry…”);
} else if (wakeup instanceof WakeupOnElapsedFrames) {
System.out.println(“WakeupOnElapsedFrames…”);
}
}
wakeupOn(wakeupCondition)
}
}
but it dose not work…
Could u give me more hint? thank u…

Well, to begin with, your two wakeup conditions make no sense together?

What are you trying to do? if you are trying to detect wall collision to avoid walking through walls you CANNOT use Java3Ds collision dection at all. It just doesnt do what you want. You need to WakeUp OnElapsed Frame(0) and then do your OWN collision tests.

Seperately, how are you using thsi behavior? show me the code thata dds it to your scenegraph and sets its activation bounds…