private BranchGroup createSceneGraph() { BranchGroup root = new BranchGroup(); root.setCapability(BranchGroup.ALLOW_DETACH); createSpinTG(); root.addChild(spin); SimpleBehavior myRotationBehavior = new SimpleBehavior(spin); myRotationBehavior.setSchedulingBounds(new BoundingSphere()); root.addChild(myRotationBehavior); KeyNavigatorBehavior behavior = new KeyNavigatorBehavior(spin); BoundingSphere bounds = new BoundingSphere(); behavior.setSchedulingBounds(bounds); root.addChild(behavior); // mouse-directed rotation MouseRotate rotator = new MouseRotate(spin); rotator.setSchedulingBounds(bounds); root.addChild(rotator); // mouse-based translation MouseTranslate translator = new MouseTranslate(spin); translator.setSchedulingBounds(bounds); root.addChild(translator); // mouse-directed zoom MouseZoom zoom = new MouseZoom(); zoom.setSchedulingBounds(bounds); root.addChild(zoom); // make background blue Background background = new Background(Colors.blue); background.setApplicationBounds(bounds); root.addChild(background); // light AmbientLight light = new AmbientLight(true, new Color3f(Color.red)); light.setInfluencingBounds(bounds); root.addChild(light); PointLight ptlight = new PointLight(new Color3f(Color.red), new Point3f(0f, 0f, -5f), new Point3f(1f, 0f, 0f)); ptlight.setInfluencingBounds(bounds); root.addChild(ptlight); PointLight ptlight2 = new PointLight( new Color3f(Color.orange), new Point3f(-2f, 2f, 2f), new Point3f(1f, 0f, 0f)); ptlight2.setInfluencingBounds(bounds); root.addChild(ptlight2); // let Java3d perform optimization on this scene graph root.compile(); return root; }
public void prepareCorak( String projectPath, CorakLSystem cor, CorakDataObject obj, boolean encloseOBJ) { this.projectPath = projectPath; // initiate our "turtle" -> Canting canting = new Canting(cor, obj); // start creating shapes based on Cor timer = System.currentTimeMillis(); canting.generate(encloseOBJ); BoundingSphere lightingBounds = new BoundingSphere(new Point3d(0, 0, 0), FARTHEST); camLamp = new PointLight(); camLamp.setCapability(PointLight.ALLOW_POSITION_READ); camLamp.setCapability(PointLight.ALLOW_POSITION_WRITE); camLamp.setColor(new Color3f(1.0f, 1.0f, 1.0f)); camLamp.setInfluencingBounds(lightingBounds); ambient = new AmbientLight(); ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f)); ambient.setInfluencingBounds(lightingBounds); canting.getBatikBG().addChild(camLamp); canting.getBatikBG().addChild(ambient); // attach generated shapes to root TransformGroup Enumeration kaintgchildren = kainTG.getAllChildren(); while (kaintgchildren.hasMoreElements()) { Node child = (Node) kaintgchildren.nextElement(); if (child instanceof Measurer) { ((Measurer) child).removeAllChildren(); } else { kainTG.removeChild(child); } } // canting.getBatikBG().compile(); kainTG.addChild(canting.getBatikBG()); timer = System.currentTimeMillis() - timer; // System.out.println("Timer= " + timer); bs = (BoundingSphere) canting.getBatikBG().getBounds(); }
public void moveCamera() { try { cameraT3D.lookAt(cameraPos, cameraFocus, up); cameraT3D.invert(); cameraTG.setTransform(cameraT3D); // lamp position at camera camLamp.setPosition(new Point3f(cameraPos)); // camera distance to object camDist = cameraPos.distance(getObjCenter()); } catch (SingularMatrixException ex) { ex.printStackTrace(); } }
/** * Used to create a new instance of the node. This routine is called by <code>cloneTree</code> to * duplicate the current node. * * @param forceDuplicate when set to <code>true</code>, causes the <code>duplicateOnCloneTree * </code> flag to be ignored. When <code>false</code>, the value of each node's <code> * duplicateOnCloneTree</code> variable determines whether NodeComponent data is duplicated or * copied. * @see Node#cloneTree * @see Node#cloneNode * @see Node#duplicateNode * @see NodeComponent#setDuplicateOnCloneTree */ public Node cloneNode(boolean forceDuplicate) { PointLight p = new PointLight(); p.duplicateNode(this, forceDuplicate); return p; }