什么是通过Matrix转换和通过Quaternion +添加之间的区别?

时间:2018-05-18 18:34:02

标签: java opengl lwjgl transformation

所以我一直试图在我的openGL渲染器中实现延迟着色管道,但由于某种原因,点光源的强度取决于相机的旋转。如果我朝北方向看,整个世界都会发出红光。如果我朝南方向(朝向点光源)看,只有光线周围的半径发红光。在尝试各种各样的事情时,我注意到一些奇怪为了将光的位置转换为视图空间,我将其转换为4维向量,将其与摄像机viewMatrix相乘,然后切掉w部分,就像下面的教程我所说的那样,但是因为这个没有工作我尝试了一些不同的方法,虽然它们应该是完全相同的转换,但不知何故都有不同的结果。

在这里,我编写了一个单独的程序来测试3种不同的方法:

    Vector4f transView = new Vector4f(POSITION);
    Matrix4f viewMatrix = new Matrix4f().identity()
            .rotationX((float) Math.toRadians(56))
            .rotateY((float) Math.toRadians(123))
            .rotateZ((float) Math.toRadians(0))
            .translate(-PLAYER_POS.x, -PLAYER_POS.y, -PLAYER_POS.z);

    transView.mul(viewMatrix);

    Quaternionf rotation = new Quaternionf().identity().rotation((float) Math.toRadians(56), (float) Math.toRadians(123), (float) Math.toRadians(0));
    Vector4f transViewQuat = new Vector4f(POSITION);

    viewMatrix = new Matrix4f().identity()
            .rotate(rotation)
            .translate(-PLAYER_POS.x, -PLAYER_POS.y, -PLAYER_POS.z);

    transViewQuat.mul(viewMatrix);

    Vector4f transQuat = new Vector4f(POSITION);

    transQuat.rotate(rotation).sub(PLAYER_POS.x, PLAYER_POS.y, PLAYER_POS.z, 0);

结果是:
-16,5228042603 -10,3134384155 8,1627197266 1(transView)
-12,0040283203 5,5546798706 16,4635715485 1(transViewQuat)

102,3978881836 -46,5307388306 22,3403549194 1(transQuat)

有人可以向我解释为什么3个输出是3个完全不同的结果以及为什么光的强度取决于相机的旋转? 在我的游戏中,我使用第一种方法来创建我的viewMatrix。

0 个答案:

没有答案
相关问题