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
@@ -9,9 +9,12 @@ import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.util.LoggingSystem;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;
import com.jme.util.LoggingSystem;
import com.threerings.jme.JmeApp;
@@ -24,25 +27,37 @@ public class PathTest extends JmeApp
{
super.initRoot();
float range = 56, muzvel = 24;
float dist = 10;
// set up the camera
Vector3f loc = new Vector3f(range/2, -range*2, 0);
Vector3f loc = new Vector3f(0, -dist, 10);
_camera.setLocation(loc);
Matrix3f rotm = new Matrix3f();
rotm.fromAngleAxis(-FastMath.PI/2, _camera.getLeft());
rotm.fromAngleAxis(-FastMath.PI/4, _camera.getLeft());
rotm.multLocal(_camera.getDirection());
rotm.multLocal(_camera.getUp());
rotm.multLocal(_camera.getLeft());
_camera.update();
Box box = new Box("box", new Vector3f(-1, -1, -1),
new Vector3f(1, 1, 1));
for (int yy = -1; yy < 1; yy++) {
for (int xx = -1; xx < 1; xx++) {
Quad quad = new Quad("ground", 10, 10);
quad.setLightCombineMode(LightState.OFF);
int index = (yy+1)*2 + (xx+1);
quad.setSolidColor(COLORS[index]);
quad.setLocalTranslation(
new Vector3f(xx * 10 + 5, yy * 10 + 5, -1));
_geom.attachChild(quad);
}
}
Box box = new Box("box", new Vector3f(-1, -0.5f, -0.25f),
new Vector3f(1, 0.5f, 0.25f));
_geom.attachChild(box);
Box box2 = new Box("box2", new Vector3f(-1, -1, -1),
new Vector3f(1, 1, 1));
box2.setLocalTranslation(new Vector3f(range, 0, 0));
Box box2 = new Box("box2", new Vector3f(-.1f, -.1f, -.1f),
new Vector3f(.1f, .1f, .1f));
box2.setLocalTranslation(new Vector3f(dist, dist, 0));
_geom.attachChild(box2);
Sprite shot = new Sprite();
@@ -52,15 +67,22 @@ public class PathTest extends JmeApp
Vector3f start = new Vector3f(0, 0, 0);
// start with the "cannon" pointed along the x axis
Vector3f vel = new Vector3f(1, 0, 0);
Vector3f diff = box2.getLocalTranslation().subtract(
box.getLocalTranslation());
Vector3f vel = diff.normalize();
float range = diff.length(), angle = -FastMath.PI/4;
Vector3f axis = UP.cross(vel);
axis.normalizeLocal();
// rotate it up (around the y axis) the necessary elevation
Quaternion rot = new Quaternion();
float angle = BallisticPath.computeElevation(range, muzvel, -9.8f);
rot.fromAngleAxis(angle, new Vector3f(0, 1, 0));
rot.fromAngleAxis(angle, axis);
rot.multLocal(vel);
// give the cannon its muzzle velocity
float muzvel = FastMath.sqrt(range * BallisticPath.G /
FastMath.sin(2*angle));
vel.multLocal(muzvel);
float time = BallisticPath.computeFlightTime(range, muzvel, angle);
@@ -69,6 +91,7 @@ public class PathTest extends JmeApp
System.out.println("Range: " + range);
System.out.println("Muzzle velocity: " + muzvel);
System.out.println("Rotation axis: " + axis);
System.out.println("Angle: " + angle + " (" +
(angle * 180 / FastMath.PI) + ")");
System.out.println("Flight time: " + time);
@@ -86,4 +109,7 @@ public class PathTest extends JmeApp
}
protected static final Vector3f GRAVITY = new Vector3f(0, 0, -9.8f);
protected static final Vector3f UP = new Vector3f(0, 0, 1);
protected static final ColorRGBA[] COLORS = {
ColorRGBA.red, ColorRGBA.green, ColorRGBA.blue, ColorRGBA.gray };
}