ソースを参照

Merge branch 'master' of github.com:xythobuz/LED-Cube

Conflicts:
	Cube Control/frame.java
Max Nuding 12年前
コミット
9446a5345a
1個のファイルの変更82行の追加53行の削除
  1. 82
    53
      Cube Control/frame.java

+ 82
- 53
Cube Control/frame.java ファイルの表示

1
-import java.awt.*;
2
-import java.awt.event.*;
3
-import javax.swing.*;
4
-import javax.swing.event.*;
5
-import java.io.File;
6
-import com.sun.j3d.utils.universe.*;
7
-import com.sun.j3d.utils.geometry.*;
8
-import javax.media.j3d.*;
9
-import javax.vecmath.*;
10
-import com.sun.j3d.utils.behaviors.mouse.*;
11
-
12
 /*
1
 /*
13
 * frame.java
2
 * frame.java
14
 *
3
 *
33
 * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
22
 * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
34
 */
23
 */
35
 
24
 
25
+import java.awt.*;
26
+import java.awt.event.*;
27
+import javax.swing.*;
28
+import javax.swing.event.*;
29
+import java.io.File;
30
+import com.sun.j3d.utils.universe.*;
31
+import com.sun.j3d.utils.geometry.*;
32
+import javax.media.j3d.*;
33
+import javax.vecmath.*;
34
+import com.sun.j3d.utils.behaviors.mouse.*;
35
+
36
 class Led3D {
36
 class Led3D {
37
   private Canvas3D canvas = null;
37
   private Canvas3D canvas = null;
38
   private SimpleUniverse universe = null;
38
   private SimpleUniverse universe = null;
43
 
43
 
44
   private Sphere[][][] leds = new Sphere[8][8][8];
44
   private Sphere[][][] leds = new Sphere[8][8][8];
45
 
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
-
46
+	private static ColoringAttributes redColor = new ColoringAttributes(new Color3f(1.0f, 0.0f, 0.0f), ColoringAttributes.FASTEST);
47
+	private static ColoringAttributes whiteColor = new ColoringAttributes(new Color3f(1.0f, 1.0f, 1.0f), ColoringAttributes.FASTEST);
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);
48
   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);
49
   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
 
50
 
53
   private Point3d eye = new Point3d(3.5, 3.5, -13.0);
51
   private Point3d eye = new Point3d(3.5, 3.5, -13.0);
54
   private Point3d look = new Point3d(3.5, 3.5, 0.0);
52
   private Point3d look = new Point3d(3.5, 3.5, 0.0);
68
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
66
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
69
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
67
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
70
     transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
68
     transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
69
+	transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
70
+	transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
71
     Viewer viewer = new Viewer(canvas);
71
     Viewer viewer = new Viewer(canvas);
72
     universe = new SimpleUniverse(viewingPlatform, viewer);
72
     universe = new SimpleUniverse(viewingPlatform, viewer);
73
     group.addChild(transGroup);
73
     group.addChild(transGroup);
74
     universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
74
     universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
75
-      universe.addBranchGraph(group); // Add group to universe
75
+    universe.addBranchGraph(group); // Add group to universe
76
 
76
 
77
     BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
77
     BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
78
     // roration with left mouse button
78
     // roration with left mouse button
79
     MouseRotate behaviour = new MouseRotate(transGroup);
79
     MouseRotate behaviour = new MouseRotate(transGroup);
80
     BranchGroup inBetween = new BranchGroup();
80
     BranchGroup inBetween = new BranchGroup();
81
     inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
81
     inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
82
+	inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
83
+	inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
82
     inBetween.addChild(behaviour);
84
     inBetween.addChild(behaviour);
83
     transGroup.addChild(inBetween);
85
     transGroup.addChild(inBetween);
84
     behaviour.setSchedulingBounds(boundBox);
86
     behaviour.setSchedulingBounds(boundBox);
87
     MouseZoom beh2 = new MouseZoom(transGroup);
89
     MouseZoom beh2 = new MouseZoom(transGroup);
88
     BranchGroup brM2 = new BranchGroup();
