Added optional target orientation to PanPath.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3840 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.jme.camera;
|
package com.threerings.jme.camera;
|
||||||
|
|
||||||
|
import com.jme.math.Quaternion;
|
||||||
import com.jme.math.Vector3f;
|
import com.jme.math.Vector3f;
|
||||||
|
import com.jme.renderer.Camera;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pans the camera to the specified location in the specified amount of time.
|
* Pans the camera to the specified location in the specified amount of time.
|
||||||
@@ -29,30 +31,57 @@ import com.jme.math.Vector3f;
|
|||||||
public class PanPath extends CameraPath
|
public class PanPath extends CameraPath
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a panning path for the specified camera.
|
* Creates a panning path for the specified camera that will retain the
|
||||||
|
* camera's current orientation.
|
||||||
*
|
*
|
||||||
* @param target the target position for the camera.
|
* @param target the target position for the camera.
|
||||||
* @param duration the number of seconds in which to pan the camera.
|
* @param duration the number of seconds in which to pan the camera.
|
||||||
*/
|
*/
|
||||||
public PanPath (CameraHandler camhand, Vector3f target, float duration)
|
public PanPath (CameraHandler camhand, Vector3f target, float duration)
|
||||||
{
|
{
|
||||||
super(camhand);
|
this(camhand, target, null, duration);
|
||||||
|
|
||||||
_start = new Vector3f(camhand.getCamera().getLocation());
|
|
||||||
_velocity = target.subtract(_start);
|
|
||||||
_velocity.divideLocal(duration);
|
|
||||||
_duration = duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a panning path for the specified camera.
|
||||||
|
*
|
||||||
|
* @param target the target position for the camera.
|
||||||
|
* @param trot the target rotation for the camera (or <code>null</code> to
|
||||||
|
* keep its current orientation)
|
||||||
|
* @param duration the number of seconds in which to pan the camera.
|
||||||
|
*/
|
||||||
|
public PanPath (CameraHandler camhand, Vector3f target, Quaternion trot,
|
||||||
|
float duration)
|
||||||
|
{
|
||||||
|
super(camhand);
|
||||||
|
|
||||||
|
Camera cam = camhand.getCamera();
|
||||||
|
_start = new Vector3f(cam.getLocation());
|
||||||
|
_velocity = target.subtract(_start);
|
||||||
|
_velocity.divideLocal(duration);
|
||||||
|
if (trot != null) {
|
||||||
|
_irot = new Quaternion();
|
||||||
|
_irot.fromAxes(cam.getLeft(), cam.getUp(), cam.getDirection());
|
||||||
|
_trot = trot;
|
||||||
|
}
|
||||||
|
|
||||||
|
_duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public boolean tick (float secondsSince)
|
public boolean tick (float secondsSince)
|
||||||
{
|
{
|
||||||
_elapsed += secondsSince;
|
_elapsed = Math.min(_elapsed + secondsSince, _duration);
|
||||||
_camloc.scaleAdd(Math.min(_elapsed, _duration), _velocity, _start);
|
_camloc.scaleAdd(_elapsed, _velocity, _start);
|
||||||
_camhand.setLocation(_camloc);
|
_camhand.setLocation(_camloc);
|
||||||
|
if (_irot != null) {
|
||||||
|
_camhand.getCamera().setAxes(_axes.slerp(_irot, _trot,
|
||||||
|
_elapsed / _duration));
|
||||||
|
}
|
||||||
return (_elapsed >= _duration);
|
return (_elapsed >= _duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Vector3f _start, _velocity, _camloc = new Vector3f();
|
protected Vector3f _start, _velocity, _camloc = new Vector3f();
|
||||||
|
protected Quaternion _irot, _trot, _axes = new Quaternion();
|
||||||
protected float _elapsed, _duration;
|
protected float _elapsed, _duration;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user