Sign in to follow this  
LabRat404

.MAP UV texture calculations

Recommended Posts

I've searched around for an aswer to this one, but I haven't found much. for calculating texture coordinaes for a cube, the top of the cube is perfectly textured, but the back and right side are half textured ( form corner to corner, splitting it in half ) and the other two sides and the bottom are not textured right. I havent done any texture rotation yet...that could be the problem. is this not correct?: U = ((Vertex . UNormal) / Width / UScale) + (UShift / Width) V = ((Vertex . VNormal) / Height / VScale) + (VShift / Height) here's my code:
/** calculate texture offsets **/
int translateTextures(void)
{
  extern WORLD world;
  extern TEXTURES textures;

  uint g, t, i;
  Vertex3 temp;


  /** get all the texture coordinates **/
  for (g=0; g < world.cntBrushes; g++)
  {
    for (t=0; t < world.poly[g].cntFaces; t++)
    {
      world.poly[g].face[t].texture.texX = malloc(world.poly[g].face[t].cntVertices * sizeof(float));
      world.poly[g].face[t].texture.texY = malloc(world.poly[g].face[t].cntVertices * sizeof(float));

      for (i=0; i < world.poly[g].face[t].cntVertices; i++)
      { // fprintf(file, "texid:%i, width:%i\n scaleV:%f\n scaleU:%f\n height:%i\n\n", world.poly[g].face[t].texture.texID, textures.tex[world.poly[g].face[t].texture.texID].width, world.poly[g].face[t].texture.scaleV, world.poly[g].face[t].texture.scaleU, textures.tex[world.poly[g].face[t].texture.texID].height);

        world.poly[g].face[t].texture.texX[i]
         = (  // U = ((Vertex . UNormal) / Width / UScale) + (UShift / Width)
             (
                 scalarProduct(&world.poly[g].face[t].vertex[i], &world.poly[g].face[t].texture.texU)
               / textures.tex[world.poly[g].face[t].texture.texID-1].width
               / world.poly[g].face[t].texture.scaleU
             )
           +
             (
                 world.poly[g].face[t].texture.shiftU
               / textures.tex[world.poly[g].face[t].texture.texID-1].width
             )
           );

        world.poly[g].face[t].texture.texY[i]
         = (  // V = ((Vertex . VNormal) / Height / VScale) + (VShift / Height)
             (
                 scalarProduct(&world.poly[g].face[t].vertex[i], &world.poly[g].face[t].texture.texV)
               / textures.tex[world.poly[g].face[t].texture.texID-1].height
               / world.poly[g].face[t].texture.scaleV
             )
           +
             (
                world.poly[g].face[t].texture.shiftV
              / textures.tex[world.poly[g].face[t].texture.texID-1].height
             )
           );
      }
    }
  }
  return 0;
}




by the way, I organized the stuff in parenthises like that because I find it much easier to read if its written likea functoin :-) [Edited by - LabRat404 on December 4, 2004 3:15:45 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this