PDA

View Full Version : UVW mapping. Don't know how to do it.



teemu turkki
11-27-2004, 01:35 PM
Hi all.
I have a problem with uvw mapping.
I have written my own .3ds file reader and I am using it in order to draw a cube:


for(unsigned int j = 0; j < myMesh.GetNumOfFaces(); j++)
{
myMesh.mFaceList[j].ComputeVertexNormals(&amp;myMesh);

// normal coordinates of the first vertex
glNormal3f( myMesh.mFaceList[j].vertexNormals[0].x,
myMesh.mFaceList[j].vertexNormals[0].y,
myMesh.mFaceList[j].vertexNormals[0].z);
// texture coordinates of the first vertex
glTexCoord2f( myMesh.GetTextCoord(j, 0).GetX(),
myMesh.GetTextCoord(j, 0).GetY() );
// coordinates of the first vertex
glVertex3f( myMesh.GetVertex(j, 0).GetX(),
myMesh.GetVertex(j, 0).GetY(),
myMesh.GetVertex(j, 0).GetZ() );

//----------------- SECOND VERTEX -----------------
// normal coordinates of the second vertex
glNormal3f( myMesh.mFaceList[j].vertexNormals[1].x,
myMesh.mFaceList[j].vertexNormals[1].y,
myMesh.mFaceList[j].vertexNormals[1].z);
// texture coordinates of the second vertex
glTexCoord2f( myMesh.GetTextCoord(j, 1).GetX(),
myMesh.GetTextCoord(j, 1).GetY() );
// coordinates of the second vertex
glVertex3f( myMesh.GetVertex(j, 1).GetX(),
myMesh.GetVertex(j, 1).GetY(),
myMesh.GetVertex(j, 1).GetZ() );

//----------------- THIRD VERTEX -----------------
// normal coordinates of the third vertex
glNormal3f( myMesh.mFaceList[j].vertexNormals[2].x,
myMesh.mFaceList[j].vertexNormals[2].y,
myMesh.mFaceList[j].vertexNormals[2].z);
// texture coordinates of the third vertex
glTexCoord2f( myMesh.GetTextCoord(j, 2).GetX(),
myMesh.GetTextCoord(j, 2).GetY() );
// coordinates of the third vertex
glVertex3f( myMesh.GetVertex(j, 2).GetX(),
myMesh.GetVertex(j, 2).GetY(),
myMesh.GetVertex(j, 2).GetZ() );
}
In addition to this drawing code, I have the u,v coordinates from my .3ds cube. How should I change the preceding code to include the u,v offsets for texture mapping?

supagu
11-27-2004, 02:33 PM
what you have looks correct assuming
myMesh.GetTextCoord returns correct data, and assuming x represents u and y represent v.