透视投影公式问题
我正在开发 3d flash 游戏,我的问题很简单。
如何将3d点转换为2d点?
我在互联网上找到了下一个公式(相机位于原点)
- x' = x/z y' = y/z
- 比率 = 焦距/(焦距 + z)
x = x*比率
y = y*ratio
但是当 z 小于零(z<0)时,这些公式给了我奇怪的结果
我需要从 A(100,100,100) 到 B (100,100;-100) 的构建线 正如你所看到的,当我尝试将 B 点转换为 2D 维度时,这些方程给出了非常奇怪的结果,
我该如何解决这个问题?
I am developing 3d flash game and my question is very simple.
How to convert 3d point to 2d point?
I've found next formula in Internet(camera is situated in origin)
- x' = x/z y' = y/z
- ratio = focal length/(focallength + z)
x = x*ratio
y = y*ratio
But these formulae give me strange result when z are less than zero(z<0)
I need build line from A(100,100,100) to B (100,100;-100)
As you can see these equations give really strange result when I try to convert B point in 2D dimension
How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑一下当 z=0 时这意味着什么。这意味着您正在执行 x/0,这很糟糕 - 在这种情况下,这意味着该点占据与相机相同的位置!随着 z 变小,这意味着这些点将位于相机后面,因此您根本不应该渲染它们。
您必须剔除(而不是渲染)“屏幕后面”的任何点。选择一个小的 z 作为“近平面”,例如 z=1。您必须针对此 z=1 平面剪切任何几何体,以防止错误渲染。
对于点,您可以检查 point.z
point.z
point.z
point.z
point.z
point.z < 1.
.对于直线,情况更为复杂——您必须计算直线与 z=1 平面的交点,并在必要时对其进行裁剪。您可以在此处找到一些有关线条剪辑的信息。
Consider what it means when z=0. This means you are doing x/0, which is bad -- in this case, it means the point occupies the same position as your camera! And as z grows smaller, this means the points are going behind your camera, so you shouldn't render them at all.
You must cull (not render) any points that are 'behind the screen'. Choose a small z to be your 'near plane', say, z=1. You have to clip any geometry against this z=1 plane to prevent incorrect rendering.
In the case of points, you can check
point.z < 1
. For lines, it is more complex--you must compute the intersection of the line with the z=1 plane and clip it if necessary.You can find some info on line clipping here.