【问题标题】:Convert a Vector3f x and y to exact pixel size将 Vector3f x 和 y 转换为精确的像素大小
【发布时间】:2014-12-18 20:45:04
【问题描述】:

我目前正在玩一些 java 游戏引擎。 (由朋友使用 LWJGL 开发)。该引擎使用 Vector3f Positions 在屏幕上绘制图片。我想用精确的像素位置绘制图片......所以我创建了一个 Vector3f,并且现在必须以某种方式将 x 和 y 值转换为像素位置。但是怎么做呢?

【问题讨论】:

    标签: lwjgl game-engine pixel


    【解决方案1】:

    假设 Vector3f 的组件使用 OpenGL 屏幕坐标(原点位于屏幕中心,x 向右,y 向上,轴的值为 -1 到 1)。生成的像素坐标使用 LWJGL 坐标系,即原点在左下角。

    import org.lwjgl.opengl.Display;
    import org.lwjgl.util.Point;
    import org.lwjgl.util.vector.Vector3f;
    
    public static Point toPixelPos(Vector3f v) {
        int width = Display.getWidth();
        int height = Display.getHeight();
        int x = (int) (width * (v.x + 1) / 2);
        int y = (int) (height * (v.y + 1) / 2);
    
        return new Point(x, y);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      相关资源
      最近更新 更多