Browse Source

Made LEDs white and bright

hutattedonmyarm 12 years ago
parent
commit
9e72de7dad
1 changed files with 155 additions and 141 deletions
  1. 155
    141
      Cube Control/frame.java

+ 155
- 141
Cube Control/frame.java View File

@@ -15,7 +15,7 @@ import com.sun.j3d.utils.behaviors.mouse.*;
15 15
 *
16 16
 * Copyright 2011 Thomas Buck <xythobuz@me.com>
17 17
 * Copyright 2011 Max Nuding <max.nuding@gmail.com>
18
-* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
18
+* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
19 19
 *
20 20
 * This file is part of LED-Cube.
21 21
 *
@@ -34,99 +34,116 @@ import com.sun.j3d.utils.behaviors.mouse.*;
34 34
 */
35 35
 
36 36
 class Led3D {
37
-	private Canvas3D canvas = null;
38
-	private SimpleUniverse universe = null;
39
-  	private BranchGroup group = null;
40
-	private Transform3D trans3D = null;
41
-	private BranchGroup inBetween = null;
42
-	private TransformGroup transGroup = null;
43
-
44
-	private Sphere[][][] leds = new Sphere[8][8][8];
45
-
46
-	private static ColoringAttributes colorRed = new ColoringAttributes(1.5f, 0.1f, 0.1f, ColoringAttributes.FASTEST);
47
-	private static ColoringAttributes colorWhite = new ColoringAttributes(1.5f, 1.5f, 1.5f, ColoringAttributes.FASTEST);
48
-
49
-	private Point3d eye = new Point3d(3.5, 3.5, -13.0);
50
-	private Point3d look = new Point3d(3.5, 3.5, 0.0);
51
-	private Vector3d lookVect = new Vector3d(1.0, 1.0, 0.0);
52
-
53
-	Led3D(Canvas3D canv) {
54
-		canvas = canv;
55
-		group = new BranchGroup();
56
-		// Position viewer, so we are looking at object
57
-		trans3D = new Transform3D();
58
-		trans3D.lookAt(eye, look, lookVect);
59
-		trans3D.invert();
60
-		//transGroup = new TransformGroup(trans3D);
61
-		transGroup = new TransformGroup();
62
-		ViewingPlatform viewingPlatform = new ViewingPlatform();
63
-		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
64
-		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
65
-		transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
66
-		Viewer viewer = new Viewer(canvas);
67
-		universe = new SimpleUniverse(viewingPlatform, viewer);
68
-		group.addChild(transGroup);
69
-		universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
70
-    	universe.addBranchGraph(group); // Add group to universe
71
-
72
-		BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
73
-		// roration with left mouse button
74
-		MouseRotate behaviour = new MouseRotate(transGroup);
75
-		BranchGroup inBetween = new BranchGroup();
76
-		inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
77
-		inBetween.addChild(behaviour);
78
-		transGroup.addChild(inBetween);
79
-		behaviour.setSchedulingBounds(boundBox);
80
-
81
-		// zoom with middle mouse button
82
-		MouseZoom beh2 = new MouseZoom(transGroup);
83
-		BranchGroup brM2 = new BranchGroup();
84
-		brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
85
-		brM2.addChild(beh2);
86
-		inBetween.addChild(brM2);
87
-		beh2.setSchedulingBounds(boundBox);
88
-
89
-		// move with right mouse button
90
-		MouseTranslate beh3 = new MouseTranslate(transGroup);
91
-		BranchGroup brM3 = new BranchGroup();
92
-		brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
93
-		brM3.addChild(beh3);
94
-		inBetween.addChild(brM3);
95
-		beh3.setSchedulingBounds(boundBox);
96
-
97
-		// Add all our led sphares to the universe
98
-		for (int x = 0; x < 8; x++) {
99
-			for (int y = 0; y < 8; y++) {
100
-				for (int z = 0; z < 8; z++) {
101
-					leds[x][y][z] = new Sphere(0.05f);
102
-					if ((x == 7) && (y == 7) && (z == 7)) {
103
-						Appearance a = new Appearance();
104
-						a.setColoringAttributes(colorRed);
105
-						leds[x][y][z].setAppearance(a);
106
-					}
107
-					TransformGroup tg = new TransformGroup();
108
-					tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
109
-					Transform3D transform = new Transform3D();
110
-					Vector3f vector = new Vector3f(x, y, z);
111
-					transform.setTranslation(vector);
112
-					tg.setTransform(transform);
113
-					tg.addChild(leds[x][y][z]);
114
-					BranchGroup allTheseGroupsScareMe = new BranchGroup();
115
-					allTheseGroupsScareMe.addChild(tg);
116
-					inBetween.addChild(allTheseGroupsScareMe);
117
-				}
118
-			}
119
-		}
120
-
121
-		// Add an ambient light
122
-		Color3f light2Color = new Color3f(8.0f, 8.0f, 8.0f);
123
-		AmbientLight light2 = new AmbientLight(light2Color);
124
-		BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
125
-		light2.setInfluencingBounds(bounds);
126
-		BranchGroup fffuuuuu = new BranchGroup();
127
-		fffuuuuu.addChild(light2);
128
-		inBetween.addChild(fffuuuuu);
129
-	}
37
+  private Canvas3D canvas = null;
38
+  private SimpleUniverse universe = null;
39
+    private BranchGroup group = null;
40
+  private Transform3D trans3D = null;
41
+  private BranchGroup inBetween = null;
42
+  private TransformGroup transGroup = null;
43
+
44
+  private Sphere[][][] leds = new Sphere[8][8][8];
45
+
46
+  private static ColoringAttributes colorRed = new ColoringAttributes(1.0f, 0.0f, 0.0f, ColoringAttributes.FASTEST);
47
+  private static ColoringAttributes colorWhite = new ColoringAttributes(1.0f, 1.0f, 1.0f, ColoringAttributes.FASTEST);
48
+
49
+  private static Material whiteMat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), 42.0f);
50
+  private static Material redMat = new Material(new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 42.0f);
51
+  private static Appearance ledAppearance = new Appearance();
52
+
53
+  private Point3d eye = new Point3d(3.5, 3.5, -13.0);
54
+  private Point3d look = new Point3d(3.5, 3.5, 0.0);
55
+  private Vector3d lookVect = new Vector3d(1.0, 1.0, 0.0);
56
+
57
+  Led3D(Canvas3D canv) {
58
+  
59
+    //Material
60
+
61
+
62
+  
63
+  
64
+    canvas = canv;
65
+    group = new BranchGroup();
66
+    // Position viewer, so we are looking at object
67
+    trans3D = new Transform3D();
68
+    trans3D.lookAt(eye, look, lookVect);
69
+    trans3D.invert();
70
+    //transGroup = new TransformGroup(trans3D);
71
+    transGroup = new TransformGroup();
72
+    ViewingPlatform viewingPlatform = new ViewingPlatform();
73
+    transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
74
+    transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
75
+    transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
76
+    Viewer viewer = new Viewer(canvas);
77
+    universe = new SimpleUniverse(viewingPlatform, viewer);
78
+    group.addChild(transGroup);
79
+    universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
80
+      universe.addBranchGraph(group); // Add group to universe
81
+
82
+    BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
83
+    // roration with left mouse button
84
+    MouseRotate behaviour = new MouseRotate(transGroup);
85
+    BranchGroup inBetween = new BranchGroup();
86
+    inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
87
+    inBetween.addChild(behaviour);
88
+    transGroup.addChild(inBetween);
89
+    behaviour.setSchedulingBounds(boundBox);
90
+
91
+    // zoom with middle mouse button
92
+    MouseZoom beh2 = new MouseZoom(transGroup);
93
+    BranchGroup brM2 = new BranchGroup();
94
+    brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
95
+    brM2.addChild(beh2);
96
+    inBetween.addChild(brM2);
97
+    beh2.setSchedulingBounds(boundBox);
98
+
99
+    // move with right mouse button
100
+    MouseTranslate beh3 = new MouseTranslate(transGroup);
101
+    BranchGroup brM3 = new BranchGroup();
102
+    brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
103
+    brM3.addChild(beh3);
104
+    inBetween.addChild(brM3);
105
+    beh3.setSchedulingBounds(boundBox);
106
+
107
+    // Add all our led sphares to the universe
108
+    for (int x = 0; x < 8; x++) {
109
+      for (int y = 0; y < 8; y++) {
110
+        for (int z = 0; z < 8; z++) {
111
+          leds[x][y][z] = new Sphere(0.05f);
112
+          if ((x == 7) && (y == 7) && (z == 7)) {
113
+            Appearance a = new Appearance();
114
+            a.setMaterial(redMat);
115
+            //a.setColoringAttributes(colorRed);
116
+            leds[x][y][z].setAppearance(a);
117
+          } else {
118
+            Appearance a = new Appearance();
119
+            a.setMaterial(whiteMat);
120
+            //a.setColoringAttributes(colorRed);
121
+            leds[x][y][z].setAppearance(a);
122
+          }
123
+          TransformGroup tg = new TransformGroup();
124
+          tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
125
+          Transform3D transform = new Transform3D();
126
+          Vector3f vector = new Vector3f(x, y, z);
127
+          transform.setTranslation(vector);
128
+          tg.setTransform(transform);
129
+          tg.addChild(leds[x][y][z]);
130
+          BranchGroup allTheseGroupsScareMe = new BranchGroup();
131
+          allTheseGroupsScareMe.addChild(tg);
132
+          inBetween.addChild(allTheseGroupsScareMe);
133
+        }
134
+      }
135
+    }
136
+
137
+    // Add an ambient light
138
+    Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
139
+    AmbientLight light2 = new AmbientLight(light2Color);
140
+    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
141
+    light2.setInfluencingBounds(bounds);
142
+    BranchGroup fffuuuuu = new BranchGroup();
143
+    light2.setEnable(true);
144
+    fffuuuuu.addChild(light2);
145
+    inBetween.addChild(fffuuuuu);
146
+  }
130 147
 }
