summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/PhysicalObject.java
blob: 2634ca2d761f93a4007b2615913b790539ff1d78 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tesseract.objects;

import java.util.ArrayList;
import java.util.List;

import javax.media.j3d.GeometryArray;
import javax.media.j3d.Node;
import javax.media.j3d.Shape3D;
import javax.vecmath.Vector3f;

import alden.CollidableObject;
import alden.CollisionInfo;

import com.sun.j3d.utils.geometry.Primitive;

/**
 * This class is the parent of all objects in the world.
 * 
 * Note: The constructor of a child class must add its shape
 *  to the transform group for it to be visible.
 * 
 * @author Jesse Morgan
 */
public class PhysicalObject extends CollidableObject {
	public PhysicalObject(final Vector3f thePosition, final float mass) {
		super(mass);
		this.position.set(thePosition);
	}

	public List<PhysicalObject> spawnChildren(final float duration) {
		return null;
	}
	
	public void addForce(final Vector3f force) {
		this.forceAccumulator.add(force);
	}
	
	public void updateState(final float duration) {
		super.updateState(duration);
		this.updateTransformGroup();
	}
	
	public void setShape(final Node node) {
		node.setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ);
		node.setCapability(javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ);

		if (node instanceof Primitive) {
			Primitive prim = (Primitive) node;
			int index = 0;
			Shape3D shape;
			while ((shape = prim.getShape(index++)) != null) {
				shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
				shape.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
				shape.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);

				for (int i = 0; i < shape.numGeometries(); i++) {
					shape.getGeometry(i).setCapability(
							GeometryArray.ALLOW_COUNT_READ);
					shape.getGeometry(i).setCapability(
							GeometryArray.ALLOW_COORDINATE_READ);
				}

			}
		}

		super.setShape(node);
	}

	public void resolveCollisions(final PhysicalObject other) {
		if (this.node != null && other.node != null) {
			super.resolveCollisions(other);
		}
	}
}