简体   繁体   中英

Java3d Behaviors and movement

I would like to move a sphere in a random direction within a simple universe. How could i achieve this with behaviours by changing the location a small amount frame by frame. The reason I am trying to do this is to produce random movement within the universe and eventually build in simple collision detection between the particles.

Any advice/links would be appreciated

Add a new class that extends Behavior, using this skeleton:

public class XXXBehavior extends Behavior
{
    private WakeupCondition wc = new WakeupOnElapsedTimer(1000); // 1000 ms

    public void initialize()
    {
        wakeupOn(wc);
    }

    public void processStimulus(Enumeration criteria)
    {
        // Move the shape here

        // prepare for the next update
        wakeupOn(wc);
    }
}

You later need to instantiate the class and add it to the scene graph. You also need to defined the bounds, otherwise nothing will happen!

xxxEffect = new XXXBehavior();
xxxEffect.setSchedulingBounds(bounds);
sceneBG.addChild(xxxEffect);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM