protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) { View view = getWwd().getView(); EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe(); // Compute ref-point position in screen coordinates. Position refPos = dragObject.getReferencePosition(); if (refPos == null) return; Vec4 refPoint = globe.computePointFromPosition(refPos); Vec4 screenRefPoint = view.project(refPoint); // Compute screen-coord delta since last event. int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x; int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y; // Find intersection of screen coord ref-point with globe. double x = screenRefPoint.x + dx; double y = dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1; Line ray = view.computeRayFromScreenPoint(x, y); Intersection inters[] = globe.intersect(ray, refPos.getElevation()); if (inters != null) { // Intersection with globe. Move reference point to the intersection point. Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint()); dragObject.moveTo(p); } }
private MovableTestWindow() throws InterruptedException { MatchConstants.init(new NetworkTimer(true), 1000); MatchConstants.clock().startExecution(); MovableTestsMap grid = new MovableTestsMap(100, 100, PLAYER_0); MapInterfaceConnector connector = TestUtils.openTestWindow(grid); movable = new Movable( grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(49, 50), PLAYER_0); movable.setSelected(true); connector.setSelection(new SelectionSet(movable)); connector.addListener( new IMapInterfaceListener() { @Override public void action(Action action) { switch (action.getActionType()) { case MOVE_TO: movable.moveTo(((PointAction) action).getPosition()); break; case SPEED_FASTER: MatchConstants.clock().multiplyGameSpeed(1.2f); break; case SPEED_SLOWER: MatchConstants.clock().multiplyGameSpeed(1 / 1.2f); break; case FAST_FORWARD: MatchConstants.clock().fastForward(); break; default: break; } } }); grid.getMovableGrid().dropMaterial(new ShortPoint2D(40, 40), EMaterialType.PLANK, true); grid.getMovableGrid().dropMaterial(new ShortPoint2D(60, 60), EMaterialType.STONE, true); new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(30, 30), PLAYER_0); new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(31, 31), PLAYER_0); new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(32, 32), PLAYER_0); new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(33, 33), PLAYER_0); new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(50, 50), PLAYER_0); { // test automatic distribution of many movables next to each other for (int x = 30; x < 40; x++) { for (int y = 80; y < 90; y++) { new Movable(grid.getMovableGrid(), EMovableType.BEARER, new ShortPoint2D(x, y), PLAYER_0); } } } { Thread.sleep(3000); // circle of three movables blocking each others path Movable m1 = new Movable( grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(50, 65), PLAYER_0); Movable m2 = new Movable( grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(51, 65), PLAYER_0); Movable m3 = new Movable( grid.getMovableGrid(), EMovableType.PIONEER, new ShortPoint2D(50, 64), PLAYER_0); m1.moveTo(new ShortPoint2D(52, 65)); m2.moveTo(new ShortPoint2D(49, 63)); m3.moveTo(new ShortPoint2D(50, 66)); } }