Browse Source

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 years ago
parent
commit
8b9c2b7ea8
1 changed files with 13 additions and 25 deletions
  1. 13
    25
      CubeControl/Led3D.java

+ 13
- 25
CubeControl/Led3D.java View File

92
 		transGroup = new TransformGroup(trans3D);
92
 		transGroup = new TransformGroup(trans3D);
93
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
93
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
94
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
94
 		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
95
-		transGroup.setCapability(Node.ALLOW_BOUNDS_READ);
96
-		transGroup.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
97
 		ViewingPlatform viewingPlatform = new ViewingPlatform();
95
 		ViewingPlatform viewingPlatform = new ViewingPlatform();
98
 		Viewer viewer = new Viewer(canvas);
96
 		Viewer viewer = new Viewer(canvas);
99
 		universe = new SimpleUniverse(viewingPlatform, viewer);
97
 		universe = new SimpleUniverse(viewingPlatform, viewer);
119
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
117
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
120
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
118
 		group.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
121
 		group.setCapability(BranchGroup.ALLOW_DETACH);
119
 		group.setCapability(BranchGroup.ALLOW_DETACH);
122
-		group.setCapability(Node.ALLOW_BOUNDS_READ);
123
-		group.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
124
 		background = createBackground();
120
 		background = createBackground();
125
 		group.addChild(background);
121
 		group.addChild(background);
126
 
122
 
140
 					Vector3f vector = new Vector3f(x, y, z);
136
 					Vector3f vector = new Vector3f(x, y, z);
141
 					transform.setTranslation(vector);
137
 					transform.setTranslation(vector);
142
 					tg.setTransform(transform);
138
 					tg.setTransform(transform);
143
-					tg.setCapability(Node.ALLOW_BOUNDS_READ);
144
-					tg.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
145
 					tg.addChild(leds[x][y][z]);
139
 					tg.addChild(leds[x][y][z]);
146
 					transGroup.addChild(tg);
140
 					transGroup.addChild(tg);
147
 
141
 
183
 		if (result != null) {
177
 		if (result != null) {
184
 			// User clicked near something
178
 			// User clicked near something
185
 			Primitive p = (Primitive)result.getNode(PickResult.PRIMITIVE);
179
 			Primitive p = (Primitive)result.getNode(PickResult.PRIMITIVE);
186
-			Shape3D s = (Shape3D)result.getNode(PickResult.SHAPE3D);
187
-			Cylinder c = null;
188
 			if (p != null) {
180
 			if (p != null) {
181
+				// p is now a Primitive that the user clicked
189
 				if (p.getClass().getName().equals("com.sun.j3d.utils.geometry.Cylinder")) {
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
 					}

Loading…
Cancel
Save