From 854b4a00c030f265608c5b7b10118de670ddcea2 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Wed, 19 Oct 2011 18:42:05 +0000 Subject: [PATCH] - used tempVars for path interpolation instead of temp attributes git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8463 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/cinematic/MotionPath.java | 24 ++++++++++--------- .../jme3/cinematic/events/MotionTrack.java | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/engine/src/core/com/jme3/cinematic/MotionPath.java b/engine/src/core/com/jme3/cinematic/MotionPath.java index a00c36163..4aa0ee915 100644 --- a/engine/src/core/com/jme3/cinematic/MotionPath.java +++ b/engine/src/core/com/jme3/cinematic/MotionPath.java @@ -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 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(); } diff --git a/engine/src/core/com/jme3/cinematic/events/MotionTrack.java b/engine/src/core/com/jme3/cinematic/events/MotionTrack.java index 0f3c1a0c9..d4d931790 100644 --- a/engine/src/core/com/jme3/cinematic/events/MotionTrack.java +++ b/engine/src/core/com/jme3/cinematic/events/MotionTrack.java @@ -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) {