【发布时间】:2017-09-23 14:21:41
【问题描述】:
我一直在使用添加了 JOML 的 LWJGL 作为创建 3D 游戏引擎的一种方式。 自从我松散地遵循 Jeffrey (YouTube) 的教程以来,我遇到了一个问题,但我一直在使用 JOML 库而不是他创建的迷你数学库。我制作了一个 Transform 类,它是从 Jeffrey 的数学库中复制而来的,我一直在翻译它以使用 JOML:
import org.joml.Matrix4f;
import org.joml.Vector3f;
public class Transform {
public static Matrix4f getPerspectiveProjection(float fov, int width, int height, float zNear, float zFar) {
return new Matrix4f().setPerspective(fov, width / height, zNear, zFar);
}
public static Matrix4f getTransformation(Vector3f translation, float rx, float ry, float rz, float scale) {
Matrix4f translationMatrix = new Matrix4f().setTranslation(translation);
// The first problem:
Matrix4f rotationMatrix = new Matrix4f().getRotation(rx, ry, rz);
Matrix4f scaleMatrix = new Matrix4f().initScale(scale);
return translationMatrix.mul(rotationMatrix.mul(scaleMatrix));
}
public static Matrix4f getViewMatrix(Camera camera) {
Vector3f pos = camera.getPosition();
Matrix4f translationMatrix = new Matrix4f().setTranslation(-pos.x, -pos.y, -pos.z);
Matrix4f rotationMatrix = new Matrix4f().initRotation(camera.getForward(), camera.getUp());
return rotationMatrix.mul(translationMatrix);
}
}
从 JOML 文档中,我只能找到将 Matrix4f.getRotation 与 AxisAngle4f 一起使用。
问题的关键是,如何将rx、ry和rz角度转换成AxisAngle4f?
【问题讨论】: