#### Archived

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.

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

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

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

• Total Topics
632927
• Total Posts
3009250
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!