/** * Get the screen pixel for map coordinates * * @param out Point projected to screen coordinate */ public void toScreenPoint(double x, double y, Point out) { double cs = mPos.scale * Tile.SIZE; double cx = mPos.x * cs; double cy = mPos.y * cs; mv[0] = (float) (x * cs - cx); mv[1] = (float) (y * cs - cy); mv[2] = 0; mv[3] = 1; mViewProjMatrix.prj(mv); out.x = (mv[0] * (mWidth / 2)); out.y = -(mv[1] * (mHeight / 2)); }
/** * Get the map position for x,y in screen coordinates. * * @param x screen coordinate * @param y screen coordinate */ public void fromScreenPoint(double x, double y, Point out) { unprojectScreen(x, y, mu); double cs = mPos.scale * Tile.SIZE; double cx = mPos.x * cs; double cy = mPos.y * cs; double dx = cx + mu[0]; double dy = cy + mu[1]; dx /= cs; dy /= cs; while (dx > 1) dx -= 1; while (dx < 0) dx += 1; if (dy > 1) dy = 1; else if (dy < 0) dy = 0; out.x = dx; out.y = dy; }