List of usage examples for javax.media.j3d View PARALLEL_PROJECTION
int PARALLEL_PROJECTION
To view the source code for javax.media.j3d View PARALLEL_PROJECTION.
Click Source Link
From source file:PolygonOffset.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); JPanel canvasPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); canvasPanel.setLayout(gridbag);/*from w w w . ja va2 s.com*/ canvas = new Canvas3D(config); canvas.setSize(600, 600); add(canvas, BorderLayout.CENTER); u = new SimpleUniverse(canvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); } // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // set the eye at z = 2.0 viewingPlatform = u.getViewingPlatform(); Transform3D vpTrans = new Transform3D(); vpTrans.set(new Vector3f(0.0f, 0.0f, 2.0f)); viewingPlatform.getViewPlatformTransform().setTransform(vpTrans); // set up a parallel projection with clip limits at 1 and -1 view = u.getViewer().getView(); view.setProjectionPolicy(View.PARALLEL_PROJECTION); view.setFrontClipPolicy(View.VIRTUAL_EYE); view.setBackClipPolicy(View.VIRTUAL_EYE); view.setFrontClipDistance(1.0f); view.setBackClipDistance(3.0f); u.addBranchGraph(scene); // set up the sliders JPanel guiPanel = new JPanel(); guiPanel.setLayout(new GridLayout(0, 1)); FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset); dynamicSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { dynamicOffset = e.getValue(); solidPa.setPolygonOffsetFactor(dynamicOffset); } }); guiPanel.add(dynamicSlider); LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset); staticSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { staticOffset = e.getValue(); solidPa.setPolygonOffset(staticOffset); } }); guiPanel.add(staticSlider); FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f, innerScale); innerSphereSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { innerScale = e.getValue(); updateInnerScale(); } }); guiPanel.add(innerSphereSlider); if (isApplication) { JButton snapButton = new JButton("Snap Image"); snapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point loc = canvas.getLocationOnScreen(); offScreenCanvas.setOffScreenLocation(loc); Dimension dim = canvas.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; nf.setMinimumIntegerDigits(3); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(snapButton); } add(guiPanel, BorderLayout.EAST); }
From source file:PickTest.java
public void actionPerformed(ActionEvent e) { String name = ((Component) e.getSource()).getName(); String value = e.getActionCommand(); //System.out.println("action: name = " + name + " value = " + value); if (name == pickModeString) { if (value == boundsString) { setPickMode(PickCanvas.BOUNDS); } else if (value == geometryString) { setPickMode(PickCanvas.GEOMETRY); } else if (value == geometryIntersectString) { setPickMode(PickCanvas.GEOMETRY_INTERSECT_INFO); } else {/* w ww . j a v a 2s. c o m*/ System.out.println("Unknown pick mode: " + value); } } else if (name == toleranceString) { if (value == tolerance0String) { setPickTolerance(0.0f); } else if (value == tolerance2String) { setPickTolerance(2.0f); } else if (value == tolerance4String) { setPickTolerance(4.0f); } else if (value == tolerance8String) { setPickTolerance(8.0f); } else { System.out.println("Unknown tolerance: " + value); } } else if (name == viewModeString) { if (value == perspectiveString) { setViewMode(View.PERSPECTIVE_PROJECTION); } else if (value == parallelString) { setViewMode(View.PARALLEL_PROJECTION); } } else { System.out.println("Unknown action name: " + name); } }
From source file:FourByFour.java
/** * Initialization//from www. ja v a 2 s . c om */ public void init() { // Set the port number. port = 4111; // Set the graphics window size. width = 350; height = 350; // Set the weighting factors used for scoring. level_weight = 1311; move_weight = 111; time_weight = 1000; // Create the "base" color for the AWT components. setBackground(new Color(200, 200, 200)); // Read the instructions file. if (appletFlag) { // Get the host from which this applet came. host = getCodeBase().getHost(); try { inStream = new BufferedInputStream(new URL(getCodeBase(), "instructions.txt").openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; while (character != -1) { text[count++] = (byte) character; character = inStream.read(); } textString = new String(text); inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } else { try { inStream = new BufferedInputStream(new FileInputStream("instructions.txt")); text = new byte[5000]; int character = inStream.read(); int count = 0; while (character != -1) { text[count++] = (byte) character; character = inStream.read(); } textString = new String(text); inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } // Read the high-scores file. places = new int[20]; scores = new int[20]; names = new String[20]; if (appletFlag) { try { inStream = new BufferedInputStream(new URL(getCodeBase(), "scores.txt").openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32, 44); st.eolIsSignificant(false); int count = 0; int token = st.nextToken(); boolean scoreFlag = true; String string; while (count < 20) { places[count] = (int) st.nval; string = new String(""); token = st.nextToken(); while (token == StreamTokenizer.TT_WORD) { string += st.sval; string += " "; token = st.nextToken(); } names[count] = string; scores[count] = (int) st.nval; token = st.nextToken(); count++; } inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } else { try { inStream = new BufferedInputStream(new FileInputStream("scores.txt")); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32, 44); st.eolIsSignificant(false); int count = 0; int token = st.nextToken(); boolean scoreFlag = true; String string; while (count < 20) { places[count] = (int) st.nval; string = new String(""); token = st.nextToken(); while (token == StreamTokenizer.TT_WORD) { string += st.sval; string += " "; token = st.nextToken(); } names[count] = string; scores[count] = (int) st.nval; token = st.nextToken(); count++; } inStream.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } // The positions object sets up the switch nodes which // control the rendering of the player's positions. positions = new Positions(); // Create the game board object which is responsible // for keeping track of the moves on the game board // and determining what move the computer should make. board = new Board(this, positions, width, height); positions.setBoard(board); // Create a 2D graphics canvas. canvas2D = new Canvas2D(board); canvas2D.setSize(width, height); canvas2D.setLocation(width + 10, 5); canvas2D.addMouseListener(canvas2D); board.setCanvas(canvas2D); // Create the 2D backbuffer backbuffer2D = createImage(width, height); canvas2D.setBuffer(backbuffer2D); // Create a 3D graphics canvas. canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); canvas3D.setSize(width, height); canvas3D.setLocation(5, 5); // Create the scene branchgroup. BranchGroup scene3D = createScene3D(); // Create a universe with the Java3D universe utility. universe = new SimpleUniverse(canvas3D); universe.addBranchGraph(scene3D); // Use parallel projection. View view = universe.getViewer().getView(); view.setProjectionPolicy(View.PARALLEL_PROJECTION); // Set the universe Transform3D object. TransformGroup tg = universe.getViewingPlatform().getViewPlatformTransform(); Transform3D transform = new Transform3D(); transform.set(65.f, new Vector3f(0.0f, 0.0f, 400.0f)); tg.setTransform(transform); // Create the canvas container. c_container = new Panel(); c_container.setSize(720, 360); c_container.setLocation(0, 0); c_container.setVisible(true); c_container.setLayout(null); add(c_container); // Add the 2D and 3D canvases to the container. c_container.add(canvas2D); c_container.add(canvas3D); // Turn off the layout manager, widgets will be sized // and positioned explicitly. setLayout(null); // Create the button container. b_container = new Panel(); b_container.setSize(720, 70); b_container.setLocation(0, 360); b_container.setVisible(true); b_container.setLayout(null); // Create the buttons. instruct_button = new Button("Instructions"); instruct_button.setSize(135, 25); instruct_button.setLocation(10, 10); instruct_button.setVisible(true); instruct_button.addActionListener(this); new_button = new Button("New Game"); new_button.setSize(135, 25); new_button.setLocation(150, 10); new_button.setVisible(true); new_button.addActionListener(this); undo_button = new Button("Undo Move"); undo_button.setSize(135, 25); undo_button.setLocation(290, 10); undo_button.setVisible(true); undo_button.addActionListener(this); skill_button = new Button("Skill Level"); skill_button.setSize(135, 25); skill_button.setLocation(430, 10); skill_button.setVisible(true); skill_button.addActionListener(this); high_button = new Button("High Scores"); high_button.setSize(135, 25); high_button.setLocation(570, 10); high_button.setVisible(true); high_button.addActionListener(this); b_container.add(new_button); b_container.add(undo_button); b_container.add(skill_button); b_container.add(high_button); b_container.add(instruct_button); // Add the button container to the applet. add(b_container); // Create the "Skill Level" dialog box. skill_panel = new Panel(); skill_panel.setSize(400, 300); skill_panel.setLocation(200, 20); skill_panel.setLayout(null); skill_label = new Label("Pick your skill level:"); skill_label.setSize(200, 25); skill_label.setLocation(25, 20); skill_label.setVisible(true); skill_panel.add(skill_label); group = new CheckboxGroup(); Checkbox skill_1 = new Checkbox("Babe in the Woods ", group, false); Checkbox skill_2 = new Checkbox("Walk and Chew Gum ", group, false); Checkbox skill_3 = new Checkbox("Jeopardy Contestant ", group, false); Checkbox skill_4 = new Checkbox("Rocket Scientist ", group, false); Checkbox skill_5 = new Checkbox("Be afraid, be very afraid", group, true); skill_1.setSize(170, 25); skill_1.setLocation(80, 60); skill_1.setVisible(true); skill_2.setSize(170, 25); skill_2.setLocation(80, 100); skill_2.setVisible(true); skill_3.setSize(170, 25); skill_3.setLocation(80, 140); skill_3.setVisible(true); skill_4.setSize(170, 25); skill_4.setLocation(80, 180); skill_4.setVisible(true); skill_5.setSize(170, 25); skill_5.setLocation(80, 220); skill_5.setVisible(true); skill_return_button = new Button("Return"); skill_return_button.setSize(120, 25); skill_return_button.setLocation(300, 370); skill_return_button.setVisible(false); skill_return_button.addActionListener(this); skill_panel.add(skill_1); skill_panel.add(skill_2); skill_panel.add(skill_3); skill_panel.add(skill_4); skill_panel.add(skill_5); skill_panel.setVisible(false); add(skill_return_button); add(skill_panel); // Create the "Instructions" panel. instruct_return_button = new Button("Return"); instruct_return_button.setLocation(300, 370); instruct_return_button.setSize(120, 25); instruct_return_button.setVisible(false); instruct_return_button.addActionListener(this); instruct_text = new TextArea(textString, 100, 200, TextArea.SCROLLBARS_VERTICAL_ONLY); instruct_text.setSize(715, 350); instruct_text.setLocation(0, 0); instruct_text.setVisible(false); add(instruct_text); add(instruct_return_button); high_panel = new Panel(); high_panel.setSize(715, 350); high_panel.setLocation(0, 0); high_panel.setVisible(false); high_panel.setLayout(null); high_label = new Label("High Scores"); high_label.setLocation(330, 5); high_label.setSize(200, 30); high_label.setVisible(true); high_panel.add(high_label); high_places = new Label[20]; high_names = new Label[20]; high_scores = new Label[20]; for (int i = 0; i < 20; i++) { high_places[i] = new Label(Integer.toString(i + 1)); high_places[i].setSize(20, 30); high_places[i].setVisible(true); high_names[i] = new Label(names[i]); high_names[i].setSize(150, 30); high_names[i].setVisible(true); high_scores[i] = new Label(Integer.toString(scores[i])); high_scores[i].setSize(150, 30); high_scores[i].setVisible(true); if (i < 10) { high_places[i].setLocation(70, i * 30 + 40); high_names[i].setLocation(100, i * 30 + 40); high_scores[i].setLocation(260, i * 30 + 40); } else { high_places[i].setLocation(425, (i - 10) * 30 + 40); high_names[i].setLocation(455, (i - 10) * 30 + 40); high_scores[i].setLocation(615, (i - 10) * 30 + 40); } high_panel.add(high_places[i]); high_panel.add(high_names[i]); high_panel.add(high_scores[i]); } high_return_button = new Button("Return"); high_return_button.setSize(120, 25); high_return_button.setLocation(300, 370); high_return_button.setVisible(false); high_return_button.addActionListener(this); add(high_return_button); add(high_panel); // Create the "Winner" dialog box winner_panel = new Panel(); winner_panel.setLayout(null); winner_panel.setSize(600, 500); winner_panel.setLocation(0, 0); winner_return_button = new Button("Return"); winner_return_button.setSize(120, 25); winner_return_button.setLocation(300, 360); winner_return_button.addActionListener(this); winner_panel.add(winner_return_button); winner_label = new Label(""); winner_label.setSize(200, 30); winner_label.setLocation(270, 110); winner_score_label = new Label(""); winner_score_label.setSize(200, 30); winner_top_label = new Label("You have a score in the top 20."); winner_top_label.setSize(200, 25); winner_top_label.setLocation(260, 185); winner_top_label.setVisible(false); winner_name_label = new Label("Enter your name here:"); winner_name_label.setSize(150, 25); winner_name_label.setLocation(260, 210); winner_name_label.setVisible(false); winner_name = new TextField(""); winner_name.setSize(200, 30); winner_name.setLocation(260, 240); winner_name.setVisible(false); winner_panel.add(winner_label); winner_panel.add(winner_score_label); winner_panel.add(winner_top_label); winner_panel.add(winner_name_label); winner_panel.add(winner_name); winner_panel.setVisible(false); add(winner_panel); }
From source file:ViewProj.java
/** * Calculates the projection transform specified by the field of view and * clip distances specified by the view. *//*from www .j av a2s .co m*/ public void updateProjTrans() { int projType = view.getProjectionPolicy(); if (projType == View.PARALLEL_PROJECTION) { //System.out.println("PARALLEL_PROJECTION"); projTrans.setIdentity(); return; } //System.out.println("PERSPECTIVE_PROJECTION"); // figure out the perspective transform from the view double fov = view.getFieldOfView(); // n = near clip double n = frontClipDist; // f = far clip double f = backClipDist; //System.out.println("n = " + nf.format(n) + " f = " + nf.format(f)); // Create a matrix using coefficents derived from the OpenGL // glFrustum() man page. This assumes the eye point is a 0,0,0, // the front clip plane is a z = -n, the back clip plane is at // z = -f and that the front clip plane intersects the FOV so that // -1 <= X,Y <= 1 at the front plane (the last assumption may not // be true, so we'll scale later). Matrix4d matrix = new Matrix4d(); matrix.m00 = n; matrix.m11 = n; matrix.m22 = -(f + n) / (f - n); matrix.m23 = -2 * f * n / (f - n); matrix.m32 = -1; //System.out.println("matrix = " + matrix); // This is the distance where the FOV maps to a -1 to 1 area in X and Y double d = 1 / Math.tan(fov / 2); //System.out.println("n = " + nf.format(n) + " f = " + nf.format(f) + // " d = " + nf.format(d)); // this is a scaling ratio to make the OpenGL glFrustum() matrix // elements work with with the J3D matrix. It compensates for the // front clip plane not being at the FOV distance (the OpenGL // matrix expects n == d). double scale = n / d; //System.out.println("scale = " + nf.format(scale)); // scale the elements of the matrix //matrix.m00 *= 1.0/scale; //matrix.m11 *= 1.0/scale; matrix.m22 *= scale; matrix.m23 *= scale; matrix.m32 *= scale; // set the Transform3D projTrans.set(matrix); //System.out.println("projTrans = " + projTrans); }
From source file:ViewProj.java
public void init() { setLayout(new BorderLayout()); nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3);// ww w.j a v a 2 s. c o m GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); JPanel canvasPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); canvasPanel.setLayout(gridbag); canvas = new Canvas3D(config); canvas.setSize(400, 400); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 2; constraints.gridheight = 2; constraints.insets = new Insets(5, 5, 5, 5); constraints.fill = GridBagConstraints.BOTH; gridbag.setConstraints(canvas, constraints); canvasPanel.add(canvas); constraints.fill = GridBagConstraints.REMAINDER; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.gridx = 2; constraints.gridy = 0; urCanvas = new Canvas3D(config); urCanvas.setSize(200, 200); gridbag.setConstraints(urCanvas, constraints); canvasPanel.add(urCanvas); constraints.gridx = 2; constraints.gridy = 1; lrCanvas = new Canvas3D(config); lrCanvas.setSize(200, 200); gridbag.setConstraints(lrCanvas, constraints); canvasPanel.add(lrCanvas); add(canvasPanel, BorderLayout.NORTH); SimpleUniverse u = new SimpleUniverse(canvas); urUniverse = new SimpleUniverse(urCanvas); lrUniverse = new SimpleUniverse(lrCanvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); urOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = urCanvas.getScreen3D(); sOff = urOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * urOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * urOffScreenScale); // attach the offscreen canvas to the view urUniverse.getViewer().getView().addCanvas3D(urOffScreenCanvas); lrOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = lrCanvas.getScreen3D(); sOff = lrOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * lrOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * lrOffScreenScale); // attach the offscreen canvas to the view lrUniverse.getViewer().getView().addCanvas3D(lrOffScreenCanvas); } // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform = u.getViewingPlatform(); viewingPlatform.setNominalViewingTransform(); view = u.getViewer().getView(); view.setFrontClipPolicy(View.VIRTUAL_EYE); view.setBackClipPolicy(View.VIRTUAL_EYE); view.setFrontClipDistance(frontClipDist); view.setBackClipDistance(backClipDist); u.addBranchGraph(scene); // init the clipGridPts arrays for (int i = 0; i < maxClipGridPts; i++) { clipGridPtsVW[i] = new Point3f(); clipGridPtsProj[i] = new Point3f(); } // init the circlePts arrays for (int i = 0; i < numCirclePts; i++) { circlePtsVW[i] = new Point3f(); circlePtsProj[i] = new Point3f(); } // setup the ur canvas urScene = createVWorldViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. urUniverse.getViewingPlatform().setNominalViewingTransform(); View urView = urUniverse.getViewer().getView(); urView.setProjectionPolicy(View.PARALLEL_PROJECTION); urUniverse.addBranchGraph(urScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background urBgWhite = new Background(white); urBgWhite.setApplicationBounds(infiniteBounds); BranchGroup urBackBG = new BranchGroup(); urBackBG.addChild(urBgWhite); urUniverse.addBranchGraph(urBackBG); // setup the lr canvas lrScene = createProjViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. lrUniverse.getViewingPlatform().setNominalViewingTransform(); View lrView = lrUniverse.getViewer().getView(); lrView.setProjectionPolicy(View.PARALLEL_PROJECTION); lrUniverse.addBranchGraph(lrScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background lrBgWhite = new Background(white); lrBgWhite.setApplicationBounds(infiniteBounds); BranchGroup lrBackBG = new BranchGroup(); lrBackBG.addChild(lrBgWhite); lrUniverse.addBranchGraph(lrBackBG); // set up the sliders JPanel guiPanel = new JPanel(); guiPanel.setLayout(new GridLayout(0, 2)); FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset); dynamicSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { dynamicOffset = e.getValue(); solidPa.setPolygonOffsetFactor(dynamicOffset); } }); guiPanel.add(dynamicSlider); LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset); staticSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { staticOffset = e.getValue(); solidPa.setPolygonOffset(staticOffset); } }); guiPanel.add(staticSlider); // These are declared final here so they can be changed by the // listener routines below. LogFloatLabelJSlider frontClipSlider = new LogFloatLabelJSlider("Front Clip Distance", 0.001f, 10.0f, frontClipDist); final LogFloatLabelJSlider backClipSlider = new LogFloatLabelJSlider("Back Clip Distance", 1.0f, 10000.0f, backClipDist); final LogFloatLabelJSlider backClipRatioSlider = new LogFloatLabelJSlider("Back Clip Ratio", 1.0f, 10000.0f, backClipRatio); frontClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { frontClipDist = e.getValue(); view.setFrontClipDistance(frontClipDist); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); updateViewWindows(); } }); guiPanel.add(frontClipSlider); backClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipDist = e.getValue(); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); view.setBackClipDistance(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipSlider); backClipRatioSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipRatio = e.getValue(); backClipDist = backClipRatio * frontClipDist; backClipSlider.setValue(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipRatioSlider); FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f, innerScale); innerSphereSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { innerScale = e.getValue(); updateInnerScale(); } }); guiPanel.add(innerSphereSlider); JButton mainSnap = new JButton(snapImageString); mainSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point loc = canvas.getLocationOnScreen(); offScreenCanvas.setOffScreenLocation(loc); Dimension dim = canvas.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; nf.setMinimumIntegerDigits(3); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(mainSnap); JButton urSnap = new JButton(urSnapImageString); urSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap UR"); Point loc = urCanvas.getLocationOnScreen(); urOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = urCanvas.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; nf.setMinimumIntegerDigits(3); urOffScreenCanvas.snapImageFile(urOutFileBase + nf.format(urOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(urSnap); JButton lrSnap = new JButton(lrSnapImageString); lrSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap LR"); Point loc = lrCanvas.getLocationOnScreen(); lrOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = lrCanvas.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; nf.setMinimumIntegerDigits(3); lrOffScreenCanvas.snapImageFile(lrOutFileBase + nf.format(lrOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(lrSnap); add(guiPanel, BorderLayout.SOUTH); }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
public void setDisplayMode(boolean mode) { perspective = mode;//w w w . j a va2s .co m if (perspective) { view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); if (offScreenView != null) offScreenView.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); } else { view.setProjectionPolicy(View.PARALLEL_PROJECTION); if (offScreenView != null) offScreenView.setProjectionPolicy(View.PARALLEL_PROJECTION); } }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
public void newOffScreen(int w, int h) { if (w * h == 0) { logger.error("bad window size"); return;/* ww w .j a va 2 s. c o m*/ } im = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); imC = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, im, true, false); imC.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); offScreenCanvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration(), true) { @Override public void postRender() { int stdEffectiveWidth = effectiveWidth; int stdEffectiveHeight = effectiveHeight; effectiveWidth = offScreenCanvas.getWidth(); effectiveHeight = offScreenCanvas.getHeight(); J3DGraphics2D vGraphics = super.getGraphics2D(); vGraphics.setFont(new Font("sans-serif", Font.PLAIN, 10)); vGraphics.setColor(Color.YELLOW); offScreenLocToWin = new LocalToWindow(objScene, offScreenCanvas); offScreenLocToWin.update(); fireProjectionChanged(new ProjectionEvent(this, offScreenLocToWin)); draw2D(vGraphics, offScreenLocToWin, effectiveWidth, effectiveHeight); vGraphics.flush(false); effectiveWidth = stdEffectiveWidth; effectiveHeight = stdEffectiveHeight; offScreenRenderDone = true; } }; offScreenView = offScreenCanvas.getView(); offScreen = offScreenCanvas.getScreen3D(); offScreenCanvas.setOffScreenLocation(0, 0); offScreenCanvas.setOffScreenBuffer(imC); offScreen.setSize(w, h); double width = 0.0254 / 90.0 * w; double height = 0.0254 / 90.0 * h; offScreen.setPhysicalScreenWidth(width); offScreen.setPhysicalScreenHeight(height); universe.getViewer().getView().addCanvas3D(offScreenCanvas); if (offScreenView != null) if (perspective) offScreenView.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); else offScreenView.setProjectionPolicy(View.PARALLEL_PROJECTION); }