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
@ -60,7 +60,7 @@ public class MotionPath implements Savable {
|
|||||||
private AssetManager assetManager;
|
private AssetManager assetManager;
|
||||||
private List<MotionPathListener> listeners;
|
private List<MotionPathListener> listeners;
|
||||||
private Spline spline = new Spline();
|
private Spline spline = new Spline();
|
||||||
private float eps = 0.0001f;
|
int prevWayPoint = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a motion Path
|
* Create a motion Path
|
||||||
@ -96,12 +96,22 @@ public class MotionPath implements Savable {
|
|||||||
tmpVector.set(temp);
|
tmpVector.set(temp);
|
||||||
control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
|
control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
|
||||||
}
|
}
|
||||||
|
checkWayPoint(control);
|
||||||
|
|
||||||
control.getSpatial().setLocalTranslation(temp);
|
control.getSpatial().setLocalTranslation(temp);
|
||||||
vars.release();
|
vars.release();
|
||||||
return traveledDistance;
|
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) {
|
private void attachDebugNode(Node root) {
|
||||||
if (debugNode == null) {
|
if (debugNode == null) {
|
||||||
debugNode = new Node();
|
debugNode = new Node();
|
||||||
|
@ -161,18 +161,27 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
|||||||
|
|
||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (isControl) {
|
if (isControl) {
|
||||||
|
internalUpdate(tpf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void internalUpdate(float tpf) {
|
||||||
if (playState == PlayState.Playing) {
|
if (playState == PlayState.Playing) {
|
||||||
time = time + (tpf * speed);
|
time = time + (tpf * speed);
|
||||||
|
if( loopMode == loopMode.Loop && time<0){
|
||||||
if (time >= initialDuration && loopMode == loopMode.DontLoop) {
|
time = initialDuration;
|
||||||
|
}
|
||||||
|
if ((time >= initialDuration || time < 0) && loopMode == loopMode.DontLoop) {
|
||||||
|
if (time >= initialDuration) {
|
||||||
|
path.triggerWayPointReach(path.getNbWayPoints() - 1, this);
|
||||||
|
}
|
||||||
stop();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
onUpdate(tpf);
|
onUpdate(tpf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initEvent(Application app, Cinematic cinematic) {
|
public void initEvent(Application app, Cinematic cinematic) {
|
||||||
@ -282,7 +291,6 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
setCurrentWayPoint(path.getNbWayPoints()-1);
|
|
||||||
currentWayPoint = 0;
|
currentWayPoint = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,10 +327,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setCurrentWayPoint(int currentWayPoint) {
|
public void setCurrentWayPoint(int currentWayPoint) {
|
||||||
if (this.currentWayPoint != currentWayPoint) {
|
|
||||||
this.currentWayPoint = currentWayPoint;
|
this.currentWayPoint = currentWayPoint;
|
||||||
path.triggerWayPointReach(currentWayPoint, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
package jme3test.animation;
|
package jme3test.animation;
|
||||||
|
|
||||||
|
import com.jme3.animation.LoopMode;
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.cinematic.MotionPath;
|
import com.jme3.cinematic.MotionPath;
|
||||||
import com.jme3.cinematic.MotionPathListener;
|
import com.jme3.cinematic.MotionPathListener;
|
||||||
@ -84,7 +85,6 @@ public class TestMotionPath extends SimpleApplication {
|
|||||||
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
|
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
|
||||||
motionControl.setInitialDuration(10f);
|
motionControl.setInitialDuration(10f);
|
||||||
motionControl.setSpeed(2f);
|
motionControl.setSpeed(2f);
|
||||||
|
|
||||||
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
||||||
final BitmapText wayPointsText = new BitmapText(guiFont, false);
|
final BitmapText wayPointsText = new BitmapText(guiFont, false);
|
||||||
wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
|
wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
|
||||||
@ -105,6 +105,10 @@ public class TestMotionPath extends SimpleApplication {
|
|||||||
|
|
||||||
flyCam.setEnabled(false);
|
flyCam.setEnabled(false);
|
||||||
ChaseCamera chaser = new ChaseCamera(cam, teapot);
|
ChaseCamera chaser = new ChaseCamera(cam, teapot);
|
||||||
|
// motionControl.setSpeed(-3f);
|
||||||
|
// motionControl.setLoopMode(LoopMode.Loop);
|
||||||
|
// path.setCycle(true);
|
||||||
|
|
||||||
|
|
||||||
// chaser.setEnabled(false);
|
// chaser.setEnabled(false);
|
||||||
chaser.registerWithInput(inputManager);
|
chaser.registerWithInput(inputManager);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user