Browse Source

started working on the clickable LEDs

hutattedonmyarm 12 years ago
parent
commit
30841912a7
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      CubeControl/Frame.java

+ 35
- 0
CubeControl/Frame.java View File

@@ -28,6 +28,8 @@ import java.awt.event.*;
28 28
 import javax.swing.*;
29 29
 import javax.swing.event.*;
30 30
 import java.io.File;
31
+import javax.vecmath.Point2d;
32
+import javax.vecmath.Point3d;
31 33
 
32 34
 public class Frame extends JFrame implements ListSelectionListener {
33 35
 
@@ -205,6 +207,16 @@ public class Frame extends JFrame implements ListSelectionListener {
205 207
 		// ----- 3D-----
206 208
 		// -------------
207 209
 		cubeCanvas.setBounds(8, 8, 250, 250);
210
+		cubeCanvas.addMouseListener(new MouseListener() {
211
+			public void mouseClicked(MouseEvent e){
212
+				Point2d mousePos = convertMousePositionToWorld(e.getX(), e.getY());	
213
+			}
214
+			public void mouseExited(MouseEvent e){}
215
+			public void mouseEntered(MouseEvent e){}
216
+			public void mouseReleased(MouseEvent e){}
217
+			public void mousePressed(MouseEvent e){}
218
+
219
+		});
208 220
 		cp.add(cubeCanvas);
209 221
 
210 222
 		// -------------
@@ -942,4 +954,27 @@ public class Frame extends JFrame implements ListSelectionListener {
942 954
 		}
943 955
 		return s;
944 956
 	}
957
+	
958
+	private Point2d convertMousePositionToWorld (int iX, int iY)
959
+	{
960
+    Point3d eye_pos = new Point3d();
961
+    Point3d mousePosn = new Point3d();
962
+
963
+    //get the eye point and mouse click point
964
+    this.cubeCanvas.getCenterEyeInImagePlate(eye_pos);
965
+    this.cubeCanvas.getPixelLocationInImagePlate(iX, iY, mousePosn);
966
+
967
+    //Transform from ImagePlate coordinates to Vworld coordinates
968
+    Transform3D motion = new Transform3D();
969
+    this.cubeCanvas.getImagePlateToVworld(motion);
970
+
971
+    motion.transform(eye_pos);
972
+    motion.transform(mousePosn);
973
+
974
+    //calculate the intersection point on Z=0
975
+    double dblX = (-eye_pos.z / (mousePosn.z - eye_pos.z)) * (mousePosn.x - eye_pos.x) + eye_pos.x;
976
+    double dblY = (-eye_pos.z / (mousePosn.z - eye_pos.z)) * (mousePosn.y - eye_pos.y) + eye_pos.y;
977
+    
978
+    return new Point2d (dblX, dblY);
979
+	}
945 980
 }

Loading…
Cancel
Save