Sign in to follow this  
mre

Eye Direction to UV Coordinate

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this