A bunch of business related to moving the camera along paths. Also repackaged
camera handling stuff into com.threerings.jme.camera. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3751 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -51,7 +51,8 @@ import com.jme.light.PointLight;
|
|||||||
import com.jme.math.Vector3f;
|
import com.jme.math.Vector3f;
|
||||||
import com.jme.util.Timer;
|
import com.jme.util.Timer;
|
||||||
|
|
||||||
import com.threerings.jme.input.GodViewHandler;
|
import com.threerings.jme.camera.CameraPath;
|
||||||
|
import com.threerings.jme.camera.GodViewHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a basic application framework providing integration with the
|
* Defines a basic application framework providing integration with the
|
||||||
@@ -180,6 +181,27 @@ public class JmeApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the camera moving along a path which will be updated every tick
|
||||||
|
* until it is complete.
|
||||||
|
*/
|
||||||
|
public void moveCamera (CameraPath path)
|
||||||
|
{
|
||||||
|
if (_campath != null) {
|
||||||
|
_campath.abort();
|
||||||
|
}
|
||||||
|
_campath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the camera is currently animating along a path, false if
|
||||||
|
* it is not.
|
||||||
|
*/
|
||||||
|
public boolean cameraIsMoving ()
|
||||||
|
{
|
||||||
|
return (_campath != null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instructs the application to stop the main loop, cleanup and exit.
|
* Instructs the application to stop the main loop, cleanup and exit.
|
||||||
*/
|
*/
|
||||||
@@ -394,6 +416,13 @@ public class JmeApp
|
|||||||
float timePerFrame = _timer.getTimePerFrame();
|
float timePerFrame = _timer.getTimePerFrame();
|
||||||
_root.updateGeometricState(timePerFrame, true);
|
_root.updateGeometricState(timePerFrame, true);
|
||||||
|
|
||||||
|
// if there's a camera path, update that as well
|
||||||
|
if (_campath != null) {
|
||||||
|
if (_campath.tick(timePerFrame)) {
|
||||||
|
_campath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update our stats display if we have one
|
// update our stats display if we have one
|
||||||
if (_stats != null) {
|
if (_stats != null) {
|
||||||
_stats.update(_timer, _display.getRenderer());
|
_stats.update(_timer, _display.getRenderer());
|
||||||
@@ -509,6 +538,7 @@ public class JmeApp
|
|||||||
protected PropertiesIO _properties;
|
protected PropertiesIO _properties;
|
||||||
protected DisplaySystem _display;
|
protected DisplaySystem _display;
|
||||||
protected Camera _camera;
|
protected Camera _camera;
|
||||||
|
protected CameraPath _campath;
|
||||||
|
|
||||||
protected InputHandler _input;
|
protected InputHandler _input;
|
||||||
protected BRootNode _rnode;
|
protected BRootNode _rnode;
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.jme.camera;
|
||||||
|
|
||||||
|
import com.jme.renderer.Camera;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to move the camera along a particular path.
|
||||||
|
*/
|
||||||
|
public abstract class CameraPath
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This is called on every frame to allow the path to adjust the position
|
||||||
|
* of the camera.
|
||||||
|
*
|
||||||
|
* @return true if the path is completed and can be disposed, false if it
|
||||||
|
* is not yet completed.
|
||||||
|
*/
|
||||||
|
public abstract boolean tick (float secondsSince);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called if this path is aborted prior to completion due to being replaced
|
||||||
|
* by a new camera path.
|
||||||
|
*/
|
||||||
|
public void abort ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CameraPath (Camera camera)
|
||||||
|
{
|
||||||
|
_camera = camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Camera _camera;
|
||||||
|
}
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
package com.threerings.jme.input;
|
package com.threerings.jme.camera;
|
||||||
|
|
||||||
import com.jme.math.FastMath;
|
import com.jme.math.FastMath;
|
||||||
import com.jme.math.Matrix3f;
|
import com.jme.math.Matrix3f;
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.jme.camera;
|
||||||
|
|
||||||
|
import com.jme.math.FastMath;
|
||||||
|
import com.jme.math.Matrix3f;
|
||||||
|
import com.jme.math.Vector3f;
|
||||||
|
import com.jme.renderer.Camera;
|
||||||
|
|
||||||
|
import com.threerings.jme.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* (moves it along its view vector) in the process.
|
||||||
|
*
|
||||||
|
* <p align="center"><img src="rotate_zoom.png">
|
||||||
|
*/
|
||||||
|
public class SwingPath extends CameraPath
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a rotating, zooming path for the specified camera.
|
||||||
|
*
|
||||||
|
* @param spot the point of interest around which to swing the camera.
|
||||||
|
* @param axis the axis around which to rotate the camera.
|
||||||
|
* @param angle the angle through which to rotate the camera.
|
||||||
|
* @param angvel the (absolute value of the) velocity at which to rotate
|
||||||
|
* the camera (in radians per second).
|
||||||
|
* @param zoom the distance to zoom along the camera's view axis (negative
|
||||||
|
* = in, positive = out).
|
||||||
|
*/
|
||||||
|
public SwingPath (Camera camera, Vector3f spot, Vector3f axis,
|
||||||
|
float angle, float angvel, float zoom)
|
||||||
|
{
|
||||||
|
super(camera);
|
||||||
|
|
||||||
|
if (angle == 0) {
|
||||||
|
Log.warning("Requested to swing camera through zero degrees " +
|
||||||
|
"[spot=" + spot + ", axis=" + axis +
|
||||||
|
", angvel=" + angvel + ", zoom=" + zoom + "].");
|
||||||
|
angle = 0.0001f;
|
||||||
|
}
|
||||||
|
if (angvel <= 0) {
|
||||||
|
Log.warning("Requested to swing camera with invalid velocity " +
|
||||||
|
"[spot=" + spot + ", axis=" + axis + ", angle=" + angle +
|
||||||
|
", angvel=" + angvel + ", zoom=" + zoom + "].");
|
||||||
|
angvel = FastMath.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
_spot = spot;
|
||||||
|
_axis = axis;
|
||||||
|
_angle = angle;
|
||||||
|
_angvel = (angle > 0) ? angvel : -1 * angvel;
|
||||||
|
_zoom = zoom;
|
||||||
|
_zoomvel = _zoom * _angvel / _angle;
|
||||||
|
|
||||||
|
// Log.info("Swinging camera [angle=" + _angle + ", angvel=" + _angvel +
|
||||||
|
// ", zoom=" + _zoom + ", zoomvel=" + _zoomvel + "].");
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public boolean tick (float secondsSince)
|
||||||
|
{
|
||||||
|
float deltaAngle = (secondsSince * _angvel);
|
||||||
|
float deltaZoom = (secondsSince * _zoomvel);
|
||||||
|
_rotated += deltaAngle;
|
||||||
|
_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);
|
||||||
|
deltaZoom -= (_zoomed - _zoom);
|
||||||
|
_rotated = _angle;
|
||||||
|
_zoomed = _zoom;
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get a vector from the camera's position to the point around which
|
||||||
|
// we're going to orbit
|
||||||
|
Vector3f camloc = _camera.getLocation();
|
||||||
|
Vector3f direction = camloc.subtract(_spot);
|
||||||
|
|
||||||
|
// create a rotation matrix
|
||||||
|
_rotm.fromAxisAngle(_axis, deltaAngle);
|
||||||
|
|
||||||
|
// rotate the center to camera vector and the camera itself
|
||||||
|
_rotm.mult(direction, direction);
|
||||||
|
_rotm.mult(_camera.getUp(), _camera.getUp());
|
||||||
|
_rotm.mult(_camera.getLeft(), _camera.getLeft());
|
||||||
|
_rotm.mult(_camera.getDirection(), _camera.getDirection());
|
||||||
|
|
||||||
|
// and move the camera to its new location (accounting for the zoom)
|
||||||
|
float scale = 1 + (deltaZoom / direction.length());
|
||||||
|
direction.scaleAdd(scale, _spot);
|
||||||
|
_camera.setLocation(direction);
|
||||||
|
_camera.update();
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Vector3f _spot, _axis;
|
||||||
|
protected float _angle, _angvel, _rotated;
|
||||||
|
protected float _zoom, _zoomvel, _zoomed;
|
||||||
|
protected Matrix3f _rotm = new Matrix3f();
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user