private static void setScreenScale (double scale) { double ratio = scale / view.getScreenScale(); view.setScreenScale(scale); view.setFrontClipDistance(view.getFrontClipDistance() * ratio); view.setBackClipDistance(view.getBackClipDistance() * ratio); }
public void moveRelative (Vector3D move) { if ((view.getProjectionPolicy() == View.PARALLEL_PROJECTION)) { setScreenScale(view.getScreenScale() * (1 + move.z / zoom)); super.move(super.relToAbs(move.times(1, 1, 0))); } else super.move(super.relToAbs(move.times(1, 1, -1))); }
/** * Sets the projection mode to perspective projection with the * given field of view. In this mode, closer objects appear * larger, as in real life. A larger field of view means that * there is more perspective distortion. Reasonable values are * between 0.5 and 3.0. * * @param fov The field of view to use. Try [0.5-3.0]. */ public static void setPerspectiveProjection (double fov) { view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); view.setWindowEyepointPolicy(View.RELATIVE_TO_FIELD_OF_VIEW); view.setFieldOfView(fov); setScreenScale(1); orbit.setZoomEnable(true); perspectiveButton.setSelected(true); if ((Double)fovSpinner.getValue() != fov) fovSpinner.setValue(fov); //if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION) return; }
/** * Sets the projection mode to orthographic projection. * In this mode, parallel lines remain parallel after * projection, and there is no perspective. It is as * looking from infinitely far away with a telescope. * AutoCAD programs use this projection mode. */ public static void setParallelProjection () { if (view.getProjectionPolicy() == View.PARALLEL_PROJECTION) return; view.setProjectionPolicy(View.PARALLEL_PROJECTION); orbit.setZoomEnable(false); parallelButton.setSelected(true); setScreenScale(0.3 / zoom); }
public BUnivers(final BCanvas3D _canvas) { canvas_ = _canvas; locale_ = new Locale(this); final ViewPlatform camera = new ViewPlatform(); final BranchGroup viewGroup = new BranchGroup(); final TransformGroup viewTg = new TransformGroup(); viewTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); viewTg.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); viewTg.addChild(camera); viewGroup.addChild(viewTg); final PhysicalBody body = new PhysicalBody(); final PhysicalEnvironment env = new PhysicalEnvironment(); final View view = new View(); view.setPhysicalBody(body); view.setPhysicalEnvironment(env); view.setBackClipDistance(100); view.setFrontClipDistance(.1); view.addCanvas3D(canvas_); view.attachViewPlatform(camera); transformU_ = viewTg; position_ = new Vector3d(); viewGroup.setCapability(BranchGroup.ALLOW_DETACH); locale_.addBranchGraph(viewGroup); }
@Override public void init(VCanvas3D canvas) { GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D(); gct.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED); this.canvas = canvas; canvas.setDoubleBuffered(true); // 12.05.2015 define default size since offscreencanvas will be null // otherwise // see: https://java.net/jira/browse/JAVA3D-386 canvas.setSize(100, 100); canvas.getOffscreenCanvas3D().setDoubleBufferEnable(true); canvas.setResizeMode(JCanvas3D.RESIZE_IMMEDIATELY); offscreenCanvas = new VOffscreenCanvas3D( SimpleUniverse.getPreferredConfiguration()); universe = new SimpleUniverse(getCanvas().getOffscreenCanvas3D()); universe.getViewer().getView().addCanvas3D(offscreenCanvas); // offscreen rendering does not work with sceneantialiasing enabled! // universe.getViewer().getView().setSceneAntialiasingEnable(true); universe.getViewingPlatform().setNominalViewingTransform(); universe.getViewer().getView().setMinimumFrameCycleTime(0); universe.getViewer().getView().setFrontClipDistance(0.1); universe.getViewer().getView().setBackClipDistance(100); BranchGroup scene = createSceneGraph(); scene.compile(); universe.addBranchGraph(scene); }
/** * Sets the scale for all three dimensions. * * @param minimum The minimum value of each scale. * @param maximum The maximum value of each scale. */ public static void setScale (double minimum, double maximum) { min = minimum; max = maximum; zoom = (max - min) / 2; double center = min + zoom; //double nominalDist = camera.getPosition().z; camera.setPosition(center, center, zoom * (2 + Math.sqrt(2))); double orbitScale = 0.5 * zoom; orbit.setZoomFactor(orbitScale); orbit.setTransFactors(orbitScale, orbitScale); setOrbitCenter(new Point3d(center, center, center)); view.setFrontClipDistance(DEFAULT_FRONT_CLIP * zoom); view.setBackClipDistance(DEFAULT_BACK_CLIP * zoom); }
final double angleCamera = getCanvas3D().getView().getFieldOfView(); final double maxL = Math.max(deltaX, deltaY); getCanvas3D().getView().setBackClipDistance(Math.abs(backClip)); getCanvas3D().getView().setFrontClipDistance(backClip / 100);
/** * This method cannot be called directly. * @deprecated */ public void mouseWheelMoved (MouseWheelEvent e) { double notches = e.getWheelRotation(); //System.out.println(notches); if ((cameraMode == ORBIT_MODE) && (view.getProjectionPolicy() == View.PARALLEL_PROJECTION)) { camera.moveRelative(0, 0, notches * zoom / 20); } }
private static Appearance createCustomAppearance (boolean fill) { Appearance ap = createBlankAppearance(); PolygonAttributes pa = new PolygonAttributes(); if (!fill) pa.setPolygonMode(PolygonAttributes.POLYGON_LINE); pa.setCullFace(PolygonAttributes.CULL_NONE); LineAttributes la = new LineAttributes(); la.setLineWidth(penRadius); la.setLineAntialiasingEnable(view.getSceneAntialiasingEnable()); PointAttributes poa = new PointAttributes(); poa.setPointAntialiasingEnable(view.getSceneAntialiasingEnable()); ap.setPolygonAttributes(pa); ap.setLineAttributes(la); ap.setPointAttributes(poa); Color3f col = new Color3f(penColor); Color3f black = new Color3f(0, 0, 0); Color3f specular = new Color3f(GRAY); // Material properties Material material = new Material(col, black, col, specular, 64); material.setCapability(Material.ALLOW_COMPONENT_READ); material.setCapability(Material.ALLOW_COMPONENT_WRITE); material.setLightingEnable(true); ap.setMaterial(material); return ap; }
view.removeAllCanvas3Ds(); try { view.attachViewPlatform(null); } catch (final RuntimeException _evt) {
BCanvas3DOffScreen(final BCanvas3D _init) { super(_init.getGraphicsConfiguration(), true); initDimensions(_init); _init.getView().addCanvas3D(this); }
@Override public void dispose() { if (universe != null) { universe.getViewer().getView().removeAllCanvas3Ds(); universe.getViewer().setViewingPlatform(null); universe.removeAllLocales(); } }
/** * Sets the scale for all three dimensions. * * @param minimum The minimum value of each scale. * @param maximum The maximum value of each scale. */ public static void setScale (double minimum, double maximum) { min = minimum; max = maximum; zoom = (max - min) / 2; double center = min + zoom; //double nominalDist = camera.getPosition().z; camera.setPosition(center, center, zoom * (2 + Math.sqrt(2))); double orbitScale = 0.5 * zoom; orbit.setZoomFactor(orbitScale); orbit.setTransFactors(orbitScale, orbitScale); setOrbitCenter(new Point3d(center, center, center)); view.setFrontClipDistance(DEFAULT_FRONT_CLIP * zoom); view.setBackClipDistance(DEFAULT_BACK_CLIP * zoom); }
/** * Sets the projection mode to orthographic projection. * In this mode, parallel lines remain parallel after * projection, and there is no perspective. It is as * looking from infinitely far away with a telescope. * AutoCAD programs use this projection mode. */ public static void setParallelProjection () { if (view.getProjectionPolicy() == View.PARALLEL_PROJECTION) return; view.setProjectionPolicy(View.PARALLEL_PROJECTION); orbit.setZoomEnable(false); parallelButton.setSelected(true); setScreenScale(0.3 / zoom); }
/** * This method cannot be called directly. * @deprecated */ public void mouseWheelMoved (MouseWheelEvent e) { double notches = e.getWheelRotation(); //System.out.println(notches); if ((cameraMode == ORBIT_MODE) && (view.getProjectionPolicy() == View.PARALLEL_PROJECTION)) { camera.moveRelative(0, 0, notches * zoom / 20); } }
private static Appearance createCustomAppearance (boolean fill) { Appearance ap = createBlankAppearance(); PolygonAttributes pa = new PolygonAttributes(); if (!fill) pa.setPolygonMode(PolygonAttributes.POLYGON_LINE); pa.setCullFace(PolygonAttributes.CULL_NONE); LineAttributes la = new LineAttributes(); la.setLineWidth(penRadius); la.setLineAntialiasingEnable(view.getSceneAntialiasingEnable()); PointAttributes poa = new PointAttributes(); poa.setPointAntialiasingEnable(view.getSceneAntialiasingEnable()); ap.setPolygonAttributes(pa); ap.setLineAttributes(la); ap.setPointAttributes(poa); Color3f col = new Color3f(penColor); Color3f black = new Color3f(0, 0, 0); Color3f specular = new Color3f(GRAY); // Material properties Material material = new Material(col, black, col, specular, 64); material.setCapability(Material.ALLOW_COMPONENT_READ); material.setCapability(Material.ALLOW_COMPONENT_WRITE); material.setLightingEnable(true); ap.setMaterial(material); return ap; }
private static void setScreenScale (double scale) { double ratio = scale / view.getScreenScale(); view.setScreenScale(scale); view.setFrontClipDistance(view.getFrontClipDistance() * ratio); view.setBackClipDistance(view.getBackClipDistance() * ratio); }
/** * Sets the projection mode to perspective projection with the * given field of view. In this mode, closer objects appear * larger, as in real life. A larger field of view means that * there is more perspective distortion. Reasonable values are * between 0.5 and 3.0. * * @param fov The field of view to use. Try [0.5-3.0]. */ public static void setPerspectiveProjection (double fov) { view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION); view.setWindowEyepointPolicy(View.RELATIVE_TO_FIELD_OF_VIEW); view.setFieldOfView(fov); setScreenScale(1); orbit.setZoomEnable(true); perspectiveButton.setSelected(true); if ((Double)fovSpinner.getValue() != fov) fovSpinner.setValue(fov); //if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION) return; }
public void moveRelative (Vector3D move) { if ((view.getProjectionPolicy() == View.PARALLEL_PROJECTION)) { setScreenScale(view.getScreenScale() * (1 + move.z / zoom)); super.move(super.relToAbs(move.times(1, 1, 0))); } else super.move(super.relToAbs(move.times(1, 1, -1))); }