Esempio n. 1
0
  /**
   * Normalizes a point on screen in screen dims
   *
   * @param point in pixels
   * @param screenWidth in pixels
   * @param screenHeight in pixels
   * @return a 2d point in relative values
   */
  public static Point2D getNormalizedCoords(Point2D point, int screenWidth, int screenHeight) {
    Point2D norm = null;

    if (null != point) {
      norm = new Point2D(point);
      norm.x /= screenWidth;
      norm.y /= screenHeight;
    }

    return norm;
  }
Esempio n. 2
0
  /**
   * Converts a relative point to screen point in pixels.
   *
   * @param point in relative values
   * @param screenWidth in pixels
   * @param screenHeight in pixels
   * @return a 2d point in pixels
   */
  public static Point2D getRelativeToScreenSpace(Point2D point, int screenWidth, int screenHeight) {
    Point2D screenPoint = null;

    if (null != point) {
      screenPoint = new Point2D(point);
      screenPoint.x = Math.round(screenPoint.x * screenWidth);
      screenPoint.y = Math.round(screenPoint.y * screenHeight);
    }

    return screenPoint;
  }
Esempio n. 3
0
  /**
   * Maps eye position of gaze coords in pixels within normalized space [x: -1:1 , y: -1:1]
   *
   * @param point in pixels
   * @param screenWidth in pixels
   * @param screenHeight in pixels
   * @return a relative point mapped into normalized space [x: -1:1 , y: -1:1]
   */
  public static Point2D getNormalizedMapping(Point2D point, int screenWidth, int screenHeight) {
    Point2D normMap = getNormalizedCoords(point, screenWidth, screenHeight);

    if (null != normMap) {
      // scale up and shift
      normMap.x *= 2f;
      normMap.x -= 1f;
      normMap.y *= 2f;
      normMap.y -= 1f;
    }

    return normMap;
  }