Projecting 3D Point onto Viewport, Dealing With Negative Depth

依然范特西╮ 提交于 2019-12-10 11:34:14

问题


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.

来源:https://stackoverflow.com/questions/7706796/projecting-3d-point-onto-viewport-dealing-with-negative-depth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!