Fixed MotionTrack setEnabled method

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8954 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 9232c71cd7
commit 1b1bad7da5
  1. 24
      engine/src/core/com/jme3/cinematic/events/MotionTrack.java

@ -69,13 +69,11 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
protected Direction directionType = Direction.None; protected Direction directionType = Direction.None;
protected MotionPath path; protected MotionPath path;
private boolean isControl = true; private boolean isControl = true;
/** /**
* the distance traveled by the spatial on the path * the distance traveled by the spatial on the path
*/ */
protected float traveledDistance = 0; protected float traveledDistance = 0;
/** /**
* Enum for the different type of target direction behavior * Enum for the different type of target direction behavior
*/ */
@ -184,17 +182,17 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
@Override @Override
public void setTime(float time) { public void setTime(float time) {
super.setTime(time); super.setTime(time);
//computing traveled distance according to new time //computing traveled distance according to new time
traveledDistance = time * (path.getLength() / initialDuration); traveledDistance = time * (path.getLength() / initialDuration);
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
Vector3f temp = vars.vect1; Vector3f temp = vars.vect1;
//getting waypoint index and current value from new traveled distance //getting waypoint index and current value from new traveled distance
Vector2f v = path.getWayPointIndexForDistance(traveledDistance); Vector2f v = path.getWayPointIndexForDistance(traveledDistance);
//setting values //setting values
currentWayPoint = (int)v.x; currentWayPoint = (int) v.x;
setCurrentValue(v.y); setCurrentValue(v.y);
//interpolating new position //interpolating new position
path.getSpline().interpolate(getCurrentValue(), getCurrentWayPoint(), temp); path.getSpline().interpolate(getCurrentValue(), getCurrentWayPoint(), temp);
@ -202,8 +200,6 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
spatial.setLocalTranslation(temp); spatial.setLocalTranslation(temp);
vars.release(); vars.release();
} }
public void onUpdate(float tpf) { public void onUpdate(float tpf) {
traveledDistance = path.interpolatePath(time, this); traveledDistance = path.interpolatePath(time, this);
@ -220,7 +216,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
} else { } else {
stop(); stop();
} }
} }
} }
@Override @Override
@ -434,7 +430,11 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
} }
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
play(); if (enabled) {
play();
} else {
pause();
}
} }
public boolean isEnabled() { public boolean isEnabled() {
@ -451,7 +451,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
public Spatial getSpatial() { public Spatial getSpatial() {
return spatial; return spatial;
} }
/** /**
* return the distance traveled by the spatial on the path * return the distance traveled by the spatial on the path
* @return * @return
@ -459,6 +459,4 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
public float getTraveledDistance() { public float getTraveledDistance() {
return traveledDistance; return traveledDistance;
} }
} }

Loading…
Cancel
Save