Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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

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:

Good luck!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!