From 350a482b32512191596daad55104beec98af9981 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Wed, 16 Feb 2011 08:12:56 +0000 Subject: Added alden's code, moved his objects into the object class and made them extend physical object. Fixed a node selection problem in TesseractUI. --- src/tesseract/objects/Polygon.java | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/tesseract/objects/Polygon.java (limited to 'src/tesseract/objects/Polygon.java') 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); + } +} -- cgit v1.2.3