这是正确的视角 FOV 矩阵吗?
我有一个透视视野,但旋转时,它“看起来”不正确 - 较远的物体比较近的物体移动得更快,将它们从屏幕中间经过。
那么:这是正确的吗?使用右手坐标,如果这很重要的话?
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
);
}
谢谢。
I have a perspective FOV, but when rotating, it doesn't "look" correct - Farther objects traverse faster than closer objects, passing them in the middle of the screen.
So: Is this correct? Using right-handed coordinates, if that matters?
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
);
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到了几个问题。
首先, tan() 的参数应从度数转换为弧度。
其次,OpenGL中透视投影的公式与你的有点不同。正如此处所指定的,它在分母中使用“近-远”而不是您的“远-近'。分子项也不同。稍微修改一下你的函数并从 Java 转换为 C,我生成了一个与 gluPerspective() 给出的投影矩阵相同的投影矩阵,其中包含以下内容:
I see a couple of problems.
First, the argument to tan() should be converted from degrees to radians.
Second, the formula for perspective projection in OpenGL is a little different from yours. As specified here, it uses 'near - far' in the denominator instead of your 'far - near'. The numerator terms are also different. Modifying your function slightly and converting from Java to C, I produced a projection matrix identical to the one given by gluPerspective() with the following:
对于诸如此类的问题,我会推荐一个很好的资源:
https://www.scratchapixel.com/课程/3d-基础渲染/透视和正交投影矩阵
它确实涉及投影矩阵的细节。它们是更多关于相机、构建相机光线等主题的课程。您需要进行一些挖掘。
For questions such as this one I would suggest an excellent resources:
https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix
It really goes in the detail of the projection matrix. They are more lessons on the topic of camera, constructing camera rays, etc. You will need to do some digging.