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); }
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; }
private void viewShiftUpdate(Viewport viewport, Map<ObjectId, GalaxySystem> systems) { GalaxySystem focus = systems.get(focusid); OrbitStatus absoluteCenter = focus.getGalaxyOrbitStatus(); double xcheck = absoluteCenter.getCartesianX(); double ycheck = absoluteCenter.getCartesianY(); Rectangle2D view = viewport.getView(); double xchange = xoff - xcheck; double ychange = yoff - ycheck; if (xchange != 0 || ychange != 0) { logger.debug(String.format("orbit status: %s", absoluteCenter)); logger.debug(String.format("changing focus-> x:%s, y:%s", xchange, ychange)); logger.debug(String.format("before: %s", view)); view.setRect(view.getX() - xchange, view.getY() - ychange, view.getWidth(), view.getHeight()); logger.debug(String.format("after : %s", view)); } xoff = xcheck; yoff = ycheck; ObjectId newidcheck = findClosestCenter(viewport, systems); if (!newidcheck.equals(focusid)) { // if they are not equal, then we need to change // the focus id to the new one. but first we need // to reset the x and y offset to make sure the // view stays smooth. GalaxySystem newfocus = systems.get(newidcheck); OrbitStatus newcenter = newfocus.getGalaxyOrbitStatus(); xoff = newcenter.getCartesianX(); yoff = newcenter.getCartesianY(); focusid = newidcheck; if (logger.isInfoEnabled()) { logger.info(String.format("new focus id set to %s", focusid)); } } }