【问题标题】:Is LWJGL's Matrix4f.mul method pre or post multiply?LWJGL 的 Matrix4f.mul 方法是先乘还是后乘?
【发布时间】:2012-06-16 04:33:01
【问题描述】:

只是想知道 LWJGL 的 Matrix4f.mul 方法是先乘还是后乘。或者有什么方法可以选择。

【问题讨论】:

    标签: java matrix lwjgl matrix-multiplication


    【解决方案1】:

    根据 javadoc,Matrix4f.mul 将:

    将右矩阵乘以左矩阵,并将结果放在第三个矩阵中。

    public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest)
    

    因此,要实现后乘,请将现有矩阵用作left 参数,并将新矩阵用作right 参数。如果您为dest 提供一个空对象,该函数将为您分配一个新的Matrix4f,并从函数调用中返回它。

    我通常认为矩阵乘法的方式是首先应用与向量“最近”的矩阵。例如:

    Perspective  *  View  *  Model  *  Vec4
    

    从最接近向量的矩阵开始,您可以看到首先应用模型变换,然后是视图变换,最后是透视变换。

    在您的代码中,上面的代码如下所示:

    Matrix4f MVP = Matrix4f.mul(View, Model, null);
    Matrix4f.mul(Perspective, MVP, MVP);
    
    Vector4f result = Matrix4f.transform(MVP, Vec4, null);
    

    希望这会有所帮助!

    编辑:以上是我倾向于连接我的变换的方式,但由于矩阵乘法是关联的,以下也应该有效:

    Matrix4f MVP = Matrix4f.mul(Perspective, View, null);
    Matrix4f.mul(MVP, Model, MVP);
    
    Vector4f result = Matrix4f.transform(MVP, Vec4, null);
    

    【讨论】:

      猜你喜欢
      • 2017-03-29
      • 2018-05-27
      • 2023-04-04
      • 2023-03-25
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 2012-07-25
      相关资源
      最近更新 更多