|
@@ -27,6 +27,7 @@ import com.sun.j3d.utils.geometry.*;
|
27
|
27
|
import javax.media.j3d.*;
|
28
|
28
|
import javax.vecmath.*;
|
29
|
29
|
import com.sun.j3d.utils.behaviors.mouse.*;
|
|
30
|
+import java.awt.Color;
|
30
|
31
|
|
31
|
32
|
/**
|
32
|
33
|
* This class is responsible for displaying the 3D View of our Cube.
|
|
@@ -68,46 +69,28 @@ public class Led3D {
|
68
|
69
|
|
69
|
70
|
transGroup = new TransformGroup(trans3D);
|
70
|
71
|
ViewingPlatform viewingPlatform = new ViewingPlatform();
|
71
|
|
- transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
|
72
|
|
- transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
73
|
|
- transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
|
74
|
|
- transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
|
75
|
|
- transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
|
76
|
72
|
Viewer viewer = new Viewer(canvas);
|
77
|
73
|
universe = new SimpleUniverse(viewingPlatform, viewer);
|
78
|
|
- group.addChild(transGroup);
|
79
|
|
- universe.addBranchGraph(group); // Add group to universe
|
80
|
74
|
|
81
|
75
|
BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
|
82
|
76
|
// roration with left mouse button
|
83
|
77
|
MouseRotate behaviour = new MouseRotate(transGroup);
|
84
|
|
- BranchGroup inBetween = new BranchGroup();
|
85
|
|
- inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
86
|
|
- inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
87
|
|
- inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
88
|
|
- inBetween.addChild(behaviour);
|
89
|
|
- transGroup.addChild(inBetween);
|
90
|
|
- behaviour.setSchedulingBounds(boundBox);
|
|
78
|
+ behaviour.setSchedulingBounds(boundBox);
|
|
79
|
+ transGroup.addChild(behaviour);
|
91
|
80
|
|
92
|
81
|
// zoom with middle mouse button
|
93
|
82
|
MouseZoom beh2 = new MouseZoom(transGroup);
|
94
|
|
- BranchGroup brM2 = new BranchGroup();
|
95
|
|
- brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
96
|
|
- brM2.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
97
|
|
- brM2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
98
|
|
- brM2.addChild(beh2);
|
99
|
|
- inBetween.addChild(brM2);
|
100
|
|
- beh2.setSchedulingBounds(boundBox);
|
|
83
|
+ beh2.setSchedulingBounds(boundBox);
|
|
84
|
+ transGroup.addChild(beh2);
|
101
|
85
|
|
102
|
86
|
// move with right mouse button
|
103
|
87
|
MouseTranslate beh3 = new MouseTranslate(transGroup);
|
104
|
|
- BranchGroup brM3 = new BranchGroup();
|
105
|
|
- brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
106
|
|
- brM3.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
107
|
|
- brM3.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
108
|
|
- brM3.addChild(beh3);
|
109
|
|
- inBetween.addChild(brM3);
|
110
|
88
|
beh3.setSchedulingBounds(boundBox);
|
|
89
|
+ transGroup.addChild(beh3);
|
|
90
|
+
|
|
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);
|
111
|
94
|
|
112
|
95
|
// Add all our led sphares to the universe
|
113
|
96
|
for (int x = 0; x < 8; x++) {
|
|
@@ -120,21 +103,12 @@ public class Led3D {
|
120
|
103
|
leds[x][y][z] = new Sphere(0.05f, Sphere.ENABLE_APPEARANCE_MODIFY, a);
|
121
|
104
|
|
122
|
105
|
TransformGroup tg = new TransformGroup();
|
123
|
|
- tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
|
124
|
|
- tg.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
|
125
|
|
- tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
|
126
|
106
|
Transform3D transform = new Transform3D();
|
127
|
107
|
Vector3f vector = new Vector3f(x, y, z);
|
128
|
108
|
transform.setTranslation(vector);
|
129
|
109
|
tg.setTransform(transform);
|
130
|
110
|
tg.addChild(leds[x][y][z]);
|
131
|
|
-
|
132
|
|
- BranchGroup allTheseGroupsScareMe = new BranchGroup();
|
133
|
|
- allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
|
134
|
|
- allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
|
135
|
|
- allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
|
136
|
|
- allTheseGroupsScareMe.addChild(tg);
|
137
|
|
- inBetween.addChild(allTheseGroupsScareMe);
|
|
111
|
+ transGroup.addChild(tg);
|
138
|
112
|
}
|
139
|
113
|
}
|
140
|
114
|
}
|
|
@@ -144,10 +118,10 @@ public class Led3D {
|
144
|
118
|
AmbientLight light2 = new AmbientLight(light2Color);
|
145
|
119
|
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
|
146
|
120
|
light2.setInfluencingBounds(bounds);
|
147
|
|
- BranchGroup fffuuuuu = new BranchGroup();
|
148
|
121
|
light2.setEnable(true);
|
149
|
|
- fffuuuuu.addChild(light2);
|
150
|
|
- inBetween.addChild(fffuuuuu);
|
|
122
|
+ transGroup.addChild(light2);
|
|
123
|
+ group.addChild(transGroup);
|
|
124
|
+ universe.addBranchGraph(group); // Add group to universe
|
151
|
125
|
}
|
152
|
126
|
|
153
|
127
|
/**
|