diff options
author | Steve <steveb9@u.washington.edu> | 2011-03-17 06:39:42 +0000 |
---|---|---|
committer | Steve <steveb9@u.washington.edu> | 2011-03-17 06:39:42 +0000 |
commit | 6d11be84e237ddc8302f3df9b08651ed5923c9b5 (patch) | |
tree | b31cb3d7814d9e5b3cb70d36d5f039e166da3e75 /src/tesseract | |
parent | 9b3febff8a2f2d920d98b420bc3553206d597b50 (diff) |
blimp roll, up down
Diffstat (limited to 'src/tesseract')
-rw-r--r-- | src/tesseract/objects/blimp/Blimp.java | 171 | ||||
-rw-r--r-- | src/tesseract/objects/blimp/BlimpBox.java | 4 | ||||
-rw-r--r-- | src/tesseract/objects/blimp/BlimpFin.java | 4 |
3 files changed, 160 insertions, 19 deletions
diff --git a/src/tesseract/objects/blimp/Blimp.java b/src/tesseract/objects/blimp/Blimp.java index 836ef41..bdc62d0 100644 --- a/src/tesseract/objects/blimp/Blimp.java +++ b/src/tesseract/objects/blimp/Blimp.java @@ -28,6 +28,12 @@ import com.sun.j3d.utils.geometry.Primitive; import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.image.TextureLoader;
+/**
+ * This class builds a blimp and the controls for it.
+ *
+ * @author Steve Bradshaw
+ *
+ */
public class Blimp extends RemoteObject {
KeyInfo lastEvent;
@@ -57,6 +63,7 @@ public class Blimp extends RemoteObject { * @param position Initial position.
* @param scale determine the size of the blimp
* @param theColor of object.
+ * @author Steve Bradshaw
*/
public Blimp(final Vector3f position, final float scale) {
super(position, DEFAULT_MASS);
@@ -87,6 +94,7 @@ public class Blimp extends RemoteObject { * @param b float in the ellipsoid formula.
* @param c float in the ellipsoid formula.
* @return TransformGroup with the shape.
+ * @author Steve Bradshaw
*/
private TransformGroup create( final float a,
final float b, final float c) {
@@ -232,7 +240,7 @@ public class Blimp extends RemoteObject { /**
* This controls the blimp. Most of it was written by Phillip Cardon for the Tank
- * and modified to fit the blimp since it can move up or down
+ * and modified to fit the blimp since it can move up or down and roll
*
* @author Phillip Cardon, Steve Bradshaw
*/
@@ -243,6 +251,8 @@ public class Blimp extends RemoteObject { my_blimp.getTransform(currentOrientation);
Transform3D turnRight = new Transform3D();
Transform3D turnLeft = new Transform3D();
+ Transform3D turnUp = new Transform3D();
+ Transform3D turnDown = new Transform3D();
Vector3f facing = new Vector3f(vectors[0]);
Transform3D faceTrans = new Transform3D();
my_blimp.getTransform(faceTrans);
@@ -257,30 +267,49 @@ public class Blimp extends RemoteObject { facing.scale(.01f);
velocity.sub(facing);
break;
-
+
+ //roll right
case KeyEvent.VK_A:
-
+ turnLeft.rotZ(-Math.PI / 32);
+ currentOrientation.mul(turnLeft);
+ my_blimp.setTransform(currentOrientation);
+ // turnLeft.transform(velocity);
+ break;
+
+ //roll left
+ case KeyEvent.VK_D:
+ turnRight.rotZ(Math.PI / 32);
+ currentOrientation.mul(turnRight);
+ my_blimp.setTransform(currentOrientation);
+ //turnRight.transform(velocity);
+ break;
+
+ case KeyEvent.VK_LEFT:
turnLeft.rotY(Math.PI / 32);
currentOrientation.mul(turnLeft);
my_blimp.setTransform(currentOrientation);
turnLeft.transform(velocity);
- //orientation.y += Math.PI / 32;
-
- //angularVelocity.y = 0;
- //orientation.normalize();
- //System.out.println(orientation.x+ ", " + orientation.y + " " + orientation.z);
break;
-
- case KeyEvent.VK_D:
-
+
+ case KeyEvent.VK_RIGHT:
turnRight.rotY(-Math.PI / 32);
currentOrientation.mul(turnRight);
my_blimp.setTransform(currentOrientation);
turnRight.transform(velocity);
- //orientation.y -= Math.PI / 32;
- //angularVelocity.y = 0;
- //orientation.normalize();
- //System.out.println(orientation.x+ ", " + orientation.y + " " + orientation.z);
+ break;
+
+ case KeyEvent.VK_UP:
+ turnUp.rotX(-Math.PI / 32);
+ currentOrientation.mul(turnUp);
+ my_blimp.setTransform(currentOrientation);
+ turnUp.transform(velocity);
+ break;
+
+ case KeyEvent.VK_DOWN:
+ turnDown.rotX(Math.PI / 32);
+ currentOrientation.mul(turnDown);
+ my_blimp.setTransform(currentOrientation);
+ turnDown.transform(velocity);
break;
}
}
@@ -301,6 +330,118 @@ public class Blimp extends RemoteObject { }*/
+ /**
+ * Update State and maybe generate a new object.
+ *
+ * @return A list of new objects to add to the world.
+ */
+ /*public List<PhysicalObject> spawnChildren(float duration) {
+ List<PhysicalObject> children = super.spawnChildren(duration);
+
+ if (children == null) {
+ children = new LinkedList<PhysicalObject>();
+ }
+
+ if (lastEvent != null && lastEvent.getKeyCode() == KeyEvent.VK_SPACE) {
+
+ TransformGroup particleBody = new TransformGroup();
+ TransformGroup particleTurret = new TransformGroup();
+ TransformGroup particleTG = new TransformGroup();
+ TransformGroup particleBarrel = new TransformGroup();
+ TransformGroup particleGunTG = new TransformGroup();
+ Transform3D collector = new Transform3D();
+ Transform3D current = new Transform3D();
+ Transform3D pTurret = new Transform3D();
+ Transform3D pTG = new Transform3D();
+ Transform3D pBarrel = new Transform3D();
+ Transform3D pGun = new Transform3D();
+ Transform3D temp = new Transform3D();
+ temp.setTranslation(new Vector3f(0, .3f * myScale, 0));
+ my_blimp.getTransform(current);
+ collector.set(current);
+ current.mul(temp);
+ particleBody.setTransform(current);
+ turret.getTransform(pTurret);
+ pTurret.setScale(1.7);
+ particleTurret.setTransform(pTurret);
+ ((TransformGroup) turret.getChild(0)).getTransform(pTG);
+ particleTG.setTransform(pTG);
+ tank.getBarrel().getTransform(pBarrel);
+ particleBarrel.setTransform(pBarrel);
+ ((TransformGroup) tank.getBarrel().getChild(0)).getTransform(pGun);
+ particleGunTG.setTransform(pGun);
+ particleBody.addChild(particleTurret);
+ particleTurret.addChild(particleTG);
+ particleTG.addChild(particleBarrel);
+ particleBarrel.addChild(particleGunTG);
+ collector.mul(pTurret);
+ collector.mul(pTG);
+ collector.mul(pBarrel);
+ collector.mul(pGun);
+ Vector3f accelerator = new Vector3f();
+ collector.get(accelerator);
+
+ //System.out.println(accelerator);
+ ModifyableParticle toAdd = new ModifyableParticle(position, 1f, new Color3f(Color.RED),
+ particleBody, particleGunTG, myScale);
+ toAdd.setAcceleration(accelerator);
+
+ float xyTheta = ((float) Math.PI / 32) * barrelElevation;
+ float xzTheta = ((float) Math.PI / 32) * barrelTurn;
+ float zyTheta = ((float) Math.PI / 32) * barrelElevation;
+ //float c = theta * Body.gunLength * myScale;
+ //toSet.y = toSet.y + c;
+ //VERTICAL CALCULATION
+ float l = Body.gunLength * myScale + .45f * myScale;
+ float q = (l * (float) Math.sin((double) xyTheta))/ (float) Math.sin((Math.PI - xyTheta) / 2);
+ float w = (l * (float) Math.sin((double) xzTheta))/ (float) Math.sin((Math.PI - xzTheta) / 2);
+ float e = (l * (float) Math.sin((double) zyTheta))/ (float) Math.sin((Math.PI - zyTheta) / 2);
+ float newX = l - ((q * q) / (2 * l));
+ float newY = (float) ((q / (2 * l)) * Math.sqrt(4 * l * l - q * q));
+ toSet.x = toSet.x + newX;
+ toSet.y = toSet.y + newY;
+
+ //HORIZONTAL CALCULATION
+ float newnewX = l - ((w * w) / (2 * l));
+ float newZ = (float) ((w / (2 * l)) * Math.sqrt(4 * l * l - w * w));
+ float newZy = (float) ((e / (2 * l)) * Math.sqrt(4 * l * l - e * e));
+ //toSet.x = toSet.x - newnewX;
+ if (barrelTurn != 0) {
+ //toSet.z = toSet.z + newZ;
+ toSet.x = toSet.x - newX;
+ float temp = Math.max(newnewX, newX) - Math.min(newnewX, newX);
+ //toSet.x = toSet.x + Math.max(newnewX, newX) - temp;
+ if (Math.abs(newnewX) > Math.abs(newX)) {
+ toSet.x = toSet.x + newnewX - temp;
+ } else {
+ toSet.x = toSet.x + newX - temp;
+ }
+
+
+ float zTemp = Math.abs(newZ - newZy);
+ if (Math.abs(newZ) < Math.abs(newZy)) {
+ toSet.z = toSet.z + newZ - zTemp;
+ } else {
+ toSet.z = toSet.z + newZy - zTemp;
+ }
+ }
+
+ System.out.println("theta " + theta);
+ System.out.println("q " + q);
+ System.out.println("l " + q);
+ System.out.println(newX);
+ System.out.println(newY);
+ //toSet.y += Body.height * myScale + .275 * myScale;
+ //System.out.println(toSet);
+ //Particle toAdd = new Particle(toSet, new Color3f(DEFAULT_BODY_COLOR));
+ //children.add(toAdd);
+ children.add(toAdd);
+ //System.out.println(toAdd.getPosition());
+ //System.out.println(this.position);
+ lastEvent = null;
+ }
+ return children;
+ }*/
public void updateState(float duration) {
float speed = velocity.length();
diff --git a/src/tesseract/objects/blimp/BlimpBox.java b/src/tesseract/objects/blimp/BlimpBox.java index 6d8b641..69c7808 100644 --- a/src/tesseract/objects/blimp/BlimpBox.java +++ b/src/tesseract/objects/blimp/BlimpBox.java @@ -63,12 +63,12 @@ public class BlimpBox extends PhysicalObject { setShape(createShape());
previousPosition.set(position);
- if (inverseMass != 0) {
+ /*if (inverseMass != 0) {
inverseInertiaTensor.m00 = 1f / 12 / inverseMass * (height * height + depth * depth);
inverseInertiaTensor.m11 = 1f / 12 / inverseMass * (width * width + depth * depth);
inverseInertiaTensor.m22 = 1f / 12 / inverseMass * (width * width + height * height);
inverseInertiaTensor.invert();
- }
+ }*/
updateTransformGroup();
}
diff --git a/src/tesseract/objects/blimp/BlimpFin.java b/src/tesseract/objects/blimp/BlimpFin.java index f5883cd..4de5b09 100644 --- a/src/tesseract/objects/blimp/BlimpFin.java +++ b/src/tesseract/objects/blimp/BlimpFin.java @@ -65,12 +65,12 @@ public class BlimpFin extends PhysicalObject { setShape(createShape(radius, DEFAULT_DIVISIONS));
- if (inverseMass != 0) {
+ /*if (inverseMass != 0) {
inverseInertiaTensor.m00 = 1f / 4 / inverseMass * radius * radius;
inverseInertiaTensor.m11 = 2 * inverseInertiaTensor.m00;
inverseInertiaTensor.m22 = inverseInertiaTensor.m00;
inverseInertiaTensor.invert();
- }
+ }*/
updateTransformGroup();
}
|