瀏覽代碼

Worked at 3D stuff

Thomas Buck 13 年之前
父節點
當前提交
8c84f9d9b6
共有 1 個文件被更改,包括 98 次插入18 次删除
  1. 98
    18
      Cube Control/frame.java

+ 98
- 18
Cube Control/frame.java 查看文件

@@ -7,6 +7,7 @@ import com.sun.j3d.utils.universe.*;
7 7
 import com.sun.j3d.utils.geometry.*;
8 8
 import javax.media.j3d.*;
9 9
 import javax.vecmath.*;
10
+import com.sun.j3d.utils.behaviors.mouse.*;
10 11
 
11 12
 /*
12 13
 * frame.java
@@ -32,14 +33,107 @@ import javax.vecmath.*;
32 33
 * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
33 34
 */
34 35
 
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
+	}
130
+}
131
+
35 132
 public class frame extends JFrame implements ListSelectionListener {
36 133
   // Anfang Variablen
37 134
   private GraphicsConfiguration gConfig = SimpleUniverse.getPreferredConfiguration();
38 135
   private Canvas3D cubeCanvas = new Canvas3D(gConfig);
39
-  SimpleUniverse universe;
40
-  Transform3D transform3d;
41
-  TransformGroup transroot;
42
-  BranchGroup branchgroup;
136
+  private Led3D ledView = new Led3D(cubeCanvas);
43 137
 
44 138
   // Anfang Attribute
45 139
   private JButton editA = new JButton();
@@ -191,20 +285,6 @@ public class frame extends JFrame implements ListSelectionListener {
191 285
     cubeCanvas.setBounds(8, 8, 250, 250);
192 286
     cp.add(cubeCanvas);
193 287
 
194
-    ColorCube cube1 = new ColorCube(0.3);
195
-    universe = new SimpleUniverse(cubeCanvas);
196
-    universe.getViewingPlatform().setNominalViewingTransform();
197
-    transform3d = new Transform3D();
198
-    transroot = new TransformGroup(transform3d);
199
-    transform3d.rotZ (Math.toRadians(30));
200
-    transroot.addChild(cube1);
201
-    transform3d.setTranslation(new Vector3d(2,2,2));
202
-    branchgroup = new BranchGroup();
203
-    branchgroup.addChild(transroot);
204
-    universe.addBranchGraph(branchgroup);
205
-
206
-
207
-
208 288
     //-------------
209 289
 
210 290
     editA.setBounds(264, 8, 107, 25);

Loading…
取消
儲存