From 3f929048737241331715fbd2ab0db13d8f72b2e1 Mon Sep 17 00:00:00 2001 From: Phillip Date: Mon, 14 Mar 2011 08:11:16 +0000 Subject: 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 :( --- src/tesseract/objects/tank/Tank.java | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/tesseract/objects/tank/Tank.java') 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: -- cgit v1.2.3