Beispiel #1
0
  /**
   * Convert the given pixel coordinates, whose origin is at the top-left of a tile's containing
   * rectangle, to fine coordinates within that tile. Converted coordinates are placed in the given
   * point object.
   *
   * @param x the x-position pixel coordinate.
   * @param y the y-position pixel coordinate.
   * @param fpos the point object to place coordinates in.
   */
  public static void pixelToFine(MisoSceneMetrics metrics, int x, int y, Point fpos) {
    // calculate line parallel to the y-axis (from the given
    // x/y-pos to the x-axis)
    float bY = y - (metrics.fineSlopeY * x);

    // determine intersection of x- and y-axis lines
    int crossx = (int) ((bY - metrics.fineBX) / (metrics.fineSlopeX - metrics.fineSlopeY));
    int crossy = (int) ((metrics.fineSlopeY * crossx) + bY);

    // TODO: final position should check distance between our
    // position and the surrounding fine coords and return the
    // actual closest fine coord, rather than just dividing.

    // determine distance along the x-axis
    float xdist = MathUtil.distance(metrics.tilehwid, 0, crossx, crossy);
    fpos.x = (int) (xdist / metrics.finelen);

    // determine distance along the y-axis
    float ydist = MathUtil.distance(x, y, crossx, crossy);
    fpos.y = (int) (ydist / metrics.finelen);

    //         Log.info("Pixel to fine " + StringUtil.coordsToString(x, y) +
    //                  " -> " + StringUtil.toString(fpos) + ".");
  }