GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas3d = new Canvas3D(config); ViewingPlatform viewingPlatform = new ViewingPlatform(); viewingPlatform.setCapability(ViewingPlatform.ALLOW_BOUNDS_WRITE); viewingPlatform.setBounds(bounds); Viewer viewer = new Viewer(canvas3d); SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);
/** * Returns the TransformGroup of the viewing platform's MultiTransformGroup * which is responsible for animation. */ public TransformGroup getAnimationTG() { return getViewingPlatform().getMultiTransformGroup().getTransformGroup( ANIMATE_TG); }
/** * Set the ViewingPlatform object used by this Viewer. * * @param platform The ViewingPlatform object to set for this * Viewer object. Use null to unset the current value and * not assign assign a new ViewingPlatform object. */ public void setViewingPlatform(ViewingPlatform platform) { if (viewingPlatform != null) { viewingPlatform.removeViewer(this); } viewingPlatform = platform; if (platform != null) { view.attachViewPlatform(platform.getViewPlatform()); platform.addViewer(this); if (avatar != null) viewingPlatform.setAvatar(this, avatar); } else view.attachViewPlatform(null); } /**
/** * Sets the ViewPlatformBehavior which will operate on the ViewPlatform * transform (the TransformGroup returned by * ViewingPlatform.getViewPlatformTransform()). The ViewPlatformBehavior * may be set after the ViewingPlatform is setLive(). * If a behavior is already present, it will be detached and it's * setViewingPlatform method will be called with a parameter of null. * @param behavior The ViewPlatformBehavior to add to the ViewingPlatform. * null will remove the ViewingPlatform behavior. * @since Java 3D 1.2.1 */ public void setViewPlatformBehavior(ViewPlatformBehavior behavior) { if (behaviors != null) { removeViewPlatformBehavior((ViewPlatformBehavior)behaviors.getChild(0)); } if (behavior != null) { addViewPlatformBehavior(behavior); } }
viewingPlatform = new ViewingPlatform(transformCount) ; ViewPlatform vp = viewingPlatform.getViewPlatform() ; viewingPlatform.setNominalViewingTransform() ; TransformGroup tg = viewingPlatform.getViewPlatformTransform() ; tg.setTransform(initialViewingTransform) ;
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas3d = new Canvas3D(config); // Manually create the viewing platform so that we can customize it ViewingPlatform viewingPlatform = new ViewingPlatform(); // **** This is the part I was missing: Activation radius viewingPlatform.getViewPlatform().setActivationRadius(300f); // Set the view position back far enough so that we can see things TransformGroup viewTransform = viewingPlatform.getViewPlatformTransform(); Transform3D t3d = new Transform3D(); // Note: Now the large value works t3d.lookAt(new Point3d(0,0,150), new Point3d(0,0,0), new Vector3d(0,1,0)); t3d.invert(); viewTransform.setTransform(t3d); // Set back clip distance so things don't disappear Viewer viewer = new Viewer(canvas3d); View view = viewer.getView(); view.setBackClipDistance(300); SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer);
/** * Creates a default ViewingPlatform, attaches the first Viewer, and then * attaches the platform to the Locale. * * @param transformCount number of TransformGroups to create in the * ViewingPlatform */ private void createDefaultViewingPlatform(int transformCount) { ViewingPlatform vp = new ViewingPlatform(transformCount); setDerivedAttachPolicy(viewer[0], vp); viewer[0].setViewingPlatform(vp); vp.setUniverse(this); locale.addBranchGraph(vp); }
/** * Sets the ViewingPlatform for this behavior. This method is called by * the ViewingPlatform. If a sub-calls overrides this method, it must * call super.setViewingPlatform(vp).<p> * * NOTE: Applications should <i>not</i> call this method. * * @param vp the target ViewingPlatform for this behavior */ public void setViewingPlatform(ViewingPlatform vp) { this.vp = vp; if (vp!=null) targetTG = vp.getViewPlatformTransform(); else targetTG = null; }
Viewer[] viewers = vp.getViewers() ; if (viewers != null) { targetTG = vp.getMultiTransformGroup().getTransformGroup(0) ;
setCapability(Group.ALLOW_CHILDREN_WRITE); setCapability(Group.ALLOW_CHILDREN_EXTEND); setCapability(BranchGroup.ALLOW_DETACH); addChild(tg);
public void writeObject( DataOutput out ) throws IOException { MultiTransformGroup mtg = universe.getViewingPlatform().getMultiTransformGroup(); int mtgSize = mtg.getNumTransforms(); out.writeInt( mtgSize ); // Store the matrix from each MTG transform Transform3D trans = new Transform3D(); Matrix4d matrix = new Matrix4d(); for(int i=0; i<mtgSize; i++) { TransformGroup tg = mtg.getTransformGroup( i ); tg.getTransform( trans ); trans.get( matrix ); control.writeMatrix4d( out, matrix ); } control.writeObject( out, control.createState( universe.getViewingPlatform().getPlatformGeometry() )); control.writeObject( out, control.createState( universe.getViewer().getAvatar() )); writeLocales( out ); }
/** * Sets a view attach policy appropriate for a window eyepoint policy. * * @param v Viewer to which the ViewingPlatform will be attached * @param vp ViewingPlatform to which the Viewer will be attached */ private void setDerivedAttachPolicy(Viewer v, ViewingPlatform vp) { if (v.getView().getWindowEyepointPolicy() != View.RELATIVE_TO_FIELD_OF_VIEW) { vp.getViewPlatform().setViewAttachPolicy(View.NOMINAL_SCREEN); } }
public Panel createPanel() { Panel p = new Panel(); p.setPreferredSize(new Dimension(512, 512)); p.setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D( SimpleUniverse.getPreferredConfiguration()); p.add("Center", canvas3D); BranchGroup scene = createSceneGraph(); scene.compile(); SimpleUniverse simpleU = new SimpleUniverse(canvas3D); simpleU.getViewingPlatform().setNominalViewingTransform(); simpleU.addBranchGraph(scene); return p; } // end of HelloJava3Dd (constructor)
/** * Attaches the echo BranchGroup to the ViewingPlatform if appropriate. */ private void attachEcho() { if (vp != null && echoBranchGroup != null && !echoBranchGroupAttached) { vp.addChild(echoBranchGroup) ; echoBranchGroupAttached = true ; } }
avatarPosition = findAvatarChild((ViewerAvatar)oldAvatar);
vwp = new ViewingPlatform(numTransforms); vwp.setUniverse( this ); viewer = new Viewer[1];
/** * Sets the ViewPlatform node for this ViewingPlatform object. * * @param vp The ViewPlatform node to associate with this ViewingPlatform * object. */ public void setViewPlatform(ViewPlatform vp) { TransformGroup tg = getViewPlatformTransform(); tg.removeChild(viewPlatform); tg.addChild(vp); viewPlatform = vp; // Assign this to all Viewers. Enumeration e = viewerList.keys(); while (e.hasMoreElements()) ((Viewer)e.nextElement()).setViewingPlatform(this); }
/** * Adds a new ViewPlatformBehavior to the ViewingPlatform */ void addViewPlatformBehavior(ViewPlatformBehavior behavior) { behavior.setViewingPlatform(this); if (behaviors == null) { behaviors = new BranchGroup(); behaviors.setCapability(BranchGroup.ALLOW_DETACH); behaviors.setCapability(BranchGroup.ALLOW_CHILDREN_READ); } // otherwise detach the BranchGroup so we can add to it else { behaviors.detach(); } behaviors.addChild(behavior); this.addChild(behaviors); }
/** * Returns the TransformGroup of the viewing platform's MultiTransformGroup * which is responsible for rotation. */ public TransformGroup getRotationTG() { return getViewingPlatform().getMultiTransformGroup().getTransformGroup( ROTATION_TG); }
double viewDistance = 1.0/Math.tan(fieldOfView/2.0); t3d.set(new Vector3d(0.0, 0.0, viewDistance)); getViewPlatformTransform().setTransform(t3d);