JOGL setPerspective错了? [英] JOGL setPerspective wrong?

查看:361
本文介绍了JOGL setPerspective错了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定在我的项目中使用JOGL。但这里是设置视角的问题。简单代码:

I've decided to use JOGL for my project. But here is the problem with setting perspective. Simple code:

System.out.println("BEFORE:");
projectionMatrix.identity();
projectionMatrix.setPerspective(fovy, aspect, zNear, zFar);
System.out.println(projectionMatrix);

System.out.println("AFTER:");
projectionMatrix.identity();        
projectionMatrix.m00 =
    (float)(1.0 / (aspect*Math.tan(viewAngle)));
projectionMatrix.m11 =
    (float)(1.0 / Math.tan(viewAngle));
projectionMatrix.m22 =
    (float)((-zNear-zFar) / (zNear-zFar));
projectionMatrix.m33 = 0.0f;

projectionMatrix.m23 =
        (float)((2*zFar*zNear) / (zNear-zFar));
projectionMatrix.m32 = 1.0f;
System.out.println(projectionMatrix);

输出:

BEFORE:
2.414E+0  0.000E+0  0.000E+0  0.000E+0
0.000E+0  2.414E+0  0.000E+0  0.000E+0
0.000E+0  0.000E+0 -1.000E+0 -2.000E-2
0.000E+0  0.000E+0 -1.000E+0  0.000E+0

AFTER:
1.000E+0  0.000E+0  0.000E+0  0.000E+0
0.000E+0  1.000E+0  0.000E+0  0.000E+0
0.000E+0  0.000E+0  1.000E+0  1.000E+0
0.000E+0  0.000E+0 -2.000E-2  0.000E+0

正如你所看到的,矩阵是不同的。他们的(jogl)代码:

As you can see, matrices are different. Their (jogl) code:

public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar) {
    float h = (float) Math.tan(fovy * 0.5f) * zNear;
    float w = h * aspect;
    m00 = zNear / w;
    m01 = 0.0f;
    m02 = 0.0f;
    m03 = 0.0f;
    m10 = 0.0f;
    m11 = zNear / h;
    m12 = 0.0f;
    m13 = 0.0f;
    m20 = 0.0f;
    m21 = 0.0f;
    m22 = -(zFar + zNear) / (zFar - zNear);
    m23 = -1.0f;
    m30 = 0.0f;
    m31 = 0.0f;
    m32 = -2.0f * zFar * zNear / (zFar - zNear);
    m33 = 0.0f;
    return this;
}

与我的不同。程序工作正常我的版本的代码。如何使用它们的库?

Gives different from mine. Program works fine with my version of code. How do I use their library?

另一个问题:通过从javax.vecmath.Matrix4f切换到org.joml.Matrix4f简单的旋转变得坏了

Another problem: simple by switching from javax.vecmath.Matrix4f to org.joml.Matrix4f rotation becomes broken (rotate around wrong axis and around a point that is slightly off camera).

推荐答案

首先更新jogl,然后使用 FloatUtil.makePerspective(final float [] m,final int m_off,final boolean initM,final float fovy_rad ,最终浮动方面,最终浮动zNear,最终浮动zFar)

First, update jogl, second use FloatUtil.makePerspective(final float[] m, final int m_off, final boolean initM, final float fovy_rad, final float aspect, final float zNear, final float zFar)

float [] m 是你需要提交的矩阵。这提供了灵活性,这意味着如果你想使用池,你可以。否则只需传递 new float [16] 并捕获返回结果

float[] m is the matrix you need to submit. This offers you flexibility, that means if you want use pools, you can. Otherwise just pass new float[16] and catch the return result

这篇关于JOGL setPerspective错了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