MotionPath.setSpeed can now be fed with a negative value to go backward. Waypoints will be properly triggered and the spatial will stop if it reaches the end of the path.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9505 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
c373f70d01
commit
9349bd97c6
@ -59,15 +59,15 @@ public class MotionPath implements Savable {
|
||||
private Node debugNode;
|
||||
private AssetManager assetManager;
|
||||
private List<MotionPathListener> listeners;
|
||||
private Spline spline = new Spline();
|
||||
private float eps = 0.0001f;
|
||||
private Spline spline = new Spline();
|
||||
int prevWayPoint = 0;
|
||||
|
||||
/**
|
||||
* Create a motion Path
|
||||
*/
|
||||
public MotionPath() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* interpolate the path giving the time since the beginnin and the motionControl
|
||||
* this methods sets the new localTranslation to the spatial of the motionTrack control.
|
||||
@ -89,19 +89,29 @@ public class MotionPath implements Savable {
|
||||
//setting values
|
||||
control.setCurrentWayPoint((int) v.x);
|
||||
control.setCurrentValue(v.y);
|
||||
|
||||
|
||||
//interpolating new position
|
||||
getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
if (control.needsDirection()) {
|
||||
tmpVector.set(temp);
|
||||
control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
|
||||
}
|
||||
|
||||
checkWayPoint(control);
|
||||
|
||||
control.getSpatial().setLocalTranslation(temp);
|
||||
vars.release();
|
||||
return traveledDistance;
|
||||
}
|
||||
|
||||
public void checkWayPoint(MotionTrack control) {
|
||||
if (control.getCurrentWayPoint() != prevWayPoint) {
|
||||
if (control.getCurrentValue() >= 0f && control.getCurrentValue() < 0.01) {
|
||||
triggerWayPointReach(control.getCurrentWayPoint(), control);
|
||||
prevWayPoint = control.getCurrentWayPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attachDebugNode(Node root) {
|
||||
if (debugNode == null) {
|
||||
debugNode = new Node();
|
||||
|
||||
@ -161,15 +161,24 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
|
||||
public void update(float tpf) {
|
||||
if (isControl) {
|
||||
internalUpdate(tpf);
|
||||
}
|
||||
}
|
||||
|
||||
if (playState == PlayState.Playing) {
|
||||
time = time + (tpf * speed);
|
||||
|
||||
if (time >= initialDuration && loopMode == loopMode.DontLoop) {
|
||||
stop();
|
||||
} else {
|
||||
onUpdate(tpf);
|
||||
@Override
|
||||
public void internalUpdate(float tpf) {
|
||||
if (playState == PlayState.Playing) {
|
||||
time = time + (tpf * speed);
|
||||
if( loopMode == loopMode.Loop && time<0){
|
||||
time = initialDuration;
|
||||
}
|
||||
if ((time >= initialDuration || time < 0) && loopMode == loopMode.DontLoop) {
|
||||
if (time >= initialDuration) {
|
||||
path.triggerWayPointReach(path.getNbWayPoints() - 1, this);
|
||||
}
|
||||
stop();
|
||||
} else {
|
||||
onUpdate(tpf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,7 +291,6 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
setCurrentWayPoint(path.getNbWayPoints()-1);
|
||||
currentWayPoint = 0;
|
||||
}
|
||||
|
||||
@ -319,10 +327,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
*
|
||||
*/
|
||||
public void setCurrentWayPoint(int currentWayPoint) {
|
||||
if (this.currentWayPoint != currentWayPoint) {
|
||||
this.currentWayPoint = currentWayPoint;
|
||||
path.triggerWayPointReach(currentWayPoint, this);
|
||||
}
|
||||
this.currentWayPoint = currentWayPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
*/
|
||||
package jme3test.animation;
|
||||
|
||||
import com.jme3.animation.LoopMode;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.cinematic.MotionPath;
|
||||
import com.jme3.cinematic.MotionPathListener;
|
||||
@ -83,8 +84,7 @@ public class TestMotionPath extends SimpleApplication {
|
||||
motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
|
||||
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
|
||||
motionControl.setInitialDuration(10f);
|
||||
motionControl.setSpeed(2f);
|
||||
|
||||
motionControl.setSpeed(2f);
|
||||
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
||||
final BitmapText wayPointsText = new BitmapText(guiFont, false);
|
||||
wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
|
||||
@ -105,6 +105,10 @@ public class TestMotionPath extends SimpleApplication {
|
||||
|
||||
flyCam.setEnabled(false);
|
||||
ChaseCamera chaser = new ChaseCamera(cam, teapot);
|
||||
// motionControl.setSpeed(-3f);
|
||||
// motionControl.setLoopMode(LoopMode.Loop);
|
||||
// path.setCycle(true);
|
||||
|
||||
|
||||
// chaser.setEnabled(false);
|
||||
chaser.registerWithInput(inputManager);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user