Browse Source

Worked at 3D stuff...

Thomas Buck 13 years ago
parent
commit
450a68e3fb
2 changed files with 87 additions and 68 deletions
  1. 86
    67
      Cube Control/frame.java
  2. 1
    1
      Cube Control/makefile

+ 86
- 67
Cube Control/frame.java View File

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);
56
 
54
 
57
   Led3D(Canvas3D canv) {
55
   Led3D(Canvas3D canv) {
58
   
56
   
59
-    //Material
60
-
61
-
62
-  
63
-  
64
     canvas = canv;
57
     canvas = canv;
65
     group = new BranchGroup();
58
     group = new BranchGroup();
66
     // Position viewer, so we are looking at object
59
     // Position viewer, so we are looking at object
73
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
66
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
74
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
67
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
75
     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);
76
     Viewer viewer = new Viewer(canvas);
71
     Viewer viewer = new Viewer(canvas);
77
     universe = new SimpleUniverse(viewingPlatform, viewer);
72
     universe = new SimpleUniverse(viewingPlatform, viewer);
78
     group.addChild(transGroup);
73
     group.addChild(transGroup);
79
     universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
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
     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));
83
     // roration with left mouse button
78
     // roration with left mouse button
84
     MouseRotate behaviour = new MouseRotate(transGroup);
79
     MouseRotate behaviour = new MouseRotate(transGroup);
85
     BranchGroup inBetween = new BranchGroup();
80
     BranchGroup inBetween = new BranchGroup();
86
     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);
87
     inBetween.addChild(behaviour);
84
     inBetween.addChild(behaviour);
88
     transGroup.addChild(inBetween);
85
     transGroup.addChild(inBetween);
89
     behaviour.setSchedulingBounds(boundBox);
86
     behaviour.setSchedulingBounds(boundBox);
92
     MouseZoom beh2 = new MouseZoom(transGroup);
89
     MouseZoom beh2 = new MouseZoom(transGroup);
93
     BranchGroup brM2 = new BranchGroup();
90
     BranchGroup brM2 = new BranchGroup();
94
     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);
95
     brM2.addChild(beh2);
94
     brM2.addChild(beh2);
96
     inBetween.addChild(brM2);
95
     inBetween.addChild(brM2);
97
     beh2.setSchedulingBounds(boundBox);
96
     beh2.setSchedulingBounds(boundBox);
100
     MouseTranslate beh3 = new MouseTranslate(transGroup);
99
     MouseTranslate beh3 = new MouseTranslate(transGroup);
101
     BranchGroup brM3 = new BranchGroup();
100
     BranchGroup brM3 = new BranchGroup();
102
     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);
103
     brM3.addChild(beh3);
104
     brM3.addChild(beh3);
104
     inBetween.addChild(brM3);
105
     inBetween.addChild(brM3);
105
     beh3.setSchedulingBounds(boundBox);
106
     beh3.setSchedulingBounds(boundBox);
109
       for (int y = 0; y < 8; y++) {
110
       for (int y = 0; y < 8; y++) {
110
         for (int z = 0; z < 8; z++) {
111
         for (int z = 0; z < 8; z++) {
111
           leds[x][y][z] = new Sphere(0.05f);
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
           TransformGroup tg = new TransformGroup();
119
           TransformGroup tg = new TransformGroup();
124
           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);
125
           Transform3D transform = new Transform3D();
123
           Transform3D transform = new Transform3D();
126
           Vector3f vector = new Vector3f(x, y, z);
124
           Vector3f vector = new Vector3f(x, y, z);
127
           transform.setTranslation(vector);
125
           transform.setTranslation(vector);
128
           tg.setTransform(transform);
126
           tg.setTransform(transform);
129
           tg.addChild(leds[x][y][z]);
127
           tg.addChild(leds[x][y][z]);
128
+
130
           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);
131
           allTheseGroupsScareMe.addChild(tg);
133
           allTheseGroupsScareMe.addChild(tg);
132
           inBetween.addChild(allTheseGroupsScareMe);
134
           inBetween.addChild(allTheseGroupsScareMe);
133
         }
135
         }
144
     fffuuuuu.addChild(light2);
146
     fffuuuuu.addChild(light2);
145
     inBetween.addChild(fffuuuuu);
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
 public class frame extends JFrame implements ListSelectionListener {
172
 public class frame extends JFrame implements ListSelectionListener {
216
   }
239
   }
217
 
240
 
218
   public void valueChanged(ListSelectionEvent evt) {
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
   private void save() {
265
   private void save() {
297
     cp.setLayout(null);
313
     cp.setLayout(null);
298
     // Anfang Komponenten
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
     //----- 3D-----
323
     //----- 3D-----
301
     //-------------
324
     //-------------
302
     cubeCanvas.setBounds(8, 8, 250, 250);
325
     cubeCanvas.setBounds(8, 8, 250, 250);
619
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
642
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
620
     // Ende Komponenten
643
     // Ende Komponenten
621
     animList.addListSelectionListener(this);
644
     animList.addListSelectionListener(this);
645
+	frameList.addListSelectionListener(this);
622
     setResizable(false);
646
     setResizable(false);
623
     setVisible(true);
647
     setVisible(true);
624
   }
648
   }
784
     if(worker.addAnimation() == -1){
808
     if(worker.addAnimation() == -1){
785
       errorMessage("Could not add animation!");
809
       errorMessage("Could not add animation!");
786
     } else {
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
     animModel.clear();
811
     animModel.clear();
793
-    for (int i = 0; i < (n + 1); i++) {
812
+    for (int i = 0; i < worker.numOfAnimations(); i++) {
794
         animModel.add(i, worker.getAnimationName(i));
813
         animModel.add(i, worker.getAnimationName(i));
795
     }
814
     }
796
     animList.setModel(animModel);
815
     animList.setModel(animModel);
885
     new frame("Cube Control");
904
     new frame("Cube Control");
886
   }
905
   }
887
   // Ende Methoden
906
   // Ende Methoden
888
-}
907
+}

+ 1
- 1
Cube Control/makefile View File

12
 
12
 
13
 # Windows doesn't like *.class, so we have to maintain a list of all classes :(
13
 # Windows doesn't like *.class, so we have to maintain a list of all classes :(
14
 ifeq ($(TARGET),win)
14
 ifeq ($(TARGET),win)
15
-INJAR = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class frame$$22.class frame$$23.class frame$$24.class AFrame.class Animation.class AnimationUtility.class HelperUtility.class LEDoff.png LEDon.png serialHelper.exe
15
+INJAR = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class frame$$22.class frame$$23.class frame$$24.class AFrame.class Animation.class AnimationUtility.class HelperUtility.class Led3D.class LEDoff.png LEDon.png serialHelper.exe
16
 else
16
 else
17
 INJAR = *.class *.png serialHelper
17
 INJAR = *.class *.png serialHelper
18
 endif
18
 endif

Loading…
Cancel
Save