java - LWJGL 的 Matrix4f.mul 方法是乘法前还是乘法后?

标签 java matrix lwjgl matrix-multiplication

只是想知道 LWJGL 的 Matrix4f.mul 方法是前乘法还是后乘法。或者有没有办法选择。

最佳答案

根据 javadoc,Matrix4f.mul 将:

Multiply the right matrix by the left and place the result in a third matrix.

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

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

我通常考虑矩阵乘法的方式是首先应用与 vector “最接近”的矩阵。例如:

Perspective  *  View  *  Model  *  Vec4

从距离 vector 最近的矩阵开始,您可以看到首先应用模型变换,然后是 View 变换,最后是透视变换。

在你的代码中,上面的代码看起来像:

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);

关于java - LWJGL 的 Matrix4f.mul 方法是乘法前还是乘法后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060849/

相关文章:

java - 适用于没有 API 的 Web 应用程序的 Android 应用程序

excel - 如何使用 Excel 将矩阵转换为单列

java - NiftyGUI的Nifty类无法实例化?

c++ - 快速访问二维矩阵中的单元格

matlab - 将 matlab 矩阵转换为向量

java - 在当前线程中找不到 OpenGL 上下文,如何修复此错误?

Java StateBased 游戏 - 在 eclipse 外部运行

带有监听器的 JavaFX 文本字段给出 : "java.lang.IllegalArgumentException: The start must be <= the end"

java - 六角网格(平顶)距离计算

Java - 在函数调用中包含数组声明?