コード例 #1
0
  private void initiateFocus(Viewport viewport, Map<ObjectId, GalaxySystem> systems) {
    GalaxySystem focuson = systems.get(focusid);
    OrbitStatus absoluteCenter = focuson.getGalaxyOrbitStatus();
    xoff = absoluteCenter.getCartesianX();
    yoff = absoluteCenter.getCartesianY();
    logger.debug(String.format("orbit status: %s", absoluteCenter));
    logger.debug(
        String.format(
            "orbit status: [x:%s, y:%s]",
            absoluteCenter.getCartesianX(), absoluteCenter.getCartesianY()));

    double xoffinit = absoluteCenter.getDistance() * Math.cos(absoluteCenter.getAlpha());
    double yoffinit = absoluteCenter.getDistance() * Math.sin(absoluteCenter.getAlpha());

    double largestdist = WindowFocusType.MULTI_SYSTEM.maxin * 1.1;

    double dy = viewport.getReal().getHeight();
    double dx = viewport.getReal().getWidth();

    Rectangle2D newview;
    if (dy < dx) {
      double ratio = (dx / dy);
      newview =
          new Rectangle2D.Double(
              xoffinit + largestdist * ratio * -1,
              yoffinit + largestdist * -1,
              largestdist * ratio * 2,
              largestdist * 2);
    } else {
      double ratio = (dy / dx);
      newview =
          new Rectangle2D.Double(
              xoffinit + largestdist * -1,
              yoffinit + largestdist * ratio * -1,
              largestdist * 2,
              largestdist * ratio * 2);
    }

    logger.info(String.format("setting new view to %s", newview));
    viewport.setView(newview);

    updateFocusingOn(viewport);
  }
コード例 #2
0
  private ObjectId findClosestCenter(Viewport viewport, Map<ObjectId, GalaxySystem> systems) {
    double cx = viewport.getView().getCenterX();
    double cy = viewport.getView().getCenterY();
    double targetdist = Math.sqrt(cx * cx + cy * cy);
    double targetalpha = Math.atan2(cy, cx);

    ObjectId result = null;
    double distance = Double.MAX_VALUE;
    for (GalaxySystem system : systems.values()) {
      OrbitStatus status = system.getGalaxyOrbitStatus();
      double check =
          SpaceFunctionUtil.distanceBetweenTwoObjects(
              targetalpha, targetdist, status.getAlpha(), status.getDistance());
      if (distance > check) {
        distance = check;
        result = system.getId();
      }
    }
    return result;
  }