public ObjectViewer(URL url) { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add("Center", canvas3D); BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000); BranchGroup root = new BranchGroup(); BranchGroup scene = createSceneGraph(url); scene.setBoundsAutoCompute(true); System.out.println(scene.getBounds()); BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds()); SimpleUniverse univ = new SimpleUniverse(canvas3D); ViewingPlatform view = univ.getViewingPlatform(); view.setNominalViewingTransform(); Transform3D t = new Transform3D(); TransformGroup viewTransform = view.getViewPlatformTransform(); t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius())); viewTransform.setTransform(t); BranchGroup lights = new BranchGroup(); Light light = new AmbientLight(); light.setInfluencingBounds(bounds); lights.addChild(light); light = new DirectionalLight(); light.setInfluencingBounds(bounds); lights.addChild(light); root.addChild(lights); TransformGroup tg = new TransformGroup(); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.addChild(scene); root.addChild(tg); MouseRotate mouse = new MouseRotate(); mouse.setTransformGroup(tg); mouse.setSchedulingBounds(bounds); root.addChild(mouse); MouseZoom mousezoom = new MouseZoom(); mousezoom.setTransformGroup(tg); mousezoom.setSchedulingBounds(bounds); root.addChild(mousezoom); Background background = new Background(1, 1, 1); background.setApplicationBounds(bounds); root.addChild(background); root.compile(); univ.addBranchGraph(root); }
// // Build scene // public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; float front = ((Float) fronts[currentFront].value).floatValue(); float back = ((Float) backs[currentBack].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false); // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere( new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the fog color, front & back distances, and // its influencing bounds fog = new LinearFog(); fog.setColor(color); fog.setFrontDistance(front); fog.setBackDistance(back); fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE); fog.setInfluencingBounds(worldBounds); scene.addChild(fog); // END EXAMPLE TOPIC // Set the background color and its application bounds // Usually, the background color should match the fog color // or the results look odd. background = new Background(); background.setColor(color); background.setApplicationBounds(worldBounds); background.setCapability(Background.ALLOW_COLOR_WRITE); scene.addChild(background); // Build foreground geometry scene.addChild(new ColumnScene(this)); return scene; }
public void paint(Graphics g) { // Vault-Tech logo Background.drawWall(g); Logo.drawCircles(g); Logo.drawLines(g); Words.drawTop(g); Words.drawBottom(g); }
// // Handle checkboxes and menu choices // public void checkboxChanged(CheckboxMenu menu, int check) { if (menu == backgroundColorMenu) { // Change the background color currentBackgroundColor = check; Color3f color = (Color3f) colors[check].value; background.setColor(color); return; } if (menu == colorMenu) { // Change the fog color currentColor = check; Color3f color = (Color3f) colors[check].value; fog.setColor(color); // If background is coupled, set the background color if (coupledBackgroundOnOff) { currentBackgroundColor = currentColor; backgroundColorMenu.setCurrent(check); background.setColor(color); } return; } if (menu == frontMenu) { // Change the fog front distance currentFront = check; float front = ((Float) fronts[currentFront].value).floatValue(); fog.setFrontDistance(front); return; } if (menu == backMenu) { // Change the fog back distance currentBack = check; float back = ((Float) backs[currentBack].value).floatValue(); fog.setBackDistance(back); return; } // Handle all other checkboxes super.checkboxChanged(menu, check); }
@Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; background.paint(g2); ship.paint(g2); for (int i = 0; i < aliens.length; i++) { aliens[i].paint(g2); } if (gameOver) { drawMessage(g2, "You've been hit!"); } else if (gameWon) { drawMessage(g2, "Congratulations, you've escaped!"); } else if (waveMessageCounter > 0) { drawMessage(g2, "Wave " + wave); } }
public void itemStateChanged(ItemEvent event) { Object src = event.getSource(); // Check if it is the coupled background choice if (src == coupledBackgroundOnOffMenu) { coupledBackgroundOnOff = coupledBackgroundOnOffMenu.getState(); if (coupledBackgroundOnOff) { currentBackgroundColor = currentColor; backgroundColorMenu.setCurrent(currentColor); Color3f color = (Color3f) colors[currentColor].value; background.setColor(color); backgroundColorMenu.setEnabled(false); } else { backgroundColorMenu.setEnabled(true); } } // Handle all other checkboxes super.itemStateChanged(event); }