From 69da8875374460e6249a642c202c202ac0d0f532 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 2 Mar 2006 01:02:03 +0000 Subject: [PATCH] Added a method to disable limits in CameraHandler and an optional second swing axis to SwingPath. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3902 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/jme/camera/CameraHandler.java | 13 +++- .../com/threerings/jme/camera/SwingPath.java | 77 ++++++++++++++----- 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/src/java/com/threerings/jme/camera/CameraHandler.java b/src/java/com/threerings/jme/camera/CameraHandler.java index 698f148d3..a9d84e72d 100644 --- a/src/java/com/threerings/jme/camera/CameraHandler.java +++ b/src/java/com/threerings/jme/camera/CameraHandler.java @@ -98,6 +98,14 @@ public class CameraHandler _maxZ = maxZ; } + /** + * Enables or disables the current set of limits. + */ + public void setLimitsEnabled (boolean enabled) + { + _limitsEnabled = enabled; + } + /** * Sets the camera zoom level to a value between zero (zoomed in maximally) * and 1 (zoomed out maximally). Zoom limits must have already been set up @@ -301,6 +309,9 @@ public class CameraHandler protected Vector3f bound (Vector3f loc) { + if (!_limitsEnabled) { + return loc; + } if (_boundViaFrustum) { bound(_camera.getFrustumLeft(), _camera.getFrustumTop(), loc); bound(_camera.getFrustumLeft(), _camera.getFrustumBottom(), loc); @@ -368,7 +379,7 @@ public class CameraHandler protected Matrix3f _rotm = new Matrix3f(); protected Vector3f _temp = new Vector3f(); - protected boolean _boundViaFrustum; + protected boolean _boundViaFrustum, _limitsEnabled = true; protected float _minX = -Float.MAX_VALUE, _maxX = Float.MAX_VALUE; protected float _minY = -Float.MAX_VALUE, _maxY = Float.MAX_VALUE; protected float _minZ = -Float.MAX_VALUE, _maxZ = Float.MAX_VALUE; diff --git a/src/java/com/threerings/jme/camera/SwingPath.java b/src/java/com/threerings/jme/camera/SwingPath.java index a19f5cff6..ed9856a11 100644 --- a/src/java/com/threerings/jme/camera/SwingPath.java +++ b/src/java/com/threerings/jme/camera/SwingPath.java @@ -22,6 +22,7 @@ package com.threerings.jme.camera; import com.jme.math.FastMath; +import com.jme.math.Quaternion; import com.jme.math.Vector3f; import com.jme.renderer.Camera; @@ -49,28 +50,55 @@ public class SwingPath extends CameraPath */ public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f axis, float angle, float angvel, float zoom) + { + this(camhand, spot, axis, angle, angvel, null, 0f, zoom); + } + + /** + * Creates a rotating, zooming path for the specified 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 pangle the angle through which to rotate the camera about the + * primary axis. + * @param angvel the (absolute value of the) velocity at which to rotate + * the camera (in radians per second) about the primary angle. + * @param saxis the secondary axis around which to rotate the camera, or + * null for none + * @param sangle the angle through which to rotate the camera about the + * secondary axis + * @param zoom the distance to zoom along the camera's view axis (negative + * = in, positive = out). + */ + public SwingPath (CameraHandler camhand, Vector3f spot, Vector3f paxis, + float pangle, float angvel, Vector3f saxis, float sangle, + float zoom) { super(camhand); - if (angle == 0) { + if (pangle == 0) { Log.warning("Requested to swing camera through zero degrees " + - "[spot=" + spot + ", axis=" + axis + + "[spot=" + spot + ", paxis=" + paxis + ", angvel=" + angvel + ", zoom=" + zoom + "]."); - angle = 0.0001f; + pangle = 0.0001f; } if (angvel <= 0) { Log.warning("Requested to swing camera with invalid velocity " + - "[spot=" + spot + ", axis=" + axis + ", angle=" + angle + - ", angvel=" + angvel + ", zoom=" + zoom + "]."); + "[spot=" + spot + ", paxis=" + paxis + ", pangle=" + + pangle + ", angvel=" + angvel + ", zoom=" + zoom + + "]."); angvel = FastMath.PI; } _spot = spot; - _axis = axis; - _angle = angle; - _angvel = (angle > 0) ? angvel : -1 * angvel; + _paxis = paxis; + _pangle = pangle; + _pangvel = (pangle > 0) ? angvel : -1 * angvel; + _saxis = (saxis == null) ? null : new Vector3f(saxis); + _sangle = sangle; + _sangvel = _sangle * _pangvel / _pangle; _zoom = zoom; - _zoomvel = _zoom * _angvel / _angle; + _zoomvel = _zoom * _pangvel / _pangle; // Log.info("Swinging camera [angle=" + _angle + ", angvel=" + _angvel + // ", zoom=" + _zoom + ", zoomvel=" + _zoomvel + "]."); @@ -79,30 +107,41 @@ public class SwingPath extends CameraPath // documentation inherited public boolean tick (float secondsSince) { - float deltaAngle = (secondsSince * _angvel); + float deltaPAngle = (secondsSince * _pangvel); + float deltaSAngle = (secondsSince * _sangvel); float deltaZoom = (secondsSince * _zoomvel); - _rotated += deltaAngle; + _protated += deltaPAngle; + _srotated += deltaSAngle; _zoomed += deltaZoom; // clamp our rotation at the target angle and determine whether or not // we're done boolean done = false; - if (_angle > 0 && _rotated > _angle || - _angle < 0 && _rotated < _angle) { - deltaAngle -= (_rotated - _angle); + if (_pangle > 0 && _protated > _pangle || + _pangle < 0 && _protated < _pangle) { + deltaPAngle -= (_protated - _pangle); + deltaSAngle -= (_srotated - _sangle); deltaZoom -= (_zoomed - _zoom); - _rotated = _angle; + _protated = _pangle; + _srotated = _sangle; _zoomed = _zoom; done = true; } // have the camera handler do the necessary rotating and zooming - _camhand.rotateCamera(_spot, _axis, deltaAngle, deltaZoom); - + _camhand.rotateCamera(_spot, _paxis, deltaPAngle, deltaZoom); + if (_saxis != null) { + _rot.fromAngleAxis(deltaPAngle, _paxis).multLocal(_saxis); + _camhand.rotateCamera(_spot, _saxis, deltaSAngle, 0f); + } + return done; } - protected Vector3f _spot, _axis; - protected float _angle, _angvel, _rotated; + protected Vector3f _spot, _paxis, _saxis; + protected float _pangle, _pangvel, _protated; + protected float _sangle, _sangvel, _srotated; protected float _zoom, _zoomvel, _zoomed; + + protected Quaternion _rot = new Quaternion(); }