我正在使用LWJGL在Java游戏中工作,而我正试图让它旋转以查看3D空间中的某个点。我已经尝试了每一个" lookAt"我可以在互联网上找到的方法,但是我无法让它工作(相机看起来并不正确)。
你能帮我弄明白怎么做吗?
编辑:
想出来,只需要反转矩阵。如果你遇到同样的问题,这是最终的代码:
public static Matrix4f lookAt(Vector3f eye, Vector3f center, Vector3f up) {
Vector3f forward = new Vector3f(0, 0, 0);
Vector3f.sub(center, eye, forward);
forward.normalise();
Vector3f side = new Vector3f(0, 0, 0);
Vector3f.cross(forward, up, side);
side.normalise();
Vector3f.cross(side, forward, up);
Matrix4f matrix = new Matrix4f();
matrix.m00 = side.x;
matrix.m01 = side.y;
matrix.m02 = side.z;
matrix.m10 = up.x;
matrix.m11 = up.y;
matrix.m12 = up.z;
matrix.m20 = -forward.x;
matrix.m21 = -forward.y;
matrix.m22 = -forward.z;
matrix.invert();
return matrix;
}