- used tempVars for path interpolation instead of temp attributes
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8463 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
83fd9107c9
commit
854b4a00c0
@ -50,6 +50,7 @@ import com.jme3.scene.VertexBuffer;
|
||||
import com.jme3.scene.shape.Box;
|
||||
import com.jme3.math.Spline.SplineType;
|
||||
import com.jme3.scene.shape.Curve;
|
||||
import com.jme3.util.TempVars;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -66,9 +67,6 @@ public class MotionPath implements Savable {
|
||||
private List<MotionPathListener> listeners;
|
||||
private Spline spline = new Spline();
|
||||
private float eps = 0.0001f;
|
||||
//temp variables to avoid crazy instanciation
|
||||
private Vector3f temp = new Vector3f();
|
||||
private Vector3f tmpVector = new Vector3f();
|
||||
|
||||
/**
|
||||
* Create a motion Path
|
||||
@ -77,26 +75,29 @@ public class MotionPath implements Savable {
|
||||
}
|
||||
|
||||
/**
|
||||
* interpolate the path giving the tpf and the motionControl
|
||||
* interpolate the path giving the tpf and the motionControl
|
||||
* this methods sets the new localTranslation to the spatial of the motionTrack control.
|
||||
* @param tpf
|
||||
* @param control
|
||||
* @return
|
||||
* @param control
|
||||
*/
|
||||
public Vector3f interpolatePath(float tpf, MotionTrack control) {
|
||||
public void interpolatePath(float tpf, MotionTrack control) {
|
||||
|
||||
float val;
|
||||
TempVars vars = TempVars.get();
|
||||
Vector3f temp = vars.vect1;
|
||||
Vector3f tmpVector = vars.vect2;
|
||||
switch (spline.getType()) {
|
||||
case CatmullRom:
|
||||
|
||||
val = tpf * (spline.getTotalLength() / control.getDuration());
|
||||
control.setCurrentValue(control.getCurrentValue() + eps);
|
||||
spline.interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
float dist = getDist(control);
|
||||
float dist = getDist(control,temp, tmpVector);
|
||||
|
||||
while (dist < val) {
|
||||
control.setCurrentValue(control.getCurrentValue() + eps);
|
||||
spline.interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
|
||||
dist = getDist(control);
|
||||
dist = getDist(control,temp, tmpVector);
|
||||
}
|
||||
if (control.needsDirection()) {
|
||||
tmpVector.set(temp);
|
||||
@ -115,10 +116,11 @@ public class MotionPath implements Savable {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return temp;
|
||||
control.getSpatial().setLocalTranslation(temp);
|
||||
vars.release();
|
||||
}
|
||||
|
||||
private float getDist(MotionTrack control) {
|
||||
private float getDist(MotionTrack control,Vector3f temp, Vector3f tmpVector) {
|
||||
tmpVector.set(temp);
|
||||
return tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).length();
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
|
||||
}
|
||||
|
||||
public void onUpdate(float tpf) {
|
||||
spatial.setLocalTranslation(path.interpolatePath(tpf * speed, this));
|
||||
path.interpolatePath(tpf * speed, this);
|
||||
computeTargetDirection();
|
||||
|
||||
if (currentValue >= 1.0f) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user