Hi again,
I would like to mention that I changed one of the examples so
that it is supposed to enable the collision detection only when
the user navigates into the virtual world with the mouse (using
the WakeupOnBehaviorPost). When the user stops navigate, then
I change the wakeupOn() to another set of criteria that don't include
collision detection. More specifically, the following class implements
this.
import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.Enumeration;
public class CollisionDetector2 extends Behavior
{
boolean activated = false;
WakeupCriterion [] criterions1;
WakeupCriterion [] criterions2;
WakeupOr wakeup1, wakeup2;
Behavior activator;
Node node;
public CollisionDetector2(Node node, Behavior act){
this.node = node;
activator = act;
}
public void initialize(){
criterions1 = new WakeupCriterion[1];
criterions1[0] = new WakeupOnBehaviorPost(activator, 3);
wakeup1 = new WakeupOr(criterions1);
criterions2 = new WakeupCriterion[4];
criterions2[0] = new WakeupOnCollisionEntry(node,
WakeupOnCollisionEntry.USE_GEOMETRY);
criterions2[1] = new WakeupOnCollisionExit(node,
WakeupOnCollisionEntry.USE_GEOMETRY);
criterions2[2] = new WakeupOnCollisionMovement(node);
criterions2[3] = new WakeupOnBehaviorPost(activator, 4);
wakeup2 = new WakeupOr(criterions2);
wakeupOn(wakeup1);
}
public void processStimulus(Enumeration criteria){
while(criteria.hasMoreElements())
{
WakeupCondition cond = (WakeupCondition) criteria.nextElement();
if(cond instanceof WakeupOnCollisionEntry)
{
WakeupOnCollisionEntry w = (WakeupOnCollisionEntry) cond;
SceneGraphPath p = w.getTriggeringPath();
Node n = p.getObject();
System.out.println("enter "+p+" "+n);
wakeupOn(wakeup2);
}
else if(cond instanceof WakeupOnCollisionExit)
{
System.out.println("exit");
wakeupOn(wakeup2);
}
else if(cond instanceof WakeupOnCollisionMovement)
{
System.out.println("move");
wakeupOn(wakeup2);
}
else if(cond instanceof WakeupOnBehaviorPost)
{
WakeupOnBehaviorPost post = (WakeupOnBehaviorPost) cond;
if (post.getPostId() == 3){
System.out.println("Enabled");
wakeupOn(wakeup2);
}
else if (post.getPostId() == 4){
setEnable(false);
wakeupOn(wakeup1);
setEnable(true);
}
if (criteria.hasMoreElements())
System.out.println("hasMoreElements");
System.out.println("WakeupOnBehaviorPost");
}
}
}
}
But still, even when I deactivate the collision detector, the CPU
utilization is 100%. I thing that the responsible thread for the collision
detection is never stopped. Is it a bug? Please, take a look at it.
Vasilios Darlagiannis
Computer Engineer
Doug Twilleager wrote:
> Almost. Our current implementation of collision detection isn't
> optimal when it comes to CPU utilization. It uses a free running
> thread to check for collisions. We are fixing this in the 1.2 implementation
> of Java 3D. In general, a behavior waking up once per frame isn't a
> bad thing. It will consume CPU, but it shouldn't hit 100%.
>
> Doug Twilleager
> Java 3D Team
>
> > X-Authentication-Warning: capra.eng.sun.com: amith set sender to
> [EMAIL PROTECTED] using -f
> > Subject: Re: [java3d] Processor utilization
> > To: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]
> > MIME-Version: 1.0
> > Content-MD5: qQt2SFZSmzRAHwnEsJng2A==
> >
> >
> > Michael got it right: the 100% CPU utilization happens because Java3D is
> > animating the scene with continuous updates. Using a WakeOnElapsedFrame(0)
> > makes Java3D continously update, since it expects the scene graph to change
> > after each frame, so it wants to display the changes as soon as possible.
> >
> > Doug Gehringer
> > Sun Microsystems
> >
> > > From: "Michael Lorenz" <[EMAIL PROTECTED]>
> > >
> > > I think the 100% utilization occur because all of the behaviors (including
> > > the utility behaviors from sun) are using the WakeupOnElapsedFrame(0) wakeup
> > > criterion which calls the processStimulus() method every single frame.
> > >
> > > Vasilios Darlagiannis wrote:
> > >
> > > > Hi everyone,
> > > > I have tried all the examples about collision detection
> > > > that have been send in the mailing list, but all of them have
> > > > the same problem. They are making 100% utilization of the
> > > > processor and in some more abvance cases this becomes
> > > > a problem. Is it natural that the utilization is 100%? Or
> > > > those examples are missing something?
> > > > I tried to solve the problem by setEnable(b) where b is
> > > > true when the mouseBehavior detects a motion and false
> > > > otherwise, but it didn't work. Does anybody have another idea?
> > > >
> > > > Cheers,
> > > >
> > > > Vasilis
> > > >
> > > >
> > > > =====================================================================
> > > > To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> > > > Java 3D Home Page: http://java.sun.com/products/java-media/3D/
> > > >
> > >
> > > =====================================================================
> > > To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> > > Java 3D Home Page: http://java.sun.com/products/java-media/3D/
> >
> > =====================================================================
> > To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> > Java 3D Home Page: http://java.sun.com/products/java-media/3D/
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/