90
     BranchGroup brM2 = new BranchGroup();
89
     brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
91
     brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
92
+	brM2.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
93
+	brM2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
90
     brM2.addChild(beh2);
94
     brM2.addChild(beh2);
91
     inBetween.addChild(brM2);
95
     inBetween.addChild(brM2);
92
     beh2.setSchedulingBounds(boundBox);
96
     beh2.setSchedulingBounds(boundBox);
95
     MouseTranslate beh3 = new MouseTranslate(transGroup);
99
     MouseTranslate beh3 = new MouseTranslate(transGroup);
96
     BranchGroup brM3 = new BranchGroup();
100
     BranchGroup brM3 = new BranchGroup();
97
     brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
101
     brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
102
+	brM3.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
103
+	brM3.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
98
     brM3.addChild(beh3);
104
     brM3.addChild(beh3);
99
     inBetween.addChild(brM3);
105
     inBetween.addChild(brM3);
100
     beh3.setSchedulingBounds(boundBox);
106
     beh3.setSchedulingBounds(boundBox);
104
       for (int y = 0; y < 8; y++) {
110
       for (int y = 0; y < 8; y++) {
105
         for (int z = 0; z < 8; z++) {
111
         for (int z = 0; z < 8; z++) {
106
           leds[x][y][z] = new Sphere(0.05f);
112
           leds[x][y][z] = new Sphere(0.05f);
113
+
107
           Appearance a = new Appearance();
114
           Appearance a = new Appearance();
108
           a.setMaterial(whiteMat);
115
           a.setMaterial(whiteMat);
109
           leds[x][y][z].setAppearance(a);
116
           leds[x][y][z].setAppearance(a);
110
-          if ((x == 7) && (y == 7) && (z == 7)) {
111
-           a.setMaterial(redMat);
112
-          }
117
+		  leds[x][y][z].getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
118
+
113
           TransformGroup tg = new TransformGroup();
119
           TransformGroup tg = new TransformGroup();
114
           tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
120
           tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
121
+		  tg.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
122
+		  tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
115
           Transform3D transform = new Transform3D();
123
           Transform3D transform = new Transform3D();
116
           Vector3f vector = new Vector3f(x, y, z);
124
           Vector3f vector = new Vector3f(x, y, z);
117
           transform.setTranslation(vector);
125
           transform.setTranslation(vector);
118
           tg.setTransform(transform);
126
           tg.setTransform(transform);
119
           tg.addChild(leds[x][y][z]);
127
           tg.addChild(leds[x][y][z]);
128
+
120
           BranchGroup allTheseGroupsScareMe = new BranchGroup();
129
           BranchGroup allTheseGroupsScareMe = new BranchGroup();
130
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
131
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
132
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
121
           allTheseGroupsScareMe.addChild(tg);
133
           allTheseGroupsScareMe.addChild(tg);
122
           inBetween.addChild(allTheseGroupsScareMe);
134
           inBetween.addChild(allTheseGroupsScareMe);
123
         }
135
         }
134
     fffuuuuu.addChild(light2);
146
     fffuuuuu.addChild(light2);
135
     inBetween.addChild(fffuuuuu);
147
     inBetween.addChild(fffuuuuu);
136
   }
148
   }
149
+
150
+	// 64 Element byte array
151
+	public void setData(short[] data) {
152
+		for (int y = 0; y < 8; y++) {
153
+			for (int z = 0; z < 8; z++) {
154
+				for (int x = 0; x < 8; x++) {
155
+					Appearance a = new Appearance();
156
+					if ((data[y + (z * 8)] & (1 << x)) != 0) {
157
+						// Activate led
158
+						a.setColoringAttributes(redColor);
159
+						a.setMaterial(redMat);
160
+					} else {
161
+						// Deactivate led
162
+						a.setColoringAttributes(whiteColor);
163
+						a.setMaterial(whiteMat);
164
+					}
165
+					leds[x][y][z].setAppearance(a);
166
+				}
167
+			}
168
+		}
169
+	}
137
 }
170
 }
138
 
171
 
