Cinematic changes :
- more consistency in the way to handle time - Complete refactoring of MotionPath interpolation (simpler and way faster) - Time seeking should now work correctly. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9168 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
72561e7a8b
commit
9836918a07
@ -35,6 +35,7 @@ import com.jme3.animation.LoopMode;
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
import com.jme3.asset.TextureKey;
|
||||
import com.jme3.cinematic.events.AbstractCinematicEvent;
|
||||
import com.jme3.cinematic.events.CinematicEvent;
|
||||
import com.jme3.cinematic.events.CinematicEventListener;
|
||||
@ -68,7 +69,6 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
||||
private CameraNode currentCam;
|
||||
private boolean initialized = false;
|
||||
private Map<String, Map<String, Object>> eventsData;
|
||||
private int scheduledPause = -1;
|
||||
|
||||
public Cinematic() {
|
||||
}
|
||||
@ -95,8 +95,6 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
||||
@Override
|
||||
public void onPlay() {
|
||||
if (isInitialized()) {
|
||||
scheduledPause = -1;
|
||||
//enableCurrentCam(true);
|
||||
if (playState == PlayState.Paused) {
|
||||
for (int i = 0; i < cinematicEvents.size(); i++) {
|
||||
CinematicEvent ce = cinematicEvents.get(i);
|
||||
@ -197,22 +195,8 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
||||
}
|
||||
}
|
||||
|
||||
private void step() {
|
||||
if (playState != PlayState.Playing) {
|
||||
play();
|
||||
scheduledPause = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(float tpf) {
|
||||
if (scheduledPause >= 0) {
|
||||
if (scheduledPause == 0) {
|
||||
pause();
|
||||
}
|
||||
scheduledPause--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cinematicEvents.size(); i++) {
|
||||
CinematicEvent ce = cinematicEvents.get(i);
|
||||
ce.internalUpdate(tpf);
|
||||
@ -242,15 +226,16 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
||||
KeyFrame keyFrame = timeLine.get(i);
|
||||
if (keyFrame != null) {
|
||||
for (CinematicEvent ce : keyFrame.getCinematicEvents()) {
|
||||
if (playState == PlayState.Playing) {
|
||||
ce.play();
|
||||
}
|
||||
ce.setTime(time - timeLine.getKeyFrameTime(keyFrame));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (playState != PlayState.Playing) {
|
||||
pause();
|
||||
}
|
||||
|
||||
step();
|
||||
// step();
|
||||
}
|
||||
|
||||
public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) {
|
||||
|
@ -81,56 +81,23 @@ public class MotionPath implements Savable {
|
||||
TempVars vars = TempVars.get();
|
||||
Vector3f temp = vars.vect1;
|
||||
Vector3f tmpVector = vars.vect2;
|
||||
switch (spline.getType()) {
|
||||
case CatmullRom:
|
||||
//computing traveled distance according to new time
|
||||
traveledDistance = time * (getLength() / control.getInitialDuration());
|
||||
|
||||
//this iterative process is done to keep the spatial travel at a constant speed on the path even if
|
||||
//waypoints are not equally spread over the path
|
||||
//getting waypoint index and current value from new traveled distance
|
||||
Vector2f v = getWayPointIndexForDistance(traveledDistance);
|
||||
|
||||
// we compute the theorical distance that the spatial should travel on this frame
|
||||
val = (time * (spline.getTotalLength() / control.getDuration())) - control.getTraveledDistance();
|
||||
//adding and epsilon value to the control currents value
|
||||
control.setCurrentValue(control.getCurrentValue() + eps);
|
||||
//computing the new position at current value
|
||||
spline.interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
//computing traveled distance at current value
|
||||
float dist = getDist(control, temp, tmpVector);
|
||||
//setting values
|
||||
control.setCurrentWayPoint((int) v.x);
|
||||
control.setCurrentValue(v.y);
|
||||
|
||||
//While the distance traveled this frame is below the theorical distance we iterate the obove computation
|
||||
while (dist < val) {
|
||||
//storing the distance traveled this frame
|
||||
traveledDistance = dist;
|
||||
control.setCurrentValue(control.getCurrentValue() + eps);
|
||||
spline.interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
dist = getDist(control, temp, tmpVector);
|
||||
}
|
||||
//compute the direction of the spline
|
||||
//interpolating new position
|
||||
getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
if (control.needsDirection()) {
|
||||
tmpVector.set(temp);
|
||||
control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
|
||||
}
|
||||
//updating traveled distance to the total distance traveled by the spatial since the start
|
||||
traveledDistance += control.getTraveledDistance();
|
||||
break;
|
||||
case Linear:
|
||||
//distance traveled this frame
|
||||
val = (time * (spline.getTotalLength() / control.getDuration())) - control.getTraveledDistance();
|
||||
// computing total traveled distance
|
||||
traveledDistance = control.getTraveledDistance() + val;
|
||||
//computing interpolation ratio for this frame
|
||||
val = val / spline.getSegmentsLength().get(control.getCurrentWayPoint());
|
||||
control.setCurrentValue(Math.min(control.getCurrentValue() + val, 1.0f));
|
||||
//interpolationg position
|
||||
spline.interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
//computing line direction
|
||||
if (control.needsDirection()) {
|
||||
tmpVector.set(spline.getControlPoints().get(control.getCurrentWayPoint() + 1));
|
||||
control.setDirection(tmpVector.subtractLocal(spline.getControlPoints().get(control.getCurrentWayPoint())).normalizeLocal());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
control.getSpatial().setLocalTranslation(temp);
|
||||
vars.release();
|
||||
return traveledDistance;
|
||||
|
@ -39,8 +39,6 @@ import com.jme3.export.InputCapsule;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.JmeImporter;
|
||||
import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.system.NanoTimer;
|
||||
import com.jme3.system.Timer;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -59,12 +57,8 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
protected float initialDuration = 10;
|
||||
protected LoopMode loopMode = LoopMode.DontLoop;
|
||||
protected float time = 0;
|
||||
protected Timer timer;
|
||||
protected float start = 0;
|
||||
/**
|
||||
* the last time the event was paused
|
||||
*/
|
||||
protected float elapsedTimePause = 0;
|
||||
protected boolean resuming = false;
|
||||
|
||||
/**
|
||||
* the list of listeners
|
||||
*/
|
||||
@ -108,12 +102,6 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
public void play() {
|
||||
onPlay();
|
||||
playState = PlayState.Playing;
|
||||
if (timer == null) {
|
||||
//only when used as a control
|
||||
timer = new NanoTimer();
|
||||
}
|
||||
start = timer.getTimeInSeconds();
|
||||
//timer.reset();
|
||||
if (listeners != null) {
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
CinematicEventListener cel = listeners.get(i);
|
||||
@ -157,7 +145,6 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
onStop();
|
||||
time = 0;
|
||||
playState = PlayState.Stopped;
|
||||
elapsedTimePause = 0;
|
||||
if (listeners != null) {
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
CinematicEventListener cel = listeners.get(i);
|
||||
@ -177,7 +164,6 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
public void pause() {
|
||||
onPause();
|
||||
playState = PlayState.Paused;
|
||||
elapsedTimePause = time;
|
||||
if (listeners != null) {
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
CinematicEventListener cel = listeners.get(i);
|
||||
@ -291,8 +277,6 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
* @param cinematic
|
||||
*/
|
||||
public void initEvent(Application app, Cinematic cinematic) {
|
||||
timer = app.getContext().getTimer();
|
||||
//timer = new NanoTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,10 +311,7 @@ public abstract class AbstractCinematicEvent implements CinematicEvent {
|
||||
* @param time the time to fast forward to
|
||||
*/
|
||||
public void setTime(float time) {
|
||||
elapsedTimePause = time / speed;
|
||||
if (playState == PlayState.Playing) {
|
||||
start = timer.getTimeInSeconds();
|
||||
}
|
||||
this.time = time / speed;
|
||||
}
|
||||
|
||||
public float getTime() {
|
||||
|
@ -122,6 +122,7 @@ public class AnimationTrack extends AbstractCinematicEvent {
|
||||
|
||||
}
|
||||
channel.setTime(t);
|
||||
channel.getControl().update(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,10 +165,12 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
if (isControl) {
|
||||
|
||||
if (playState == PlayState.Playing) {
|
||||
time = (elapsedTimePause + timer.getTimeInSeconds() - start) * speed;
|
||||
onUpdate(tpf);
|
||||
time = time + (tpf * speed);
|
||||
|
||||
if (time >= initialDuration && loopMode == loopMode.DontLoop) {
|
||||
stop();
|
||||
} else {
|
||||
onUpdate(tpf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,40 +185,12 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
@Override
|
||||
public void setTime(float time) {
|
||||
super.setTime(time);
|
||||
|
||||
//computing traveled distance according to new time
|
||||
traveledDistance = time * (path.getLength() / initialDuration);
|
||||
|
||||
TempVars vars = TempVars.get();
|
||||
Vector3f temp = vars.vect1;
|
||||
//getting waypoint index and current value from new traveled distance
|
||||
Vector2f v = path.getWayPointIndexForDistance(traveledDistance);
|
||||
//setting values
|
||||
currentWayPoint = (int) v.x;
|
||||
setCurrentValue(v.y);
|
||||
//interpolating new position
|
||||
path.getSpline().interpolate(getCurrentValue(), getCurrentWayPoint(), temp);
|
||||
//setting new position to the spatial
|
||||
spatial.setLocalTranslation(temp);
|
||||
vars.release();
|
||||
onUpdate(0);
|
||||
}
|
||||
|
||||
public void onUpdate(float tpf) {
|
||||
traveledDistance = path.interpolatePath(time, this);
|
||||
computeTargetDirection();
|
||||
|
||||
if (currentValue >= 1.0f) {
|
||||
currentValue = 0;
|
||||
currentWayPoint++;
|
||||
path.triggerWayPointReach(currentWayPoint, this);
|
||||
}
|
||||
if (currentWayPoint == path.getNbWayPoints() - 1) {
|
||||
if (loopMode == LoopMode.Loop) {
|
||||
currentWayPoint = 0;
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -346,7 +320,10 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
*
|
||||
*/
|
||||
public void setCurrentWayPoint(int currentWayPoint) {
|
||||
if (this.currentWayPoint != currentWayPoint) {
|
||||
this.currentWayPoint = currentWayPoint;
|
||||
path.triggerWayPointReach(currentWayPoint, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,7 +115,11 @@ public class SoundTrack extends AbstractCinematicEvent {
|
||||
@Override
|
||||
public void setTime(float time) {
|
||||
super.setTime(time);
|
||||
//TODO has to be implemented in the audioRenderer
|
||||
//can occur on rewind
|
||||
if (time < 0) {
|
||||
stop();
|
||||
}
|
||||
audioNode.setTimeOffset(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user