[gameprogrammer] Re: issues with Calculating texture coordinates

There is no algorithm to calculate the texture coordinate for an arbitrary
mesh. It really depends on the shape, and how you want the texture to
project onto it. Say if you have a cylinder and you want a cylindrical
projection (so the texture "wraps around" the side of the cylinder) you
would give U values from 0 to 1 as you go around the cylinder (so for vertex
i with n vertices around the pipe you would give a U value of i/n) and
similarly the V value would go from 0 to 1 from the top to the bottom of the
cylinder.

Obviously the cylindrical projection is easiest on a cylinder. What kind of
projection do you want to do? Planar (as if a video projector is projecting
the texture from some direction), spherical (so it is projected from all
directions), cubical?

For game models none of these projections are used, generally the model will
be made, and then a texture map generated which can be painted on, but the
3D model will do all the UV calculations for each vertex.

It would be helpful to hear what kind of model it is and what kind of
texture mapping you are hoping to achieve.

Nick


On 02/06/06, Gautam Narain <gautam_n_@xxxxxxxxxxx> wrote:

Hi,

In the most simple case this will be alright. But I am looking at how
those
values are calculated. Yes for a simple triangle its as simple as this -
just put 0,0, and 1, 1 and 0,1 etc appropriately. But lets say I had a 3d
model with 100 vertices and I wanted to calcluate the texture coordinates
then how would I do it ?

Hence I was looking at http://www.gameprogrammer.com/6-text.html and
PCGPE.

Thanks
Gautam

>[gameprogrammer] Re: issues with Calculating texture coordinates
>
>   * From: "Olof Bjarnason" <olof.bjarnason@xxxxxxxxx>
>    * To: gameprogrammer@xxxxxxxxxxxxx
>    * Date: Thu, 1 Jun 2006 15:14:03 +0200

>if you just want to stretch the texture over the triangle in the
>simplest, most basic way, just type something like


>glTexCoord2f(0,0); // (0,0) is the top-left corner of texture >glVertex3f(0,0,-10);


>glTexCoord2f(1,0); // (1,0) is the top-right corner of texture >glVertex3f(0,1,-10);


>glTexCoord3f(1,1); // (1,1) is the bottom-right corner of texture >glVertex3f(1,1,-10);


>good luck


/Olof




--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html



Other related posts: