简体   繁体   English

Java3d行为与运动

[英]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: 使用此框架添加一个扩展Behavior的新类:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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