将 3D 点投影到视口上,处理负深度
我做了很多搜索,但没有找到解决这个问题的方法。
我有一个视口,其中中心(我们观察的位置)始终位于 (0,0,0)。我们总是朝着(0,0,1)的方向看。在完成所有数学计算后,它简化为:
Projected X = 3D X Coordinate / 3D Z Coordinate
Projected Y = 3D Y Coordinate / 3D Z Coordinate
并且它工作得很好。每个点都正确投影到 z=1 处的平面上。但底片深度存在问题。我不能渲染具有负深度点的多边形,但是如果三角形具有到达视锥体的其他顶点怎么办?我希望能够仍然渲染三角形,因为您仍然可以看到它的一部分。
我怎样才能:
A:在观察平面上找到一个可以代表该顶点的点,然后使用该点绘制三角形?
或者
B:找到 2 个点并绘制 2 个三角形,在 z=0 和三角形进入视锥体之间的某个位置将三角形切成两半?
编辑:好吧,抱歉,我想我刚刚知道该怎么做。我刚刚设置了一个近剪切窗格,这样我就可以看到直线或三角形与其相交的位置。它适用于直线,我即将开始处理三角形。
I did a lot of searching but didn't find any solutions to this problem.
I have a viewport where the center (where we are looking from) is always at (0,0,0). We are always looking in the direction of (0,0,1). After doing all my math, it simplified to:
Projected X = 3D X Coordinate / 3D Z Coordinate
Projected Y = 3D Y Coordinate / 3D Z Coordinate
And it works perfectly. Every point is correctly projected onto the plane at z=1. But there is an issue with negatives depths. I could just not render polygons with negative depth points, but what if the triangle has other vertices that reach into the viewing frustum? I want to be able to render the triangle still, because you can still see part of it.
How might I either:
A: Find a point on the viewing plane that can represent that vertex, and then draw the triangle using that point?
or
B: Find 2 points and draw 2 triangles, to cut the triangle in half somewhere in between z=0 and where the triangle enters the viewing frustum?
EDIT: Okay, sorry, I think I just figured out what to do. I just set up a near-clipping pane, so I can just see where the line or triangle intersects it. It works properly for lines, and I'm about to start working on triangles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论