/Users/lyon/j4p/src/j3d/cr325/BasicUniverse.java

1    package j3d.cr325; 
2     
3    import j3d.Utils; 
4     
5    import javax.media.j3d.*; 
6    import javax.vecmath.Vector3f; 
7     
8    import com.sun.j3d.utils.universe.ViewingPlatform; 
9     
10   /** 
11    * DocJava, Inc. 
12    * http://www.docjava.com 
13    * Programmer: dlyon 
14    * Date: Mar 30, 2004 
15    * Time: 3:26:29 PM 
16    */ 
17   public class BasicUniverse { 
18       private VirtualUniverse universe = new VirtualUniverse(); 
19       private Locale locale = new Locale(universe); 
20       private BranchGroup viewBranchGroup = Utils.getBranchGroup(); 
21       private TransformGroup viewTransformGroup = Utils.getTransformGroup(); 
22       private ViewPlatform viewPlatform = Utils.getViewPlatform(); 
23       private ViewingPlatform viewingPlatform = new ViewingPlatform(); 
24       private View view = new View(); 
25       private Canvas3D canvas3d; 
26       private float zViewingDistance; 
27    
28       public Transform3D getViewTransform3D() { 
29           Transform3D t3d = new Transform3D(); 
30           viewTransformGroup.getTransform(t3d); 
31           return t3d; 
32       } 
33       public BasicUniverse(Canvas3D canvas3d, float zViewingDistance){ 
34           this.canvas3d = canvas3d; 
35    
36           this.zViewingDistance = zViewingDistance; 
37           Utils.addKeyboardNavigation(viewTransformGroup,viewBranchGroup); 
38           setupViewPlatform(); 
39           viewBranchGroup.addChild(viewTransformGroup); 
40           setupView(canvas3d); 
41           view.attachViewPlatform(viewPlatform); 
42           locale.addBranchGraph(viewBranchGroup); 
43       } 
44       public ViewPlatform getViewPlatform() { 
45           return viewPlatform; 
46       } 
47       private void setupView(Canvas3D c){ 
48           view.addCanvas3D(c); 
49           view.setPhysicalBody(new PhysicalBody()); 
50           view.setPhysicalEnvironment(new PhysicalEnvironment()); 
51       } 
52       private void setupViewPlatform(){ 
53           //viewingPlatform.addChild(viewPlatform); 
54           setViewingDistance(zViewingDistance); 
55           viewTransformGroup.addChild(viewPlatform); 
56       } 
57       public void setViewingDistance(float viewDistance){ 
58           zViewingDistance = viewDistance; 
59           Transform3D transform = new Transform3D(); 
60           transform.set(new Vector3f(0,0,zViewingDistance)); 
61           viewTransformGroup.setTransform(transform); 
62       } 
63       public void addBranchGraph(BranchGroup bg){ 
64           locale.addBranchGraph(bg); 
65       } 
66       public TransformGroup getViewTransformGroup(){ 
67           return viewTransformGroup; 
68       } 
69       public View getView() { 
70           return view; 
71       } 
72    
73   } 
74