Hi all,
I need an object moving along a spline with constant speed. I tried to achieve this using the MotionPath class but experienced strange bevaviour. The moving box seems to slow down while passing waypoints. Running the code below shows the problem I described.
[java]import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Spline.SplineType;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class InterpolationTest extends SimpleApplication {
@Override
public void simpleInitApp() {
MotionPath path = new MotionPath();
path.addWayPoint(new Vector3f(20, 1, 0));
path.addWayPoint(new Vector3f(20, 1, 5));
path.addWayPoint(new Vector3f(25, 1, 10));
path.addWayPoint(new Vector3f(30, 1, 15));
path.addWayPoint(new Vector3f(35, 1, 15));
path.setPathSplineType(SplineType.CatmullRom);
path.setCurveTension(0.8f);
path.setCycle(false);
path.enableDebugShape(assetManager, rootNode);
Box box = new Box(0.5f, 0.5f, 0.5f);
Geometry g = new Geometry("Box", box);
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
g.setMaterial(mat);
rootNode.attachChild(g);
MotionEvent motionControl = new MotionEvent(g,path);
motionControl.setDirectionType(MotionEvent.Direction.Path);
motionControl.setSpeed(4);
motionControl.play();
motionControl.setLoopMode(LoopMode.Loop);
getCamera().setLocation(new Vector3f(4.7138753f, 6.6103964f, -3.0110395f));
getCamera().setRotation(new Quaternion(0.1379087f, 0.53978395f, -0.09017422f, 0.82551986f));
//getCamera().lookAtDirection(new Vector3f(0.8663331f, -0.32504195f, 0.37922895f), Vector3f.NAN);
}
public static void main(String[] args) {
InterpolationTest wnd = new InterpolationTest();
wnd.start();
}
}[/java]
Setting the spline’s type to Linear or Bezier resolves the issue but I need a smooth curve passing all waypoints so I am stuck with Catmull-Rom.
Thanks for your input!