# Eye Direction to UV Coordinate

This topic is 3690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631438
• Total Posts
3000073
×