当前位置 : 主页 > 编程语言 > java >

屏幕坐标转换成openGL

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.java /** * Convert x to openGL * * @param x * Screen x offset top left * @return Screen x offset top left in OpenGL */ public static float toGLX(float x) { return -1.0f * ratio + toGLWidth(x); } /** * Convert y to openGL y * * @pa
gistfile1.java
/**
   * Convert x to openGL
   * 
   * @param x
   *            Screen x offset top left
   * @return Screen x offset top left in OpenGL
   */
  public static float toGLX(float x) {
      return -1.0f * ratio + toGLWidth(x);
  }
 
  /**
   * Convert y to openGL y
   * 
   * @param y
   *            Screen y offset top left
   * @return Screen y offset top left in OpenGL
   */
  public static float toGLY(float y) {
      return 1.0f - toGLHeight(y);
  }
 
  /**
   * Convert width to openGL width
   * 
   * @param width
   * @return Width in openGL
   */
  public static float toGLWidth(float width) {
      return 2.0f * (width / screenWidth) * ratio;
  }
 
  /**
   * Convert height to openGL height
   * 
   * @param height
   * @return Height in openGL
   */
  public static float toGLHeight(float height) {
      return 2.0f * (height / screenHeight);
  }
 
  /**
   * Convert x to screen x
   * 
   * @param glX
   *            openGL x
   * @return screen x
   */
  public static float toScreenX(float glX) {
      return toScreenWidth(glX - (-1 * ratio));
  }
 
  /**
   * Convert y to screent y
   * 
   * @param glY
   *            openGL y
   * @return screen y
   */
  public static float toScreenY(float glY) {
      return toScreenHeight(1.0f - glY);
  }
 
  /**
   * Convert glWidth to screen width
   * 
   * @param glWidth
   * @return Width in screen
   */
  public static float toScreenWidth(float glWidth) {
      return (glWidth * screenWidth) / (2.0f * ratio);
  }
 
  /**
   * Convert height to screen height
   * 
   * @param glHeight
   * @return Height in screen
   */
  public static float toScreenHeight(float glHeight) {
      return (glHeight * screenHeight) / 2.0f;
  }
上一篇:域名过滤器
下一篇:java中使用redis锁
网友评论