Fixed the orienting ballistic path, though it doesn't properly handle

arbitrarily oriented sprites. They currently have to "point" toward (1, 0,
0) as that is the direction that will be aligned with the velocity.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3619 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-06-23 03:49:18 +00:00
parent 732a6512c5
commit 2bf5936317
3 changed files with 64 additions and 38 deletions
@@ -29,6 +29,9 @@ import com.jme.math.Vector3f;
*/
public class BallisticPath extends Path
{
/** Gravity: it's the law. */
public static final float G = -9.8f;
/**
* Moves the supplied sprite from the starting coordinate (which will
* be modified) using the starting velocity, under the specified
@@ -21,8 +21,6 @@
package com.threerings.jme.sprite;
import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
@@ -45,42 +43,41 @@ public class OrientingBallisticPath extends BallisticPath
{
super(sprite, start, velocity, accel, duration);
// rotate the sprite to start
rotate(orient, velocity);
// TODO: handle orient that is not (1, 0, 0)
_orient = orient;
// compute the up vector (opposite of acceleration)
_up = accel.negate();
_up.normalizeLocal();
computeRotation(velocity);
_sprite.getLocalRotation().set(_rotate);
}
// documentation inherited
public void update (float time)
{
// keep track of the old velocity before we update
_ovelocity.set(_velocity);
// do the normal update
super.update(time);
// rotate the sprite accordingly
rotate(_ovelocity, _velocity);
computeRotation(_velocity);
_sprite.getLocalRotation().set(_rotate);
}
protected void rotate (Vector3f oorient, Vector3f norient)
protected void computeRotation (Vector3f velocity)
{
// compute the cross product to get the normal to the plane
// defined by the velocity vectors
oorient.cross(norient, _normal);
// compute the angle between the two vectors
float angle = FastMath.acos(
oorient.dot(norient) / (norient.length() * oorient.length()));
// now use that to compute a rotation matrix from the old to the
// new vector
_rotate.fromAngleAxis(angle, _normal);
// finally rotate the sprite accordingly
_sprite.getLocalRotation().multLocal(_rotate);
_axes[0].set(velocity);
_axes[0].normalizeLocal();
_axes[0].cross(_up, _axes[1]);
_axes[1].normalizeLocal();
_axes[1].cross(_axes[0], _axes[2]);
_axes[2].cross(_axes[0], _axes[1]);
_rotate.fromAxes(_axes);
}
protected Vector3f _ovelocity = new Vector3f();
protected Vector3f _normal = new Vector3f();
protected Vector3f _orient;
protected Vector3f _up;
protected Vector3f[] _axes = {
new Vector3f(), new Vector3f(), new Vector3f() };
protected Quaternion _rotate = new Quaternion();
}