Jump to content
  • Advertisement
Sign in to follow this  
LabRat404

.MAP UV texture calculations

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

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
         = (  // U = ((Vertex . UNormal) / Width / UScale) + (UShift / Width)
             (
                 scalarProduct(&world.poly[g].face[t].vertex, &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
         = (  // V = ((Vertex . VNormal) / Height / VScale) + (VShift / Height)
             (
                 scalarProduct(&world.poly[g].face[t].vertex, &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
Advertisement
Sign in to follow this  

  • 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!