Browse Source

3D now pretty :)

Thomas Buck 12 years ago
parent
commit
1a30e1e164

+ 58
- 4
Cube Control/Led3D.java View File

@@ -28,6 +28,7 @@ import javax.media.j3d.*;
28 28
 import javax.vecmath.*;
29 29
 import com.sun.j3d.utils.behaviors.mouse.*;
30 30
 import java.awt.Color;
31
+import com.sun.j3d.utils.image.TextureLoader;
31 32
 
32 33
 /**
33 34
  * This class is responsible for displaying the 3D View of our Cube.
@@ -68,6 +69,8 @@ public class Led3D {
68 69
 	trans3D.set(mat);
69 70
 
70 71
 	transGroup = new TransformGroup(trans3D);
72
+	transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
73
+	transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
71 74
     ViewingPlatform viewingPlatform = new ViewingPlatform();
72 75
     Viewer viewer = new Viewer(canvas);
73 76
     universe = new SimpleUniverse(viewingPlatform, viewer);
@@ -88,9 +91,7 @@ public class Led3D {
88 91
     beh3.setSchedulingBounds(boundBox);
89 92
 	transGroup.addChild(beh3);
90 93
 
91
-	Background bg = new Background(0.0f, 0.0f, 0.42f);
92
-	bg.setApplicationBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
93
-	group.addChild(bg);
94
+	group.addChild(createBackground());
94 95
 
95 96
     // Add all our led sphares to the universe
96 97
     for (int x = 0; x < 8; x++) {
@@ -100,7 +101,7 @@ public class Led3D {
100 101
           a.setMaterial(whiteMat);
101 102
 		  a.setColoringAttributes(whiteColor);
102 103
 		  
103
-		  leds[x][y][z] = new Sphere(0.05f, Sphere.ENABLE_APPEARANCE_MODIFY, a);
104
+		  leds[x][y][z] = new Sphere(0.08f, Sphere.ENABLE_APPEARANCE_MODIFY, a);
104 105
 
105 106
           TransformGroup tg = new TransformGroup();
106 107
           Transform3D transform = new Transform3D();
@@ -109,8 +110,16 @@ public class Led3D {
109 110
           tg.setTransform(transform);
110 111
           tg.addChild(leds[x][y][z]);
111 112
           transGroup.addChild(tg);
113
+
114
+		  drawLedFeetVertical((double)x, y + 0.5, (double)z, 0.9f, 0.01f);
115
+		  drawLedFeetHorizontal(x + 0.5, (double)y, (double)z, 0.9f, 0.01f, 0);
116
+
112 117
         }
113 118
       }
119
+	  // 8 times, use x as y
120
+	  drawLedFeetHorizontal(0.5, (double)x, 3.5, 7.0f, 0.02f, 90);
121
+	  drawLedFeetHorizontal(6.5, (double)x, 3.5, 7.0f, 0.02f, 90);
122
+	  drawLedFeetHorizontal(3.5, (double)x, 3.5, 7.0f, 0.02f, 90);
114 123
     }
115 124
 
116 125
     // Add an ambient light
@@ -124,6 +133,43 @@ public class Led3D {
124 133
 	universe.addBranchGraph(group); // Add group to universe
125 134
   }
126 135
 
136
+	private void drawLedFeetVertical(double x, double y, double z, float length, float rad) {
137
+		// draw Feet going down
138
+		Appearance feetApp = new Appearance();
139
+		feetApp.setMaterial(whiteMat);
140
+		feetApp.setColoringAttributes(whiteColor);
141
+		Cylinder c = new Cylinder(rad, length, feetApp);
142
+
143
+		TransformGroup tg = new TransformGroup();
144
+		Transform3D transform = new Transform3D();
145
+		Vector3d vector = new Vector3d(x, y, z);
146
+		transform.setTranslation(vector);
147
+		tg.setTransform(transform);
148
+		tg.addChild(c);
149
+
150
+		transGroup.addChild(tg);
151
+	}
152
+
153
+	private void drawLedFeetHorizontal(double x, double y, double z, float length, float rad, int deg) {
154
+		// draw Feet going down
155
+		Appearance feetApp = new Appearance();
156
+		feetApp.setMaterial(whiteMat);
157
+		feetApp.setColoringAttributes(whiteColor);
158
+		Cylinder c = new Cylinder(rad, length, feetApp);
159
+
160
+		TransformGroup tg = new TransformGroup();
161
+		Transform3D transform = new Transform3D();
162
+		Vector3d vector = new Vector3d(x, y, z);
163
+		transform.rotZ(Math.toRadians(90));
164
+		if (deg != 0)
165
+			transform.rotX(Math.toRadians(deg));
166
+		transform.setTranslation(vector);
167
+		tg.setTransform(transform);
168
+		tg.addChild(c);
169
+
170
+		transGroup.addChild(tg);
171
+	}
172
+
127 173
 	/**
128 174
 	 * Prints the translation matrix that is changed by moving/rotating the 3D Cube with your mouse.
129 175
 	 */
@@ -159,4 +205,12 @@ public class Led3D {
159 205
 			}
160 206
 		}
161 207
 	}
208
+
209
+	// create nice background
210
+	private Background createBackground() {
211
+		ImageComponent2D image = new TextureLoader(getClass().getResource("bg.png"), null).getImage();
212
+		Background bg = new Background(image);
213
+		bg.setApplicationBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
214
+		return bg;
215
+	}
162 216
 }

BIN
Cube Control/bg.png View File


+ 1
- 1
Cube Control/doc/AFrame.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:17 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:33 CET 2011 -->
6 6
 <TITLE>
7 7
 AFrame
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/Animation.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:17 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:33 CET 2011 -->
6 6
 <TITLE>
7 7
 Animation
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/AnimationUtility.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:17 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:33 CET 2011 -->
6 6
 <TITLE>
7 7
 AnimationUtility
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/HelperUtility.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:18 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:34 CET 2011 -->
6 6
 <TITLE>
7 7
 HelperUtility
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/Led3D.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Led3D
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/allclasses-frame.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 All Classes
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/allclasses-noframe.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 All Classes
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/constant-values.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Constant Field Values
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/cubeWorker.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:17 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:33 CET 2011 -->
6 6
 <TITLE>
7 7
 cubeWorker
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/deprecated-list.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Deprecated List
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/frame.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:17 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:33 CET 2011 -->
6 6
 <TITLE>
7 7
 Frame
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/help-doc.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 API Help
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/index-all.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Index
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/index.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc on Mon Dec 05 17:23:19 CET 2011-->
5
+<!-- Generated by javadoc on Mon Dec 05 20:09:35 CET 2011-->
6 6
 <TITLE>
7 7
 Generated Documentation (Untitled)
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/layerEditFrame.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:18 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:34 CET 2011 -->
6 6
 <TITLE>
7 7
 layerEditFrame
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/overview-tree.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Class Hierarchy
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/package-frame.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 &lt;Unnamed&gt;
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/package-summary.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/package-tree.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
  Class Hierarchy
8 8
 </TITLE>

+ 1
- 1
Cube Control/doc/serialized-form.html View File

@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5
-<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 17:23:19 CET 2011 -->
5
+<!-- Generated by javadoc (build 1.6.0_29) on Mon Dec 05 20:09:35 CET 2011 -->
6 6
 <TITLE>
7 7
 Serialized Form
8 8
 </TITLE>

Loading…
Cancel
Save