131 148
 
132 149
 public class frame extends JFrame implements ListSelectionListener {
@@ -205,12 +222,12 @@ public class frame extends JFrame implements ListSelectionListener {
205 222
      if (anim == -1){
206 223
         anim = 0;
207 224
      }
208
-	 if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
209
-	   	   frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
210
-	 }
225
+   if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
226
+         frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
227
+   }
211 228
      if(evt.getSource() == frameList){
212 229
        max = worker.numOfAnimations();
213
-	   animModel.clear();
230
+     animModel.clear();
214 231
      } else {
215 232
        max = worker.numOfFrames(anim);
216 233
        frameListModel.clear();
@@ -381,7 +398,7 @@ public class frame extends JFrame implements ListSelectionListener {
381 398
       }
382 399
     });
383 400
 
384
-	frameAdd.setBounds(544, 39, 107, 28);
401
+  frameAdd.setBounds(544, 39, 107, 28);
385 402
     frameAdd.setText("Add");
386 403
     frameAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
387 404
     cp.add(frameAdd);
@@ -391,7 +408,7 @@ public class frame extends JFrame implements ListSelectionListener {
391 408
       }
392 409
     });
393 410
 
394
-	frameRemove.setBounds(544, 70, 107, 28);
411
+  frameRemove.setBounds(544, 70, 107, 28);
395 412
     frameRemove.setText("Remove");
