Ejemplo n.º 1
0
  /**
   * Centers the camera on the minimap coordinates given.
   *
   * @param x minimap x coordinate to center on
   * @param y minimap y coordinate to center on
   */
  private void centerOn(int x, int y) {
    if (imageData != null && waitingCallable.running.compareAndSet(false, true)) {
      int deltaX = (canvas.getSize().x - imageData.width) / 2;
      int deltaY = (canvas.getSize().y - imageData.height) / 2;

      Vector3f coords0 =
          mapCamera.getWorldCoordinates(new Vector2f(x - deltaX, 200 - y + deltaY), 0);
      Vector3f coords1 =
          mapCamera.getWorldCoordinates(new Vector2f(x - deltaX, 200 - y + deltaY), 1);

      Vector3f direction = coords0.subtract(coords1).normalizeLocal();

      Vector3f ground1 = coords0.subtract(direction.mult(coords0.y / direction.y));

      coords0 =
          implementor
              .getCamera()
              .getWorldCoordinates(
                  new Vector2f(
                      implementor.getCanvas().getSize().x / 2,
                      implementor.getCanvas().getSize().y / 2),
                  0);
      coords1 =
          implementor
              .getCamera()
              .getWorldCoordinates(
                  new Vector2f(
                      implementor.getCanvas().getSize().y / 2,
                      implementor.getCanvas().getSize().y / 2),
                  1);
      direction = coords0.subtract(coords1).normalizeLocal();

      Vector3f ground2 = coords0.subtract(direction.mult(coords0.y / direction.y));

      // scale the direction out to the ground plane
      waitingCallable.pos = ground1.subtract(ground2);
      implementor.render(waitingCallable);
    }
  }
Ejemplo n.º 2
0
  protected void drawImage() {
    if (imageData != null) {
      int deltaX = (canvas.getSize().x - imageData.width) / 2;
      int deltaY = (canvas.getSize().y - imageData.height) / 2;
      image.dispose();
      image = new Image(Display.getCurrent(), imageData);
      bgImage.dispose();
      bgImage = new Image(Display.getCurrent(), canvas.getSize().x, canvas.getSize().y);
      GC gc = new GC(bgImage);
      gc.drawImage(image, deltaX, deltaY);
      gc.setLineWidth(3);
      gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));

      Vector3f coords0 =
          implementor
              .getCamera()
              .getWorldCoordinates(
                  new Vector2f(
                      implementor.getCanvas().getSize().x / 2,
                      implementor.getCanvas().getSize().y / 2),
                  0);
      Vector3f coords1 =
          implementor
              .getCamera()
              .getWorldCoordinates(
                  new Vector2f(
                      implementor.getCanvas().getSize().x / 2,
                      implementor.getCanvas().getSize().y / 2),
                  1);
      Vector3f direction = coords0.subtract(coords1).normalizeLocal();
      coords0.subtractLocal(direction.mult(coords0.y / direction.y));
      Vector3f coords = mapCamera.getScreenCoordinates(coords0);
      gc.drawRectangle(deltaX + (int) coords.x - 25, 200 + deltaY - (int) coords.y - 25, 50, 50);

      canvas.setBackgroundImage(bgImage);
      gc.dispose();
    }
  }