/** * interpolate the path giving the time since the beginning and the motionControl * this methods sets the new localTranslation to the spatial of the MotionEvent control. * @param time the time since the animation started * @param control the control over the moving spatial */ public float interpolatePath(float time, MotionEvent control, float tpf) { float traveledDistance = 0; TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; Vector3f tmpVector = vars.vect2; Vector2f v = vars.vect2d; //computing traveled distance according to new time traveledDistance = time * (getLength() / control.getInitialDuration()); //getting waypoint index and current value from new traveled distance v = getWayPointIndexForDistance(traveledDistance,v); //setting values control.setCurrentWayPoint((int) v.x); control.setCurrentValue(v.y); //interpolating new position getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp); if (control.needsDirection()) { tmpVector.set(temp); control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal()); } checkWayPoint(control, tpf); control.getSpatial().setLocalTranslation(temp); vars.release(); return traveledDistance; }
/** * interpolate the path giving the time since the beginning and the motionControl * this methods sets the new localTranslation to the spatial of the MotionEvent control. * @param time the time since the animation started * @param control the control over the moving spatial */ public float interpolatePath(float time, MotionEvent control, float tpf) { float traveledDistance = 0; TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; Vector3f tmpVector = vars.vect2; Vector2f v = vars.vect2d; //computing traveled distance according to new time traveledDistance = time * (getLength() / control.getInitialDuration()); //getting waypoint index and current value from new traveled distance v = getWayPointIndexForDistance(traveledDistance,v); //setting values control.setCurrentWayPoint((int) v.x); control.setCurrentValue(v.y); //interpolating new position getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp); if (control.needsDirection()) { tmpVector.set(temp); control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal()); } checkWayPoint(control, tpf); control.getSpatial().setLocalTranslation(temp); vars.release(); return traveledDistance; }