/** * Convert an iso coordinate to the (uncorrected) map tile that lives there. * */ public MapPoint fromIsoCoord(final Point2D in, final CameraAngle a) { Point2D t; try { switch (a) { case UL: t = rUL.inverseTransform(isoTransform.inverseTransform(in)); return new MapPoint((int) (t.getX() - 0.5), (int) t.getY()); case LL: t = rLL.inverseTransform(isoTransform.inverseTransform(in)); return new MapPoint((int) (t.getX() + 0.5), (int) (t.getY() + 1.5)); case LR: t = rLR.inverseTransform(isoTransform.inverseTransform(in)); return new MapPoint((int) (t.getX() + 1.5), (int) t.getY()); case UR: t = rUR.inverseTransform(isoTransform.inverseTransform(in)); return new MapPoint((int) (t.getX() - 1.5), (int) (t.getY() + 0.5)); default: throw new RuntimeException( "Invalid camera angle. This cannot happen"); } } catch (NonInvertibleTransformException e) { throw new RuntimeException("This cannot happen", e); } }
public void setViewportTransform(Location projectionCenter, Location mapCenter, Point2D viewportCenter, double zoomLevel, double heading) { viewportScale = getViewportScale(zoomLevel); Point2D center = locationToPoint(mapCenter); Affine transform = new Affine(); transform.prependTranslation(-center.getX(), -center.getY()); transform.prependScale(viewportScale, -viewportScale); transform.prependRotation(heading); transform.prependTranslation(viewportCenter.getX(), viewportCenter.getY()); viewportTransform.setToTransform(transform); try { transform.invert(); } catch (NonInvertibleTransformException ex) { throw new RuntimeException(ex); // this will never happen } inverseViewportTransform.setToTransform(transform); }
/** * The point on the target at which the current centre point of the viewport is. * * @return a point on the target using target's coordinate system */ public Point2D targetPointAtViewportCentre() { try { return affine.inverseTransform(viewportCentre()); } catch (NonInvertibleTransformException e) { // TODO what can be done? throw new RuntimeException(e); } }
/** * Computes the point on the target at the given viewport point. * * @param viewportPoint a point on the viewport * @return a point on the target that corresponds to the viewport point or empty if the point * is not within the the bound returned by {@link #getViewportBound()} */ public Optional<Point2D> targetPointAt(Point2D viewportPoint) { if (!getViewportBound().contains(viewportPoint)) return Optional.empty(); try { return Optional.of(affine.inverseTransform(viewportPoint)); } catch (NonInvertibleTransformException e) { // TODO does this ever happen with just translate and scale? return Optional.empty(); } }
/** * Get the tile at the mouse position. * @return null if there is no tile under the mouse. * */ public MapPoint tileAtMouse(final Point2D mouse, final Stage stage) { try { return stage.collisions.mouseTileCollision( totalScreenTransform.inverseTransform(mouse), angle); } catch (NonInvertibleTransformException e) { throw new RuntimeException("This cannot happen", e); } }
/** * Get the sprite at the mouse position. * @return null if there is no sprite under the mouse. * */ public MapPoint spriteAtMouse(final Point2D mouse, final Stage stage) { try { return stage.collisions.mouseSpriteCollision( totalScreenTransform.inverseTransform(mouse), angle); } catch (NonInvertibleTransformException e) { throw new RuntimeException("This cannot happen", e); } }
/** * Transforms a given bounding box from camera coordinates to world coordinates. * @param b the given bounding box * @return the transformed bounding box */ public Bounds cameraToWorld(Bounds b) { Bounds world = null; try { world = worldToCamera().inverseTransform(b); } catch (NonInvertibleTransformException e) { e.printStackTrace(); } return world; }
/** * Compute the transformation to be applied for the zoom. * @param zoom the scale of the zoom. * @param center the center of the zoom, in camera space * @return the transformation for the zoom. */ protected Transform computeZoom(double zoom, Point2D center) { Point2D world; Transform newScale = scale; try { world = scale.inverseTransform(center.getX() - toCenter.getX() - translate.getX(), center.getY() - toCenter.getY() - translate.getY()); newScale = scale.createConcatenation(new Scale(zoom, zoom, world.getX(), world.getY())); } catch (NonInvertibleTransformException e) { e.printStackTrace(); } return newScale; }
public Point3D unTransform(Point3D p){ try { javafx.geometry.Point3D ta = a.inverseTransform(p.x,p.y,p.z); return new Point3D((float)ta.getX(), (float)ta.getY(), (float)ta.getZ()); } catch (NonInvertibleTransformException ex) { System.out.println("p not invertible "+p); } return p; }
@Override public void start(Stage stage) throws NonInvertibleTransformException { createSubscene(); createCameraView(); createOverlay(); Scene scene = new Scene(rootPane, 1024, 668); stage.setTitle("Billbording Test!"); stage.setScene(scene); stage.setMaximized(true); stage.show(); }
/** * Sets the global position. * * @param position * the 2D position */ public void setPosition(Position position) { try { Point2D p = getParentFxNode().getLocalToSceneTransform().inverseTransform(position.getX(), position.getY()); setTranslateMatrix(Transform.translate(p.getX(), p.getY())); } catch (NonInvertibleTransformException e) { throw new TrydentInternalException("Local -> Scene not invertable! " + e); } }