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
This commit is contained in:
Andrzej Kapolka
2006-03-02 01:02:03 +00:00
parent 8039de2dad
commit 69da887537
2 changed files with 70 additions and 20 deletions
@@ -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;
@@ -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
* <code>null</code> 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();
}