Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Texture Mapping Coordinates of random triangles

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

Can anyone please tell me how to map texture coordinates of random triangles. It won''t matter the position of the texture, as long as it covers all the triangle. Like for example, texturing a land of grass, where the position of the grass texture wont matter. Thanks

Share this post

Link to post
Share on other sites
The easiest way of mapping a texture is just planar mapping. With this, you just use 2 of the 3 coordinates of the vertex position as the texture coordinates. You probably want to scale them a bit, by multiplying them by some scaling value.

Another easy way is cubic mapping. This is very similar to planar mapping, except that you first decide on which plane of the cube you want to map.
What you do is, you first calculate the normal for each triangle
normal = CrossProduct(vertex[1] - vertex[0],vertex[2] - vertex[0]);
normal.x = fabsf(normal.x);
normal.y = fabsf(normal.y);
normal.z = fabsf(normal.z);
then, if the x coordinate of the normal is the largest, you use the z and y coordinate for for u and v, if y is the largest, you use x,z and if z is the largest, you use x and y.

There are other ways too, like spherical mapping, or cylindrical mapping, but I don''t think you need that.

My Site

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!