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 = foc开发者_如何转开发al 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?
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.
精彩评论