Eye Direction to UV Coordinate
Hello,
I'm sure this is a simple solution but I'm not sure how to do it. I want to use my camera's direction vector to sample a texture file. The texture is not a cube map, just a simple square texture. I know the result won't be great, but it fits in with what I'm trying to do. :) I want the UV coordinate to be in 0-1 range, and the direction is of course a normalized vector. The end result should be similar to if I had mapped the texture to a sphere that was centred on the camera.
Thanks!
Hey mre,
Here's one way you could it:
Map the camera direction to spherical coordinates - so take the x,y,z of the camera direction and map to a radius, omega, and phi.
The radius should always be one, because the direction is normalized.
Omega will then be in the range of 0 - 2PI (which is like your yaw/horizontal angle), and then Phi will be in the range of 0-PI (which is like your pitch/vertical angle).
Once you get omega and phi, just remap these to ranges of 0 - 1
So:
U = Omega / 2PI
V = Phi / PI
That would be one way of doing the mapping. The formulas for converting from cartesian (x,y,z) to spherical coordinates can be found on the wikipedia page:
http://en.wikipedia.org/wiki/Spherical_coordinates
Good luck!
Here's one way you could it:
Map the camera direction to spherical coordinates - so take the x,y,z of the camera direction and map to a radius, omega, and phi.
The radius should always be one, because the direction is normalized.
Omega will then be in the range of 0 - 2PI (which is like your yaw/horizontal angle), and then Phi will be in the range of 0-PI (which is like your pitch/vertical angle).
Once you get omega and phi, just remap these to ranges of 0 - 1
So:
U = Omega / 2PI
V = Phi / PI
That would be one way of doing the mapping. The formulas for converting from cartesian (x,y,z) to spherical coordinates can be found on the wikipedia page:
http://en.wikipedia.org/wiki/Spherical_coordinates
Good luck!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement