Ejemplo n.º 1
0
  /**
   * @deprecated match the input rectangle to support range query the return is
   * @param x
   * @param y
   * @param radius
   * @return an array of two boxes object, and the first box represents the left top point and the
   *     second box represents the right bottom point
   */
  public Hashtable<String, XBox[]> dmatch(double x, double y, double radius) {
    System.out.println("in matching./..." + x + ";" + y);
    Rectangle2D.Double matchRect =
        new Rectangle2D.Double(x - radius, y - radius, 2 * radius, 2 * radius);
    List<XQuadTree> tiles = this.quadtree.tileMatch(x, y, radius);
    Hashtable<String, XBox[]> result = null;
    try {
      if (tiles != null && tiles.size() > 0) {
        result = new Hashtable<String, XBox[]>();
        for (int i = 0; i < tiles.size(); i++) {
          XQuadTree oneTile = tiles.get(i);
          String tileIndex = oneTile.getIndex();
          // get the tile rect where the point is located
          Rectangle2D.Double tile_rect = oneTile.getM_rect();
          Point2D.Double offsetPoint = new Point2D.Double(tile_rect.getX(), tile_rect.getY());
          X2DGrid grid = new X2DGrid(tile_rect, this.cell_size, offsetPoint);
          XBox[] range = grid.intersect(matchRect);
          result.put(tileIndex, range);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return result;
  }
Ejemplo n.º 2
0
  public static void loadingText(String string) {
    if (loadingScreen != null) {
      loadingGraphics.setPaint(Color.WHITE);
      loadingGraphics.drawString(
          string, (int) loadingTextArea.getX(), (int) loadingTextArea.getY() + 20);

      loadingScreen.update();
    }
  }
Ejemplo n.º 3
0
  /**
   * Renders the shape that is currently being sized by the user as they drag the mouse across the
   * canvas. We render this separately because we have not yet put it in the shapes list for the
   * pose.
   *
   * @param g2 The graphics context for this canvas.
   * @param poseArea The area in the middle of the canvas where the pose will be rendered.
   */
  private void renderShapeInProgress(Graphics2D g2, Rectangle2D.Double poseArea) {
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager();
    PoseurShape shapeInProgress = poseurStateManager.getShapeInProgress();

    // ONLY DO THIS ON THE RIGHT SIDE
    if (state.isZoomable() && (shapeInProgress != null)) {
      float zoomLevel = state.getZoomLevel();
      shapeInProgress.render(g2, (int) poseArea.getX(), (int) poseArea.getY(), zoomLevel, true);
    }
  }
Ejemplo n.º 4
0
 public void getTiles(XQuadTree treeNode) {
   if (!treeNode.isHasChild()) { // this is the leaf node     	
     Rectangle2D.Double tile_rect = treeNode.getM_rect();
     Point2D.Double offsetPoint = new Point2D.Double(tile_rect.getX(), tile_rect.getY());
     X2DGrid grid = new X2DGrid(tile_rect, this.cell_size, offsetPoint);
     this.m_tiles.put(treeNode.getIndex(), grid);
   } else {
     this.getTiles(treeNode.getM_tl_child());
     this.getTiles(treeNode.getM_tr_child());
     this.getTiles(treeNode.getM_bl_child());
     this.getTiles(treeNode.getM_br_child());
   }
 }
Ejemplo n.º 5
0
 /**
  * @deprecated get index for the data point, the column index should be appended the location id
  *     later row index: (QT tile index - row index, column index)
  * @param x latitude of the location point
  * @param y longitude of the location point
  * @return
  */
 public String[] dlocate(double x, double y) {
   // filter the tile with quad tree first
   XQuadTree tile = this.quadtree.locate(x, y);
   // get index in the first level
   String tile_index = tile.getIndex();
   // get the tile rect where the point is located
   Rectangle2D.Double tile_rect = tile.getM_rect();
   Point2D.Double offsetPoint = new Point2D.Double(tile_rect.getX(), tile_rect.getY());
   X2DGrid grid = new X2DGrid(tile_rect, this.cell_size, offsetPoint);
   XBox box = grid.locate(x, y);
   String[] indexes = new String[2];
   indexes[0] = tile_index + "-" + box.getRow();
   indexes[1] = box.getColumn();
   // System.out.println("row=> "+indexes[0]+";column=>"+indexes[1]);
   return indexes;
 }
Ejemplo n.º 6
0
  public boolean bounce(Rectangle2D.Double rect, boolean isPaddle) {
    int _oldAngle = _angle;
    double x = _circle.getCenterX();
    double y = _circle.getCenterY();
    if (isPaddle) {
      if (_circle.intersects(rect)) {
        _gravity = -4;
        if ((_circle.getY() + 10) >= rect.getY()
            && _circle.getX() + 5 >= rect.getX()
            && _circle.getX() + 5 <= rect.getX() + rect.getWidth()
            && _circle.intersects(rect)) {
          _angle = 135 - (int) (90.0 * ((x - rect.getX()) / rect.getWidth()));
        } else if (rect.getX() - x <= 5) {
          _angle = 150;
        } else if (rect.getX() + rect.getWidth() - _circle.getX() <= 5) {
          _angle = 30;
        }
      }

    } else {
      if (_circle.intersects(rect)) {
        if (x >= rect.getX() + .1 && x <= rect.getX() + rect.getWidth() + .1) _angle = 0 - _angle;
        else if (y >= rect.getY() + .1 && y <= rect.getY() + rect.getWidth() + .1)
          if (_angle > 180) _angle = 540 - _angle;
          else _angle = 180 - _angle;
      }
    }

    if (_circle.getX() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100) < 0 && !_intersects) {
      if (_angle > 180) _angle = 540 - _angle;
      else _angle = 180 - _angle;
      return false;
    }
    if (_circle.getY() - (_speed * (Math.sin(Math.toRadians(_angle))) / 100) < 0 && !_intersects) {
      _angle = 0 - _angle;
      _gravity = 0;
      return false;
    }
    if (_circle.getX() + _circle.getWidth() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100)
            > 800
        && !_intersects) {
      if (_angle > 180) _angle = 180 + 180 - (_angle - 180);
      else _angle = 180 - _angle;
      return false;
    }
    if (_circle.getX() + _circle.getWidth() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100)
            > 800
        || _circle.getY() < 0
        || _circle.getX() < 0) _intersects = true;
    else _intersects = false;

    return _angle != _oldAngle;
  }
Ejemplo n.º 7
0
  /**
   * Renders all the shapes in the corresponding canvas state object for this canvas.
   *
   * @param g2 The graphics context of this panel.
   */
  private void renderShapes(Graphics2D g2, Rectangle2D.Double poseArea) {
    // LET'S GET THE POSE AREA AND THE POSE
    PoseurPose pose = state.getPose();
    float zoomLevel = state.getZoomLevel();

    // RENDER THE ENTIRE POSE
    Iterator<PoseurShape> shapesIt = pose.getShapesIterator();
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager();
    while (shapesIt.hasNext()) {
      PoseurShape shape = shapesIt.next();
      boolean isSelected = poseurStateManager.isSelectedShape(shape);

      // NOTE THAT WE NEVER DEPICT SELECTED SHAPES DIFFERENTLY
      // IN THE TRUE CANVAS, ONLY THE ZOOMABLE CANVAS
      if (!state.isZoomable()) {
        isSelected = false;
      }
      shape.render(g2, (int) poseArea.getX(), (int) poseArea.getY(), zoomLevel, isSelected);
    }
  }