Jump to content
  • Advertisement
Sign in to follow this  
spek

UV coords to 3D world position

This topic is 4317 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

Hi, I'm doing stuff with lightMaps, and now I need to calculate a 3D world position. Given info is: - UV coordinates - The polygon where it belongs to - Polygon normal - 3 Polygon vertices (world positions) - The 3 UV coordates of those vertices So, I need a function something like this:
vector3f  UV_To_WorldPos( const float    u,v
                          const vector3f v1,v2,v3 // vertices
                          const vector2f t1,t2,t3 // vertex UV's
                          const vector3f normal );
{
   ...
}
Eventually I can also give the axis what was used for mapping the polygon (XY, XZ or YZ). But I'm not sure if that's correct... the UV coordinates are generated by another program, so I'm not sure if I use the right axis. I've read a few descriptions, but my math is not very good, and my technical english neither. Sorry! Greetings, Rick

Share this post


Link to post
Share on other sites
Advertisement
Well, I've gotten a bit rusty so there's most likely a much better way, but just to give a way...

Picture plotting the triangle in 2D using the UV coordinates then plotting the point on that triangle. You can then draw a line parallel to one axis through that point, say the U axis. That will intersect two sides. You don't know the V coordinate for those intersection points, but you know the U coordinate because it's the same as the point. You can use the U coordinate to find the percentage of the way along each edge and that percentage can be used to find the V coordinate. That percentage can also be used to find the 3D coordinates of those two points. The V coordinate of the point can then be used to find the percentage of the way between the two intersection points to the point of interest and that can be used to find the 3D coordintes of the point.

That's a bit of a brute force approach, but I'm a bit too rusty to provide a more elegant solution and suspect, even if I wasn't, the explaination of a more elegant solution wouldn't sound too elegant.

Share this post


Link to post
Share on other sites
Barycentric coordinates... that was exactly the thing I need! It works now, thanks!

Rick

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!