diff options
| author | Phillip <pacardon@u.washington.edu> | 2011-03-14 08:11:16 +0000 | 
|---|---|---|
| committer | Phillip <pacardon@u.washington.edu> | 2011-03-14 08:11:16 +0000 | 
| commit | 3f929048737241331715fbd2ab0db13d8f72b2e1 (patch) | |
| tree | 5ed9d149a846816d656b791d27c80d0e23c994c2 | |
| parent | e3467fc8846e2d91f127f1750d219e2a7eec1f8e (diff) | |
Updated turning code for tank to rotate the shape rather than add/subtract rotational velocity.
Still at a loss on how to accellerate in a given direction :(
| -rw-r--r-- | src/tesseract/objects/tank/Body.java | 5 | ||||
| -rw-r--r-- | src/tesseract/objects/tank/Tank.java | 32 | 
2 files changed, 28 insertions, 9 deletions
| diff --git a/src/tesseract/objects/tank/Body.java b/src/tesseract/objects/tank/Body.java index e67f3c1..bd7e0b0 100644 --- a/src/tesseract/objects/tank/Body.java +++ b/src/tesseract/objects/tank/Body.java @@ -41,6 +41,7 @@ public class Body {  		turretMove.setTranslation(new Vector3f(0, height * theScale, 0));
  		makeTurret(turretColor, theScale, turretMove);
  		barrel.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
 +		
  	}
  	private void makeBody(Color trackColor, Color bodyColor, float theScale) {
 @@ -121,7 +122,7 @@ public class Body {  		return barrel;
  	}
 -	public Vector3f[] getFacing() {
 -		return vectors;
 +	public Vector3f getFacing() {
 +		return vectors[0];
  	}
  }
 diff --git a/src/tesseract/objects/tank/Tank.java b/src/tesseract/objects/tank/Tank.java index b5341c3..f487ba5 100644 --- a/src/tesseract/objects/tank/Tank.java +++ b/src/tesseract/objects/tank/Tank.java @@ -14,7 +14,7 @@ public class Tank extends RemoteObject {  	private final TransformGroup whole;
  	private final TransformGroup turret;
 -	private final Vector3f orientation;
 +	//private final Vector3f orientation;
  	private final Vector3f aim;
  	private final Point3f gunLocation;
  	private static final float DEFAULT_SCALE = 0.0625f;
 @@ -39,7 +39,7 @@ public class Tank extends RemoteObject {  			Color bodyColor, Color trackColor, Color turretColor) {
  		super (thePosition, mass);
  		tank = new Body(trackColor, bodyColor, theScale, turretColor);
 -		orientation = new Vector3f();
 +		//orientation = new Vector3f();
  		aim = new Vector3f();
  		gunLocation = new Point3f();
  		Transform3D turretMove = new Transform3D();
 @@ -50,6 +50,7 @@ public class Tank extends RemoteObject {  		whole = new TransformGroup();
  		whole.addChild(tank.getBody());
  		whole.addChild(turret);
 +		whole.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  		setShape(whole);
  		inverseInertiaTensor.m00 = 1f / 12 / inverseMass * (Body.height * Body.height * theScale + Body.depth * Body.depth * theScale);
  		inverseInertiaTensor.m11 = 1f / 12 / inverseMass * (Body.width * Body.width * theScale + Body.depth * Body.depth * theScale);
 @@ -69,11 +70,13 @@ public class Tank extends RemoteObject {  	}
  	protected void keyEventReceived(final KeyEvent event) {
 -		Transform3D check = new Transform3D();
 -		tank.getBody().getTransform(check);
 -		check.get(orientation);
 +		//Transform3D check = new Transform3D();
 +		//tank.getBody().getTransform(check);
 +		//check.get(orientation);
  		Transform3D current = new Transform3D();
  		turret.getTransform(current);
 +		Transform3D currentOrientation = new Transform3D();
 +		whole.getTransform(currentOrientation);
  		switch (event.getKeyCode()) {
  			case KeyEvent.VK_W:
 @@ -84,11 +87,26 @@ public class Tank extends RemoteObject {  				break;
  			case KeyEvent.VK_A:
 -				angularVelocity.y += STEP;
 +				Transform3D turnLeft = new Transform3D();
 +				turnLeft.rotY(Math.PI / 32);
 +				currentOrientation.mul(turnLeft);
 +				whole.setTransform(currentOrientation);
 +				//orientation.y += Math.PI / 32;
 +				
 +				//angularVelocity.y = 0;
 +				//orientation.normalize();
 +				//System.out.println(orientation.x+ ", " + orientation.y + " " + orientation.z);
  				break;
  			case KeyEvent.VK_D:
 -				angularVelocity.y -= STEP;
 +				Transform3D turnRight = new Transform3D();
 +				turnRight.rotY(-Math.PI / 32);
 +				currentOrientation.mul(turnRight);
 +				whole.setTransform(currentOrientation);
 +				//orientation.y -= Math.PI / 32;
 +				//angularVelocity.y = 0;
 +				//orientation.normalize();
 +				//System.out.println(orientation.x+ ", " + orientation.y + " " + orientation.z);
  				break;
  			case KeyEvent.VK_LEFT:
 | 
