summaryrefslogtreecommitdiff
path: root/src/tesseract/objects/Polygon.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/tesseract/objects/Polygon.java')
-rw-r--r--src/tesseract/objects/Polygon.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/tesseract/objects/Polygon.java b/src/tesseract/objects/Polygon.java
new file mode 100644
index 0000000..c8fcf53
--- /dev/null
+++ b/src/tesseract/objects/Polygon.java
@@ -0,0 +1,43 @@
+package tesseract.objects;
+import javax.media.j3d.Transform3D;
+import javax.vecmath.*;
+
+import alden.CollidableObject;
+
+public abstract class Polygon extends PhysicalObject {
+ public Vector3f normal;
+ // Right-hand side of the plane equation: Ax + By + Cz = D
+ public float intercept;
+
+ public Polygon(Vector3f position, Vector3f normal) {
+ this(1, position, normal);
+ }
+
+ public Polygon(float mass, Vector3f position, Vector3f normal) {
+ super(position, mass);
+
+ 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);
+ }
+}