I am playing around with 3d transformations and came along an issue.
I have a 3d vector already within the viewport and need to transform it to a 2d vector. (let's say my screen is 10x10)
Does that just straight works like regualar transformation or is something different here?
i.e.: I have the vector a = (2, 1, 0) within the viewport and want the 2d vector.
Does that works like this and if yes how do I handle the "0" within the 3rd component?
Answer
If you have a point in 3D space you can multiply it by the view and then projection matrix to get the screen coordinate. This is a preferable method since it allows for different screens and view parameters. The example in the link x = x / z won't usually work since it relies on a very specific view frustum. It might be a good approximation for some system.
The issue with just multiplying with the view and then projection matrix is that you can loose magnitude in your vector which might not be what you want. This is because the camera isn't necessarily centered on the world origin.
So a point in 3D space of (10, 10, 0) might come out in screen space as (5, 5) instead of the expected (10, 10) because of the camera position. Since it's just a point we want then it's fine, but if you were working out how a vector for velocity will impact a 2D object, then this is obviously bad.
Finally, transforming from a 3D to a 2D coordinate system isn't the same as translating from world space to screen space which seems to be what you are asking. Going from world to screen requires knowledge of the view eye (camera) and the screen. Going from 3D to 2D is a different transformation which involves calculating an objects projection onto a plane. (I think an orthographic projection matrix might give an easy way to do this though, as I can't remember how you actually do it).
No comments:
Post a Comment