Просмотр исходного кода

Now not comparing Bounds but comparing objects.

Unfortunately, the Class.equals() seems to compare something that
differs between our stored LED Spheres and the Clicked Primitive… Need
to find another way to compare…
Thomas Buck 12 лет назад
Родитель
Сommit
8b9c2b7ea8
1 измененных файлов: 13 добавлений и 25 удалений
  1. 13
    25
      CubeControl/Led3D.java

+ 13
- 25
CubeControl/Led3D.java Просмотреть файл

@@ -92,8 +92,6 @@ public class Led3D extends MouseAdapter {
92 92
 		transGroup = new TransformGroup(trans3D);
93 93
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
94 94
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
95
-		transGroup.setCapability(Node.ALLOW_BOUNDS_READ);
96
-		transGroup.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
97 95
 		ViewingPlatform viewingPlatform = new ViewingPlatform();
98 96
 		Viewer viewer = new Viewer(canvas);
99 97
 		universe = new SimpleUniverse(viewingPlatform, viewer);
@@ -119,8 +117,6 @@ public class Led3D extends MouseAdapter {
119 117
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
120 118
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
121 119
 		group.setCapability(BranchGroup.ALLOW_DETACH);
122
-		group.setCapability(Node.ALLOW_BOUNDS_READ);
123
-		group.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
124 120
 		background = createBackground();
125 121
 		group.addChild(background);
126 122
 
@@ -140,8 +136,6 @@ public class Led3D extends MouseAdapter {
140 136
 					Vector3f vector = new Vector3f(x, y, z);
141 137
 					transform.setTranslation(vector);
142 138
 					tg.setTransform(transform);
143
-					tg.setCapability(Node.ALLOW_BOUNDS_READ);
144
-					tg.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
145 139
 					tg.addChild(leds[x][y][z]);
146 140
 					transGroup.addChild(tg);
147 141
 
@@ -183,27 +177,21 @@ public class Led3D extends MouseAdapter {
183 177
 		if (result != null) {
184 178
 			// User clicked near something
185 179
 			Primitive p = (Primitive)result.getNode(PickResult.PRIMITIVE);
186
-			Shape3D s = (Shape3D)result.getNode(PickResult.SHAPE3D);
187
-			Cylinder c = null;
188 180
 			if (p != null) {
181
+				// p is now a Primitive that the user clicked
189 182
 				if (p.getClass().getName().equals("com.sun.j3d.utils.geometry.Cylinder")) {
190
-					c = (Cylinder)p;
191
-				}
192
-			} else if (s != null) {
193
-				if (s.getClass().getName().equals("com.sun.j3d.utils.geometry.Cylinder")) {
194
-					c = (Cylinder)p;
195
-				}
196
-			}
197
-			if (c != null) {
198
-/* ---> */		Bounds b = c.getBounds();
199
-				// CapabilityNotSetException: no capability to read user bounds
200
-				
201
-				for (int x = 0; x < 8; x++) {
202
-					for (int y = 0; y < 8; y++) {
203
-						for (int z = 0; z < 8; z++) {
204
-							if (b.equals(leds[x][y][z].getBounds())) {
205
-								// Clicked led found!
206
-								parentFrame.toggleLED(x, y, z);
183
+					// p is a Cylinder. Our LEDs are Spheres, so p.equals(led[x][y][z]) does not find anything...
184
+					for (int x = 0; x < 8; x++) {
185
+						for (int y = 0; y < 8; y++) {
186
+							for (int z = 0; z < 8; z++) {
187
+								if (p.equals(leds[x][y][z])) {
188
+									// Clicked led found!
189
+									System.out.println("Clicked LED found: " + x + " " + y + " " + z);
190
+									parentFrame.toggleLED(x, y, z);
191
+									break;
192
+								} else if ((x == 7) && (y == 7) && (z == 7)) {
193
+									System.out.println("Clicked, but LED not found!");
194
+								}
207 195
 							}
208 196
 						}
209 197
 					}

Загрузка…
Отмена
Сохранить