开发者

Projecting 3D Point onto Viewport, Dealing With Negative Depth

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 tr开发者_运维技巧iangles, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