diff --git a/src/java/com/threerings/jme/camera/PanPath.java b/src/java/com/threerings/jme/camera/PanPath.java index 3e55edcbc..ac3fd9dfd 100644 --- a/src/java/com/threerings/jme/camera/PanPath.java +++ b/src/java/com/threerings/jme/camera/PanPath.java @@ -21,7 +21,9 @@ package com.threerings.jme.camera; +import com.jme.math.Quaternion; import com.jme.math.Vector3f; +import com.jme.renderer.Camera; /** * 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 { /** - * 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 duration the number of seconds in which to pan the camera. */ public PanPath (CameraHandler camhand, Vector3f target, float duration) { - super(camhand); - - _start = new Vector3f(camhand.getCamera().getLocation()); - _velocity = target.subtract(_start); - _velocity.divideLocal(duration); - _duration = duration; + this(camhand, target, null, 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 null 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 public boolean tick (float secondsSince) { - _elapsed += secondsSince; - _camloc.scaleAdd(Math.min(_elapsed, _duration), _velocity, _start); + _elapsed = Math.min(_elapsed + secondsSince, _duration); + _camloc.scaleAdd(_elapsed, _velocity, _start); _camhand.setLocation(_camloc); + if (_irot != null) { + _camhand.getCamera().setAxes(_axes.slerp(_irot, _trot, + _elapsed / _duration)); + } return (_elapsed >= _duration); } protected Vector3f _start, _velocity, _camloc = new Vector3f(); + protected Quaternion _irot, _trot, _axes = new Quaternion(); protected float _elapsed, _duration; }