139
 public class frame extends JFrame implements ListSelectionListener {
172
 public class frame extends JFrame implements ListSelectionListener {
206
   }
239
   }
207
 
240
 
208
   public void valueChanged(ListSelectionEvent evt) {
241
   public void valueChanged(ListSelectionEvent evt) {
209
-    if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
210
-     int anim = animList.getSelectedIndex();
211
-     int max;
212
-     if (anim == -1){
213
-        anim = 0;
214
-     }
215
-   if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
216
-         frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
217
-   }
218
-     if(evt.getSource() == frameList){
219
-       max = worker.numOfAnimations();
220
-     animModel.clear();
221
-     } else {
222
-       max = worker.numOfFrames(anim);
223
-       frameListModel.clear();
224
-     }
225
-
226
-   // if value changed in anim, rebuild frame, else other way round
227
-   for (int i = 0; i < max; i++) {
228
-       if(evt.getSource() == animList){
229
-      frameListModel.addElement(worker.getFrameName(anim, i));
230
-      frameList.setModel(frameListModel);
231
-       } else {
232
-      animModel.addElement(worker.getAnimationName(i));
233
-      animList.setModel(animModel);
234
-       }
235
-   }
236
-    }
242
+	if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
243
+		// If animList or framsList is the source, we act...
244
+
245
+		// If both selections are valid, update frame duration and set 3D data
246
+		if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
247
+			ledView.setData(worker.getFrame(animList.getSelectedIndex(), frameList.getSelectedIndex()));
248
+			frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
249
+		} else {
250
+			// clear frame duration
251
+			frmLngthTxt.setText("");
252
+		}
253
+
254
+		if ((evt.getSource() == animList) && (animList.getSelectedIndex() != -1)) {
255
+			// animList selection changed, update frameList
256
+			frameListModel.clear();
257
+			for (int i = 0; i < worker.numOfFrames(animList.getSelectedIndex()); i++) {
258
+				frameListModel.addElement(worker.getFrameName(animList.getSelectedIndex(), i));
259
+			}
260
+			frameList.setModel(frameListModel);
261
+		}
262
+	}
237
   }
263
   }
238
 
264
 
239
   private void save() {
265
   private void save() {
287
     cp.setLayout(null);
313
     cp.setLayout(null);
288
     // Anfang Komponenten
314
     // Anfang Komponenten
289
 
315
 
316
+	// ledView init
317
+	short[] dat = new short[64];
318
+	for (int i = 0; i < dat.length; i++) {
319
+		dat[i] = 0xFF;
320
+	}
321
+	ledView.setData(dat);
322
+
290
     //----- 3D-----
323
     //----- 3D-----
291
     //-------------
324
     //-------------
292
     cubeCanvas.setBounds(8, 8, 250, 250);
325
     cubeCanvas.setBounds(8, 8, 250, 250);
609
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
642
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
610
     // Ende Komponenten
643
     // Ende Komponenten
611
     animList.addListSelectionListener(this);
644
     animList.addListSelectionListener(this);
645
+	frameList.addListSelectionListener(this);
612
     setResizable(false);
646
     setResizable(false);
613
     setVisible(true);
647
     setVisible(true);
614
   }
648
   }
774
     if(worker.addAnimation() == -1){
808
     if(worker.addAnimation() == -1){
775
       errorMessage("Could not add animation!");
809
       errorMessage("Could not add animation!");
776
     } else {
810
     } else {
777
-    int n = worker.numOfAnimations() - 1;
778
-    // would have 0 anims after successfully adding one...
779
-  /*if (n < 0) {
780
-n = 0;
781
-}*/
782
     animModel.clear();
811
     animModel.clear();
783
-    for (int i = 0; i < (n + 1); i++) {
812
+    for (int i = 0; i < worker.numOfAnimations(); i++) {
784
         animModel.add(i, worker.getAnimationName(i));
813
         animModel.add(i, worker.getAnimationName(i));
785
     }
814
     }
786
     animList.setModel(animModel);
815
     animList.setModel(animModel);

読み込み中…
キャンセル
保存