|
@@ -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
|
}
|