1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
package tesseract.objects.tank;
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.Material;
import javax.media.j3d.Node;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
//import tesseract.objects.emitters.FireableEmitter;
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;
public class Body {
public static final float width = 1.35f;
public static final float height = .45f;
public static final float depth = .9f;
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;
private Vector3f aim;
//private FireableEmitter shooter;
public Body(Color trackColor, Color bodyColor, float theScale, Color turretColor) {
//shooter = new FireableEmitter(new Vector3f(), new Vector3f(), new Color3f(1f, 0f, 0f));
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));
appearance.setColoringAttributes(new ColoringAttributes(new Color3f(bodyColor), ColoringAttributes.NICEST));
appearance.setMaterial(material);
Primitive box = new Box(width * theScale, height * theScale,
depth * theScale, appearance);
Shape3D front = box.getShape(Box.FRONT);
//
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));
trackMove.setTranslation(new Vector3f(0, 0, depth * theScale));
trackMove.mul(downward);
Shape3D leftTrack = Track.makeTrack(theScale, trackColor, trackMove);
trackMove = new Transform3D();
trackMove.setTranslation(new Vector3f(0, 0, -depth * theScale));
trackMove.mul(downward);
Shape3D rightTrack = Track.makeTrack(theScale, trackColor, trackMove);
//Shape3D body = new Shape3D();
//body.removeAllGeometries();
body.addChild(box);
body.addChild(leftTrack);
body.addChild(rightTrack);
//makeTurret(appearance, theScale, turretMove);
//TransformGroup turret = makeTurret(appearance, theScale, turretMove);
//TransformGroup[] tankNturret = {tank, turret};
}
public void makeTurret(Color turretColor, float theScale,
Transform3D toMove) {
Appearance appearance = new Appearance();
Material material = new Material();
material.setDiffuseColor(new Color3f(turretColor));
appearance.setColoringAttributes(new ColoringAttributes(new Color3f(turretColor), ColoringAttributes.NICEST));
appearance.setMaterial(material);
TransformGroup tg = new TransformGroup();
TransformGroup gunTG = new TransformGroup();
Primitive sphere = new Sphere(radius * theScale, appearance);
Primitive gun = new Cylinder(gunRad * theScale, gunLength * theScale, appearance);
gunTG.addChild(gun);
Transform3D mg = new Transform3D();
mg.rotZ(Math.PI / 2);
mg.setTranslation(new Vector3f(1.4f * theScale, .25f * theScale, 0));
//shooter.moveMe(new Vector3f(1.4f * theScale, .25f * theScale, 0));
gunTG.setTransform(mg);
Transform3D rotateGun = new Transform3D();
rotateGun.rotY(Math.PI / 2);
//toMove.mul(rotateGun);
tg.addChild(sphere);
tg.addChild(barrel);
barrel.addChild(gunTG);
tg.setTransform(toMove);
turret.addChild(tg);
//Node s = barrel.getChild(Cylinder.BOTTOM);
//if (s instanceof Shape3D) {
//Shape3D r = (Shape3D) s;
//Geometry g = r.getGeometry(0);
//GeometryInfo gi = new GeometryInfo((GeometryArray)g);
//aim = (gi.getNormals())[0];
//}
//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[0];
}
public Vector3f getAim() {
return aim;
}
//public FireableEmitter getShooter() {
// return shooter;
//}
}
|