396 413
     frameRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
397 414
     cp.add(frameRemove);
@@ -400,12 +417,12 @@ public class frame extends JFrame implements ListSelectionListener {
400 417
         frameRemove_ActionPerformed(evt);
401 418
       }
402 419
     });
403
-	
404
-	frameRename.setBounds(544, 101, 107, 28);
405
-	frameRename.setText("Rename");
406
-  	frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
407
-  	cp.add(frameRename);
408
-  	frameRename.addActionListener(new ActionListener() {
420
+  
421
+  frameRename.setBounds(544, 101, 107, 28);
422
+  frameRename.setText("Rename");
423
+    frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
424
+    cp.add(frameRename);
425
+    frameRename.addActionListener(new ActionListener() {
409 426
     public void actionPerformed(ActionEvent evt) {
410 427
       int a = animList.getSelectedIndex();
411 428
       if (a < 0) {
@@ -443,32 +460,32 @@ public class frame extends JFrame implements ListSelectionListener {
443 460
     frmLngthTxt.setFont(new Font("Dialog", Font.PLAIN, 13));
444 461
     cp.add(frmLngthTxt);
445 462
 
446
-	frameDuration.setBounds(590, 184, 50, 24);
447
-	frameDuration.setText("OK");
448
-	frameDuration.setFont(new Font("Dialog", Font.PLAIN, 13));
449
-	cp.add(frameDuration);
450
-	frameDuration.addActionListener(new ActionListener() {
451
-		public void actionPerformed(ActionEvent evt) {
452
-			if (frmLngthTxt.getText().equals("0")) {
453
-				errorMessage("0 is not a valid value!");
454
-				frmLngthTxt.setText("1");
455
-			} else if (Integer.parseInt(frmLngthTxt.getText()) > 256) {
456
-				errorMessage("Value too high. Max: 256");
457
-				frmLngthTxt.setText("256");
458
-				return;
459
-			} else {
460
-				if (animList.getSelectedIndex() == -1) {
461
-					errorMessage("Please select an animation!");
462
-					return;
463
-				}
464
-				if (frameList.getSelectedIndex() == -1) {
465
-					errorMessage("Please select a frame!");
466
-					return;
467
-				}
468
-				worker.setFrameTime((byte)(Integer.parseInt(frmLngthTxt.getText()) - 1), animList.getSelectedIndex(), frameList.getSelectedIndex());
469
-			}
470
-		}
471
-	});
463
+  frameDuration.setBounds(590, 184, 50, 24);
464
+  frameDuration.setText("OK");
465
+  frameDuration.setFont(new Font("Dialog", Font.PLAIN, 13));
466
+  cp.add(frameDuration);
467
+  frameDuration.addActionListener(new ActionListener() {
468
+    public void actionPerformed(ActionEvent evt) {
469
+      if (frmLngthTxt.getText().equals("0")) {
470
+        errorMessage("0 is not a valid value!");
471
+        frmLngthTxt.setText("1");
472
+      } else if (Integer.parseInt(frmLngthTxt.getText()) > 256) {
473
+        errorMessage("Value too high. Max: 256");
474
+        frmLngthTxt.setText("256");
475
+        return;
476
+      } else {
477
+        if (animList.getSelectedIndex() == -1) {
478
+          errorMessage("Please select an animation!");
479
+          return;
480
+        }
481
+        if (frameList.getSelectedIndex() == -1) {
482
+          errorMessage("Please select a frame!");
483
+          return;
484
+        }
485
+        worker.setFrameTime((byte)(Integer.parseInt(frmLngthTxt.getText()) - 1), animList.getSelectedIndex(), frameList.getSelectedIndex());
486
+      }
487
+    }
488
+  });
472 489
 
473 490
     animScrollPane.setBounds(8, 264, 209, 121);
474 491
     animList.setModel(animModel);
@@ -484,7 +501,7 @@ public class frame extends JFrame implements ListSelectionListener {
484 501
       }
485 502
     });
486 503
 
487
-  	animDown.setBounds(224, 368, 99, 25);
504
+    animDown.setBounds(224, 368, 99, 25);
488 505
     animDown.setText("Move down");
489 506
     animDown.setFont(new Font("Dialog", Font.PLAIN, 13));
490 507
     cp.add(animDown);
@@ -495,10 +512,10 @@ public class frame extends JFrame implements ListSelectionListener {
495 512
     });
496 513
 
497 514
     animRename.setBounds(224, 342, 99, 25);
498
-  	animRename.setText("Rename");
499
-  	animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
500
-  	cp.add(animRename);
501
-  	animRename.addActionListener(new ActionListener() {
515
+    animRename.setText("Rename");
516
+    animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
517
+    cp.add(animRename);
518
+    animRename.addActionListener(new ActionListener() {
502 519
     public void actionPerformed(ActionEvent evt) {
503 520
       int a = animList.getSelectedIndex();
504 521
       if (a < 0) {
@@ -868,7 +885,4 @@ n = 0;
868 885
     new frame("Cube Control");
869 886
   }
870 887
   // Ende Methoden
871
-}
872
-
873
-
874
-
888
+}

Loading…
Cancel
Save