diff options
author | Phillip <pacardon@u.washington.edu> | 2011-03-11 23:39:29 +0000 |
---|---|---|
committer | Phillip <pacardon@u.washington.edu> | 2011-03-11 23:39:29 +0000 |
commit | e3467fc8846e2d91f127f1750d219e2a7eec1f8e (patch) | |
tree | 779ed6a351f29424f0cc66a4321943c20f382d9e /src/tesseract/objects/tank/Body.java | |
parent | 199caa58d3bbafbb500b756523af8b023e37ddfb (diff) |
Body is now an INSTANTIABLE OBJECT holding only the Group Tree Structure and Geometry for the Tank RemoteObject.
Tank now takes advantage of utilizing saved references in Body object.
Tank can now rotate in place (imperfect), as well as rotate the turret (all the way around), and elevate the turret up to +13 * Pi / 32 degrees and down to -Pi / 32 Degrees.
ToDo:
Body: add emitter to barrel for firing
Tank: add keycode to fire
NEWCLASS: Ammunition class
Diffstat (limited to 'src/tesseract/objects/tank/Body.java')
-rw-r--r-- | src/tesseract/objects/tank/Body.java | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/src/tesseract/objects/tank/Body.java b/src/tesseract/objects/tank/Body.java index 5238846..e67f3c1 100644 --- a/src/tesseract/objects/tank/Body.java +++ b/src/tesseract/objects/tank/Body.java @@ -4,6 +4,8 @@ import java.awt.Color; import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
+import javax.media.j3d.Geometry;
+import javax.media.j3d.GeometryArray;
import javax.media.j3d.Group;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
@@ -14,6 +16,7 @@ import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
+import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.geometry.Sphere;
@@ -24,9 +27,24 @@ public class Body { public static float radius = .75f;
public static float gunRad = .075f;
public static float gunLength = 2f;
+ private TransformGroup body;
+ private TransformGroup turret;
+ private TransformGroup barrel;
+ private Vector3f[] vectors;
- public static TransformGroup makeBody(Color trackColor, Color bodyColor, float theScale) {
- TransformGroup tank = new TransformGroup();
+ public Body(Color trackColor, Color bodyColor, float theScale, Color turretColor) {
+ body = new TransformGroup();
+ turret = new TransformGroup();
+ barrel = new TransformGroup();
+ makeBody(trackColor, bodyColor, theScale);
+ Transform3D turretMove = new Transform3D();
+ 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) {
+ Vector3f facing = new Vector3f();
Appearance appearance = new Appearance();
Material material = new Material();
material.setDiffuseColor(new Color3f(bodyColor));
@@ -34,6 +52,13 @@ public class Body { appearance.setMaterial(material);
Primitive box = new Box(width * theScale, height * theScale,
depth * theScale, appearance);
+ Shape3D front = box.getShape(Box.RIGHT);
+ //
+ Geometry g = front.getGeometry(0);
+ GeometryInfo gi = new GeometryInfo((GeometryArray)g);
+ vectors = gi.getNormals();
+
+ //
Transform3D trackMove = new Transform3D();
Transform3D downward = new Transform3D();
downward.setTranslation(new Vector3f(0, (-height / 1.125f) * theScale,0));
@@ -46,18 +71,17 @@ public class Body { Shape3D rightTrack = Track.makeTrack(theScale, trackColor, trackMove);
//Shape3D body = new Shape3D();
//body.removeAllGeometries();
- Transform3D turretMove = new Transform3D();
- turretMove.setTranslation(new Vector3f(0, height * theScale, 0));
- tank.addChild(box);
- tank.addChild(leftTrack);
- tank.addChild(rightTrack);
+
+ body.addChild(box);
+ body.addChild(leftTrack);
+ body.addChild(rightTrack);
//makeTurret(appearance, theScale, turretMove);
//TransformGroup turret = makeTurret(appearance, theScale, turretMove);
//TransformGroup[] tankNturret = {tank, turret};
- return tank;
}
- public static TransformGroup makeTurret(Color turretColor,
- float theScale, Transform3D toMove) {
+
+ public void makeTurret(Color turretColor, float theScale,
+ Transform3D toMove) {
Appearance appearance = new Appearance();
Material material = new Material();
material.setDiffuseColor(new Color3f(turretColor));
@@ -76,12 +100,28 @@ public class Body { rotateGun.rotY(Math.PI / 2);
//toMove.mul(rotateGun);
tg.addChild(sphere);
- tg.addChild(gunTG);
+ tg.addChild(barrel);
+ barrel.addChild(gunTG);
tg.setTransform(toMove);
- TransformGroup turret = new TransformGroup();
turret.addChild(tg);
+ //turret.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
//turret.setTransform(rotateGun);
//tg.setTransform();
+ }
+
+ public TransformGroup getBody() {
+ return body;
+ }
+
+ public TransformGroup getTurret() {
return turret;
}
+
+ public TransformGroup getBarrel() {
+ return barrel;
+ }
+
+ public Vector3f[] getFacing() {
+ return vectors;
+ }
}
|