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
3.0
rem..om 13 years ago
parent c373f70d01
commit 9349bd97c6
  1. 12
      engine/src/core/com/jme3/cinematic/MotionPath.java
  2. 19
      engine/src/core/com/jme3/cinematic/events/MotionTrack.java
  3. 6
      engine/src/test/jme3test/animation/TestMotionPath.java

@ -60,7 +60,7 @@ public class MotionPath implements Savable {
private AssetManager assetManager;
private List<MotionPathListener> listeners;
private Spline spline = new Spline();
private float eps = 0.0001f;
int prevWayPoint = 0;
/**
* Create a motion Path
@ -96,12 +96,22 @@ public class MotionPath implements Savable {
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,18 +161,27 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
public void update(float tpf) {
if (isControl) {
internalUpdate(tpf);
}
}
@Override
public void internalUpdate(float tpf) {
if (playState == PlayState.Playing) {
time = time + (tpf * speed);
if (time >= initialDuration && loopMode == loopMode.DontLoop) {
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);
}
}
}
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
@ -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);
}
}
/**

@ -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;
@ -84,7 +85,6 @@ public class TestMotionPath extends SimpleApplication {
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
motionControl.setInitialDuration(10f);
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…
Cancel
Save