Added an optional pan to SwingPath.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3919 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2006-03-07 22:46:28 +00:00
parent d8276bb4a9
commit af8408fe5d
@@ -30,8 +30,8 @@ import com.threerings.jme.Log;
/** /**
* Swings the camera around a point of interest (which should be somewhere * Swings the camera around a point of interest (which should be somewhere
* along the camera's view vector). Also optionally zooms the camera in or out * along the camera's view vector). Also optionally pans the camera and/or
* (moves it along its view vector) in the process. * zooms it in or out (moves it along its view vector) in the process.
* *
* <p align="center"><img src="rotate_zoom.png"> * <p align="center"><img src="rotate_zoom.png">
*/ */
@@ -51,11 +51,11 @@ public class SwingPath extends CameraPath
public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f axis, public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f axis,
float angle, float angvel, float zoom) float angle, float angvel, float zoom)
{ {
this(camhand, spot, axis, angle, angvel, null, 0f, zoom); this(camhand, spot, axis, angle, angvel, null, 0f, null, zoom);
} }
/** /**
* Creates a rotating, zooming path for the specified camera. * Creates a rotating, panning, zooming path for the specified camera.
* *
* @param spot the point of interest around which to swing the camera. * @param spot the point of interest around which to swing the camera.
* @param paxis the primary axis around which to rotate the camera. * @param paxis the primary axis around which to rotate the camera.
@@ -67,12 +67,13 @@ public class SwingPath extends CameraPath
* <code>null</code> for none * <code>null</code> for none
* @param sangle the angle through which to rotate the camera about the * @param sangle the angle through which to rotate the camera about the
* secondary axis * secondary axis
* @param pan the amount to pan the camera, or <code>null</code> for none
* @param zoom the distance to zoom along the camera's view axis (negative * @param zoom the distance to zoom along the camera's view axis (negative
* = in, positive = out). * = in, positive = out).
*/ */
public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f paxis, public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f paxis,
float pangle, float angvel, Vector3f saxis, float sangle, float pangle, float angvel, Vector3f saxis, float sangle,
float zoom) Vector3f pan, float zoom)
{ {
super(camhand); super(camhand);
@@ -90,13 +91,18 @@ public class SwingPath extends CameraPath
angvel = FastMath.PI; angvel = FastMath.PI;
} }
_spot = spot; _spot = new Vector3f(spot);
_paxis = paxis; _paxis = paxis;
_pangle = pangle; _pangle = pangle;
_pangvel = (pangle > 0) ? angvel : -1 * angvel; _pangvel = (pangle > 0) ? angvel : -1 * angvel;
_saxis = (saxis == null) ? null : new Vector3f(saxis); _saxis = (saxis == null) ? null : new Vector3f(saxis);
_sangle = sangle; _sangle = sangle;
_sangvel = _sangle * _pangvel / _pangle; _sangvel = _sangle * _pangvel / _pangle;
_pan = pan;
if (_pan != null) {
_panvel = _pan.mult(_pangvel / _pangle);
_panned = new Vector3f();
}
_zoom = zoom; _zoom = zoom;
_zoomvel = _zoom * _pangvel / _pangle; _zoomvel = _zoom * _pangvel / _pangle;
@@ -113,7 +119,11 @@ public class SwingPath extends CameraPath
_protated += deltaPAngle; _protated += deltaPAngle;
_srotated += deltaSAngle; _srotated += deltaSAngle;
_zoomed += deltaZoom; _zoomed += deltaZoom;
if (_pan != null) {
_panvel.mult(secondsSince, _deltaPan);
_panned.addLocal(_deltaPan);
}
// clamp our rotation at the target angle and determine whether or not // clamp our rotation at the target angle and determine whether or not
// we're done // we're done
boolean done = false; boolean done = false;
@@ -122,26 +132,37 @@ public class SwingPath extends CameraPath
deltaPAngle -= (_protated - _pangle); deltaPAngle -= (_protated - _pangle);
deltaSAngle -= (_srotated - _sangle); deltaSAngle -= (_srotated - _sangle);
deltaZoom -= (_zoomed - _zoom); deltaZoom -= (_zoomed - _zoom);
if (_pan != null) {
_deltaPan.subtractLocal(_panned).addLocal(_pan);
}
_protated = _pangle; _protated = _pangle;
_srotated = _sangle; _srotated = _sangle;
_panned = _pan;
_zoomed = _zoom; _zoomed = _zoom;
done = true; done = true;
} }
// have the camera handler do the necessary rotating and zooming // have the camera handler do the necessary rotating, panning, zooming
if (_pan != null) {
_camhand.setLocation(
_camhand.getCamera().getLocation().addLocal(_deltaPan));
_spot.addLocal(_deltaPan);
}
_camhand.rotateCamera(_spot, _paxis, deltaPAngle, deltaZoom); _camhand.rotateCamera(_spot, _paxis, deltaPAngle, deltaZoom);
if (_saxis != null) { if (_saxis != null) {
_rot.fromAngleAxis(deltaPAngle, _paxis).multLocal(_saxis); _rot.fromAngleAxis(deltaPAngle, _paxis).multLocal(_saxis);
_camhand.rotateCamera(_spot, _saxis, deltaSAngle, 0f); _camhand.rotateCamera(_spot, _saxis, deltaSAngle, 0f);
} }
return done; return done;
} }
protected Vector3f _spot, _paxis, _saxis; protected Vector3f _spot, _paxis, _saxis;
protected float _pangle, _pangvel, _protated; protected float _pangle, _pangvel, _protated;
protected float _sangle, _sangvel, _srotated; protected float _sangle, _sangvel, _srotated;
protected Vector3f _pan, _panvel, _panned;
protected float _zoom, _zoomvel, _zoomed; protected float _zoom, _zoomvel, _zoomed;
protected Quaternion _rot = new Quaternion(); protected Quaternion _rot = new Quaternion();
protected Vector3f _deltaPan = new Vector3f();
} }