summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/tank/Tank.java
blob: 12f6fb39ab1668dd7eee5a01119dcd96baf60322 (plain)
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
package tesseract.objects.tank;

import java.awt.Color;

import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;

import tesseract.objects.remote.RemoteObject;

public class Tank extends RemoteObject {
	
	private final TransformGroup tank;
	private final TransformGroup body;
	private final TransformGroup turret;
	private static final float DEFAULT_SCALE = 0.0625f;
	private static final Color DEFAULT_BODY_COLOR = Color.GREEN;
	private static final Color DEFAULT_TRACK_COLOR = Color.DARK_GRAY;
	private static final Color DEFAULT_TURRET_COLOR = Color.GREEN;
	
	public Tank(Vector3f thePosition, float mass) {
		this(thePosition, mass, DEFAULT_SCALE);
	}

	public Tank(Vector3f thePosition, float mass, float theScale) {
		this(thePosition, mass, theScale, DEFAULT_BODY_COLOR,
				DEFAULT_TRACK_COLOR, DEFAULT_TURRET_COLOR);
	}

	public Tank(Vector3f thePosition, float mass, float theScale,
			Color bodyColor, Color trackColor, Color turretColor) {
		super (thePosition, mass);
		body = Body.makeBody(DEFAULT_BODY_COLOR, DEFAULT_TRACK_COLOR, theScale);
		Transform3D turretMove = new Transform3D();
		turretMove.setTranslation(new Vector3f(0, Body.height * theScale, 0));
		turret = Body.makeTurret(turretColor, theScale, turretMove);
		tank = new TransformGroup();
		tank.addChild(body);
		tank.addChild(turret);
		setShape(tank);
		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);
		inverseInertiaTensor.m22 = 1f / 12 / inverseMass * (Body.width * Body.width * theScale + Body.height * Body.height * theScale);
		inverseInertiaTensor.invert();
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 4419863813052251438L;

	@Override
	public String getName() {
		return "Tank";
	}

}