Java Reference
In-Depth Information
Figure 6. Code segment and result for MultiViewApp.java
1.
public BranchGroup createViewGraph() {
2.
final int numberOfViews = 4;
3.
Canvas3D canvas3D[] = new Canvas3D[numberOfViews];
4.
String caption[] = {"Front View", "Side View", "Plan View", "Zoom Out View"};
5.
TransformGroup viewPlatform;
6.
viewManager = new ViewManager(this, 2, 2);
7.
BranchGroup viewRoot = new BranchGroup();
8.
TransformGroup transformGroup = new TransformGroup();
9.
viewRoot.addChild(transformGroup);
10.
GraphicsConfiguration config = viewManager.getPreferredGraphicsConfiguration();
11.
for (int i = 0; i < numberOfViews; i++) {
12.
canvas3D[i] = new Canvas3D(config);
13.
viewManager.add(canvas3D[i], caption[i]);
14.
viewPlatform = createViewPlatform(canvas3D[i], i);
15.
transformGroup.addChild(viewPlatform); }
16.
return viewRoot; }
17.
18. public TransformGroup createViewPlatform(Canvas3D canvas3D, int mode) {
19.
Transform3D transform3D = vpTransform3D(mode);
20.
ViewPlatform viewPlatform = new ViewPlatform();
21.
TransformGroup objTransform = new TransformGroup(transform3D);
22.
objTransform.addChild(viewPlatform);
23.
View view = new View();
24.
view.attachViewPlatform(viewPlatform);
25.
view.addCanvas3D(canvas3D);
26.
view.setPhysicalBody(new PhysicalBody());
27.
view.setPhysicalEnvironment(new PhysicalEnvironment());
28.
return objTransform; }
29.
30. public Transform3D vpTransform3D(int mode) {
31.
Transform3D transform3D = new Transform3D();
32.
switch (mode) {
33.
case FRONT_VIEW: break;
34.
case SIDE_VIEW:
transform3D.rotY(Math.PI / 2.0d); break;
35.
case PLAN_VIEW:
transform3D.rotX(-1 * Math.PI / 2.0d); break;
36.
case ZOOM_OUT:
transform3D.setTranslation(new Vector3f(0.0f, 0.0f, 3.0f)); break; }
37.
return transform3D; }
views can be readily done by using appropriate transforms and associating these with the
relevant view platforms.
Following this approach, Figure 6 shows the code segment and result for getting four
views by using a loop to create a number of transform groups, view platforms, and canvas.
The transform for each platform is then initiated depending on a specific view needed by
using the method vpTransform3D.
Search WWH ::




Custom Search