From 456444da26a62c2cdc5f4c664054bb15328f7459 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 8 Sep 2005 23:45:51 +0000 Subject: [PATCH] Added support for smoothly rotating the camera. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3699 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/jme/input/GodViewHandler.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/jme/input/GodViewHandler.java b/src/java/com/threerings/jme/input/GodViewHandler.java index 653e94c70..83edd15fd 100644 --- a/src/java/com/threerings/jme/input/GodViewHandler.java +++ b/src/java/com/threerings/jme/input/GodViewHandler.java @@ -90,13 +90,41 @@ public class GodViewHandler extends InputHandler return (_camera.getLocation().z - _minZ) / (_maxZ - _minZ); } + /** + * Configures the rotational velocity of the camera, which is used to + * smoothly slide the camera to its new position following a call to + * {@link #rotateCamera}. + */ + public void setRotateVelocity (float radiansPerSecond) + { + _rotateVelocity = radiansPerSecond; + } + /** * Swings the camera around the point on the ground at which it is - * "looking", by the requested angle (in radians). + * "looking", by the requested angle (in radians). The camera does not + * jump by the specified angle but rather smoothly rotates there. */ public void rotateCamera (float deltaAngle) { - rotateCamera(_groundNormal, deltaAngle); + _rotateDelta += deltaAngle; + } + + // documentation inherited + public void update (float time) + { + super.update(time); + + float deltaAngle = 0; + if (_rotateDelta < 0) { + deltaAngle = Math.min(time * _rotateVelocity, -_rotateDelta); + } else if (_rotateDelta > 0) { + deltaAngle = Math.max(-1f * time * _rotateVelocity, -_rotateDelta); + } + if (deltaAngle != 0) { + _rotateDelta += deltaAngle; + rotateCamera(_groundNormal, deltaAngle); + } } protected void setKeyBindings (String api) @@ -350,6 +378,8 @@ public class GodViewHandler extends InputHandler protected Camera _camera; protected Matrix3f _rotm = new Matrix3f(); + protected float _rotateVelocity = 3*FastMath.PI/2, _rotateDelta; + protected float _minX = Float.MIN_VALUE, _maxX = Float.MAX_VALUE; protected float _minY = Float.MIN_VALUE, _maxY = Float.MAX_VALUE; protected float _minZ = Float.MIN_VALUE, _maxZ = Float.MAX_VALUE;