diff options
Diffstat (limited to 'src/common/Polygon.java')
-rw-r--r-- | src/common/Polygon.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/Polygon.java b/src/common/Polygon.java new file mode 100644 index 0000000..9240e9c --- /dev/null +++ b/src/common/Polygon.java @@ -0,0 +1,43 @@ +package common;
+
+import javax.media.j3d.Transform3D;
+import javax.vecmath.*;
+
+@SuppressWarnings("restriction")
+public abstract class Polygon extends CollidableObject {
+ protected Vector3f normal;
+ // Right-hand side of the plane equation: Ax + By + Cz = D
+ protected float intercept;
+
+ public Polygon(Vector3f position, Vector3f normal) {
+ this(1, position, normal);
+ }
+
+ public Polygon(float mass, Vector3f position, Vector3f normal) {
+ super(mass);
+ this.position.set(position);
+ this.normal = new Vector3f(normal);
+ this.normal.normalize();
+ intercept = this.normal.dot(position);
+ Vector3f newX = new Vector3f(1, 0, 0);
+ if (Math.abs(newX.dot(this.normal)) == 1)
+ newX = new Vector3f(0, -1, 0);
+ newX.scaleAdd(-newX.dot(this.normal), this.normal, newX);
+ newX.normalize();
+ Vector3f newZ = new Vector3f();
+ newZ.cross(newX, this.normal);
+ new Matrix4f(new Matrix3f(newX.x, this.normal.x, newZ.x, newX.y, this.normal.y, newZ.y, newX.z, this.normal.z, newZ.z), position, 1).get(orientation);
+ }
+
+ protected void updateTransformGroup() {
+ super.updateTransformGroup();
+ Transform3D tmp = new Transform3D();
+ TG.getTransform(tmp);
+ Matrix3f rot = new Matrix3f();
+ tmp.get(rot);
+ normal.x = rot.m01;
+ normal.y = rot.m11;
+ normal.z = rot.m21;
+ intercept = normal.dot(position);
+ }
+}
|