我正在使用右手坐标进行3D图形“蓝屏无纹理立方体”测试。然而,它们出现奇怪的剪裁或扭曲(在Orthographic中,显示屏的左侧在窗口之前结束;在透视图中,它看起来像是从左后方延伸到右前方。)
不确定问题究竟是什么,但投影矩阵似乎是一个很好的起点。
我现在正在使用的那些:
// Went back to where I found it and found out this is a
// left-handed projection. Oops!
public static Matrix4x4 Orthographic(float width, float height,
float near, float far)
{
float farmnear = far - near;
return new Matrix4x4(
2 / width, 0, 0, 0,
0, 2 / height, 0, 0,
0, 0, 1 / farmnear, -near / farmnear,
0, 0, 0, 1
);
}
// Copied from a previous project.
public static Matrix4x4 PerspectiveFov(float fov, float aspect,
float near, float far)
{
float yScale = 1.0F / (float)Math.Tan(fov / 2);
float xScale = yScale / aspect;
float farmnear = far - near;
return new Matrix4x4(
xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, far / (farmnear), 1,
0, 0, -near * far / (farmnear), 1
);
}
由于
答案 0 :(得分:0)
解决了 - 感谢您的帮助。它不是投影矩阵;它是LookAt / View矩阵中的一个错误放置的变量。现在所有东西都已正确显示。
public static Matrix4x4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
{
Vector3 zAxis = target; zAxis.Subtract(ref eye); zAxis.Normalize();
Vector3 xAxis = up; xAxis.Cross(zAxis); xAxis.Normalize();
Vector3 yAxis = zAxis; yAxis.Cross(xAxis);
return new Matrix4x4(
xAxis.X, yAxis.X, zAxis.Z, 0, // There.
xAxis.Y, yAxis.Y, zAxis.Y, 0,
xAxis.Z, yAxis.Z, zAxis.Z, 0,
-xAxis.Dot(eye), -yAxis.Dot(eye), -zAxis.Dot(eye), 1
);
}
糟糕。 :)