summaryrefslogtreecommitdiff
path: root/src/tesseract
diff options
context:
space:
mode:
Diffstat (limited to 'src/tesseract')
-rw-r--r--src/tesseract/TesseractUI.java101
1 files changed, 25 insertions, 76 deletions
diff --git a/src/tesseract/TesseractUI.java b/src/tesseract/TesseractUI.java
index cc2f078..4519585 100644
--- a/src/tesseract/TesseractUI.java
+++ b/src/tesseract/TesseractUI.java
@@ -8,7 +8,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
-import java.util.ArrayList;
import javax.media.j3d.BoundingBox;
import javax.media.j3d.Canvas3D;
@@ -21,17 +20,14 @@ import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
-import javax.vecmath.Point2i;
import javax.vecmath.Point3d;
-import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import tesseract.forces.Gravity;
import tesseract.menuitems.ParticleEmitterMenuItem;
import tesseract.menuitems.ParticleMenuItem;
import tesseract.objects.Particle;
-import tesseract.objects.Physical;
-import tesseract.objects.PhysicalObject;
+import tesseract.objects.emitters.ParticleEmitter;
import com.sun.j3d.utils.universe.SimpleUniverse;
@@ -63,11 +59,6 @@ public class TesseractUI extends JFrame {
private static final int MILISECONDS_IN_SECOND = 1000;
/**
- * List of items to appear in add objects menu.
- */
- private ArrayList<JMenuItem> myObjectMenuItems;
-
- /**
* A reference to the world.
*/
private World myWorld;
@@ -88,9 +79,9 @@ public class TesseractUI extends JFrame {
private double cameraXRotation, cameraYRotation, cameraDistance;
/**
- * Reference to the currently selected physical object.
+ * Object Menu Items.
*/
- private Physical myCurrentObject;
+ private JMenuItem[] myObjectMenuItems;
/**
* UI Constructor.
@@ -99,16 +90,14 @@ public class TesseractUI extends JFrame {
super("Tesseract Project");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- myCurrentObject = null;
-
myWorld = new World(
new BoundingBox(new Point3d(-UNIT / 2, -UNIT / 2, -UNIT / 2),
new Point3d(UNIT / 2, UNIT / 2, UNIT / 2)));
- myObjectMenuItems = new ArrayList<JMenuItem>();
- myObjectMenuItems.add(new ParticleEmitterMenuItem(myWorld));
- myObjectMenuItems.add(new ParticleMenuItem(myWorld));
-
+ myObjectMenuItems = new JMenuItem[] {
+ new ParticleEmitterMenuItem(myWorld),
+ new ParticleMenuItem(myWorld)
+ };
createMenu();
setupCanvas();
@@ -122,12 +111,9 @@ public class TesseractUI extends JFrame {
// THIS IS WHERE OBJECTS ARE FORCED INTO EXISTANCE
// TODO: REMOVE TEST CODE
- PhysicalObject p = new Particle(new Vector3f(0, 0, 0), null);
-
- //myWorld.addObject(p);
-
+ myWorld.addObject(new Particle(new Vector3f(0, 0, 0), null));
myWorld.addForce(new Gravity());
- //myWorld.addObject(new ParticleEmitter(new Vector3f(0, 0.49f, 0), 0.5f, null));
+ myWorld.addObject(new ParticleEmitter(new Vector3f(0, 0.49f, 0), 0.5f, null));
}
/**
@@ -138,15 +124,15 @@ public class TesseractUI extends JFrame {
JMenu simulationMenu = new JMenu("Simulation");
- //Added by Steve: Fixes viewing menu problem with Canvas3D on both my windows machines
+ // Added by Steve: Fixes viewing menu problem with Canvas3D on both my windows machines
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
menuBar.add(simulationMenu);
JMenu objectsMenu = new JMenu("Add Object");
- for (JMenuItem i : myObjectMenuItems) {
- objectsMenu.add(i);
+ for (JMenuItem item : myObjectMenuItems) {
+ objectsMenu.add(item);
}
menuBar.add(objectsMenu);
@@ -215,47 +201,28 @@ public class TesseractUI extends JFrame {
private MouseEvent lastDragEvent = null;
public void mouseDragged(final MouseEvent e) {
- if (myCurrentObject != null) {
- Point3d point = mouseToWorld(
- new Point2i(e.getX(), e.getY()));
- myCurrentObject.setPosition(new Vector3f(point));
-
- } else {
- Point3d point = mouseToWorld(
- new Point2i(e.getX(), e.getY()));
- Vector3d direction = new Vector3d(0, 0, -1);
- Transform3D t3d = new Transform3D();
- cameraTG.getTransform(t3d);
- t3d.transform(direction);
+ if (lastDragEvent != null) {
+ cameraXRotation +=
+ Math.toRadians(e.getY() - lastDragEvent.getY()) / 3;
- myCurrentObject = myWorld.getObject(point, direction);
- System.out.println(point);
- System.out.println(myCurrentObject);
-
- if (lastDragEvent != null) {
- cameraXRotation +=
- Math.toRadians(e.getY() - lastDragEvent.getY()) / 3;
-
- if (cameraXRotation > Math.PI / 2) {
- cameraXRotation = Math.PI / 2;
-
- } else if (cameraXRotation < -Math.PI / 2) {
- cameraXRotation = -Math.PI / 2;
- }
+ if (cameraXRotation > Math.PI / 2) {
+ cameraXRotation = Math.PI / 2;
- cameraYRotation +=
- Math.toRadians(e.getX() - lastDragEvent.getX()) / 3;
-
- updateCamera();
+ } else if (cameraXRotation < -Math.PI / 2) {
+ cameraXRotation = -Math.PI / 2;
}
- lastDragEvent = e;
+ cameraYRotation +=
+ Math.toRadians(e.getX() - lastDragEvent.getX()) / 3;
+
+ updateCamera();
}
+
+ lastDragEvent = e;
}
public void mouseMoved(final MouseEvent e) {
lastDragEvent = null;
- myCurrentObject = null;
}
});
@@ -284,24 +251,6 @@ public class TesseractUI extends JFrame {
}
/**
- * Convert screen coordinates to world coordinates.
- *
- * @param mousePosition The mouse position on screen.
- * @return A point in the world.
- */
- private Point3d mouseToWorld(final Point2i mousePosition) {
- Point3d position = new Point3d();
- myCanvas.getPixelLocationInImagePlate(
- mousePosition.getX(), mousePosition.getY(), position);
-
- Transform3D transform = new Transform3D();
- myCanvas.getImagePlateToVworld(transform);
- transform.transform(position);
-
- return position;
- }
-
- /**
* Method to update the camera.
*/
private void updateCamera() {