|
@@ -1,14 +1,3 @@
|
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
|
2
|
* frame.java
|
14
|
3
|
*
|
|
@@ -33,6 +22,17 @@ import com.sun.j3d.utils.behaviors.mouse.*;
|
33
|
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
|
36
|
class Led3D {
|
37
|
37
|
private Canvas3D canvas = null;
|
38
|
38
|
private SimpleUniverse universe = null;
|
|
@@ -43,12 +43,10 @@ class Led3D {
|
43
|
43
|
|
44
|
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
|
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
|
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
|
51
|
private Point3d eye = new Point3d(3.5, 3.5, -13.0);
|
54
|
52
|
private Point3d look = new Point3d(3.5, 3.5, 0.0);
|
|
@@ -56,11 +54,6 @@ class Led3D {
|
56
|
54
|
|
57
|
55
|
Led3D(Canvas3D canv) {
|
58
|
56
|
|
59
|
|
- //Material
|
60
|
|
-
|
61
|
|
-
|
62
|
|
-
|
63
|
|
-
|
64
|
57
|
canvas = canv;
|
65
|
58
|
group = new BranchGroup();
|
66
|
59
|
// Position viewer, so we are looking at object
|
|
@@ -73,17 +66,21 @@ class Led3D {
|
73
|
66
|
transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
|
74
|
67
|
transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
75
|
68
|
transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
|
|
69
|
+ transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
|
|
70
|
+ transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
|
76
|
71
|
Viewer viewer = new Viewer(canvas);
|
77
|
72
|
universe = new SimpleUniverse(viewingPlatform, viewer);
|
78
|
73
|
group.addChild(transGroup);
|
79
|
74
|
universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
|
80
|
|
- universe.addBranchGraph(group); // Add group to universe
|
|
75
|
+ universe.addBranchGraph(group); // Add group to universe
|
81
|
76
|
|
82
|
77
|
BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
|
83
|
78
|
// roration with left mouse button
|
84
|
79
|
MouseRotate behaviour = new MouseRotate(transGroup);
|
85
|
80
|
BranchGroup inBetween = new BranchGroup();
|
86
|
81
|
inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
|
82
|
+ inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
|
83
|
+ inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
87
|
84
|
inBetween.addChild(behaviour);
|
88
|
85
|
transGroup.addChild(inBetween);
|
89
|
86
|
behaviour.setSchedulingBounds(boundBox);
|
|
@@ -92,6 +89,8 @@ class Led3D {
|
92
|
89
|
MouseZoom beh2 = new MouseZoom(transGroup);
|
93
|
90
|
BranchGroup brM2 = new BranchGroup();
|
94
|
91
|
brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
|
92
|
+ brM2.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
|
93
|
+ brM2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
95
|
94
|
brM2.addChild(beh2);
|
96
|
95
|
inBetween.addChild(brM2);
|
97
|
96
|
beh2.setSchedulingBounds(boundBox);
|
|
@@ -100,6 +99,8 @@ class Led3D {
|
100
|
99
|
MouseTranslate beh3 = new MouseTranslate(transGroup);
|
101
|
100
|
BranchGroup brM3 = new BranchGroup();
|
102
|
101
|
brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
|
102
|
+ brM3.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
|
103
|
+ brM3.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
103
|
104
|
brM3.addChild(beh3);
|
104
|
105
|
inBetween.addChild(brM3);
|
105
|
106
|
beh3.setSchedulingBounds(boundBox);
|
|
@@ -109,25 +110,26 @@ class Led3D {
|
109
|
110
|
for (int y = 0; y < 8; y++) {
|
110
|
111
|
for (int z = 0; z < 8; z++) {
|
111
|
112
|
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
|
|
- }
|
|
113
|
+
|
|
114
|
+ Appearance a = new Appearance();
|
|
115
|
+ a.setMaterial(whiteMat);
|
|
116
|
+ leds[x][y][z].setAppearance(a);
|
|
117
|
+ leds[x][y][z].getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
|
|
118
|
+
|
123
|
119
|
TransformGroup tg = new TransformGroup();
|
124
|
120
|
tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
|
|
121
|
+ tg.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
|
|
122
|
+ tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
|
125
|
123
|
Transform3D transform = new Transform3D();
|
126
|
124
|
Vector3f vector = new Vector3f(x, y, z);
|
127
|
125
|
transform.setTranslation(vector);
|
128
|
126
|
tg.setTransform(transform);
|
129
|
127
|
tg.addChild(leds[x][y][z]);
|
|
128
|
+
|
130
|
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);
|
131
|
133
|
allTheseGroupsScareMe.addChild(tg);
|
132
|
134
|
inBetween.addChild(allTheseGroupsScareMe);
|
133
|
135
|
}
|
|
@@ -144,6 +146,27 @@ class Led3D {
|
144
|
146
|
fffuuuuu.addChild(light2);
|
145
|
147
|
inBetween.addChild(fffuuuuu);
|
146
|
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
|
+ }
|
147
|
170
|
}
|
148
|
171
|
|
149
|
172
|
public class frame extends JFrame implements ListSelectionListener {
|
|
@@ -216,34 +239,27 @@ public class frame extends JFrame implements ListSelectionListener {
|
216
|
239
|
}
|
217
|
240
|
|
218
|
241
|
public void valueChanged(ListSelectionEvent evt) {
|
219
|
|
- if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
|
220
|
|
- int anim = animList.getSelectedIndex();
|
221
|
|
- int max;
|
222
|
|
- if (anim == -1){
|
223
|
|
- anim = 0;
|
224
|
|
- }
|
225
|
|
- if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
|
226
|
|
- frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
|
227
|
|
- }
|
228
|
|
- if(evt.getSource() == frameList){
|
229
|
|
- max = worker.numOfAnimations();
|
230
|
|
- animModel.clear();
|
231
|
|
- } else {
|
232
|
|
- max = worker.numOfFrames(anim);
|
233
|
|
- frameListModel.clear();
|
234
|
|
- }
|
235
|
|
-
|
236
|
|
- // if value changed in anim, rebuild frame, else other way round
|
237
|
|
- for (int i = 0; i < max; i++) {
|
238
|
|
- if(evt.getSource() == animList){
|
239
|
|
- frameListModel.addElement(worker.getFrameName(anim, i));
|
240
|
|
- frameList.setModel(frameListModel);
|
241
|
|
- } else {
|
242
|
|
- animModel.addElement(worker.getAnimationName(i));
|
243
|
|
- animList.setModel(animModel);
|
244
|
|
- }
|
245
|
|
- }
|
246
|
|
- }
|
|
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
|
+ }
|
247
|
263
|
}
|
248
|
264
|
|
249
|
265
|
private void save() {
|
|
@@ -297,6 +313,13 @@ public class frame extends JFrame implements ListSelectionListener {
|
297
|
313
|
cp.setLayout(null);
|
298
|
314
|
// Anfang Komponenten
|
299
|
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
|
+
|
300
|
323
|
//----- 3D-----
|
301
|
324
|
//-------------
|
302
|
325
|
cubeCanvas.setBounds(8, 8, 250, 250);
|
|
@@ -619,6 +642,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
619
|
642
|
frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
|
620
|
643
|
// Ende Komponenten
|
621
|
644
|
animList.addListSelectionListener(this);
|
|
645
|
+ frameList.addListSelectionListener(this);
|
622
|
646
|
setResizable(false);
|
623
|
647
|
setVisible(true);
|
624
|
648
|
}
|
|
@@ -784,13 +808,8 @@ public class frame extends JFrame implements ListSelectionListener {
|
784
|
808
|
if(worker.addAnimation() == -1){
|
785
|
809
|
errorMessage("Could not add animation!");
|
786
|
810
|
} else {
|
787
|
|
- int n = worker.numOfAnimations() - 1;
|
788
|
|
- // would have 0 anims after successfully adding one...
|
789
|
|
- /*if (n < 0) {
|
790
|
|
-n = 0;
|
791
|
|
-}*/
|
792
|
811
|
animModel.clear();
|
793
|
|
- for (int i = 0; i < (n + 1); i++) {
|
|
812
|
+ for (int i = 0; i < worker.numOfAnimations(); i++) {
|
794
|
813
|
animModel.add(i, worker.getAnimationName(i));
|
795
|
814
|
}
|
796
|
815
|
animList.setModel(animModel);
|
|
@@ -885,4 +904,4 @@ n = 0;
|
885
|
904
|
new frame("Cube Control");
|
886
|
905
|
}
|
887
|
906
|
// Ende Methoden
|
888
|
|
-}
|
|
907
|
+}
|