Advertisement Jump to content
Sign in to follow this  

# Mapping between vertex coordinate and texture coordinate

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

Mapping between vertex coordinate and texture coordinate? Hey all, Happy New Year. My current study is the arithmetic of mapping between vertex coordinate and texture coordinate. The primary problem is to compute the axis base for the plane where the vertices are on. There is a way from Quake3 source code, but I can`t understand it. (As we known, Quake3 uses right-handed coordinate systems: z-axis points up,y-axis points into the screen) //typedef float vec_t; //typedef vec_t vec3_t[3]; // NOTE : ComputeAxisBase here and in editor code must always BE THE SAME ! // WARNING : special case behaviour of atan2(y,x) <-> atan(y/x) might not be the same everywhere when x == 0 // rotation by (0,RotY,RotZ) assigns X to normal void ComputeAxisBase(vec3_t normal,vec3_t texX,vec3_t texY) { vec_t RotY,RotZ; // compute the two rotations around Y and Z to rotate X to normal RotY = -atan2(normal[2], sqrt(normal[1]*normal[1] + normal[0]*normal[0])); RotZ = atan2(normal[1], normal[0]); // rotate (0,1,0) and (0,0,1) to compute texX and texY texX[0]= -sin(RotZ); texX[1]= cos(RotZ); texX[2]= 0; // the texY vector is along -Z ( T texture coorinates axis ) texY[0]= -sin(RotY)*cos(RotZ); texY[1]= -sin(RotY)*sin(RotZ); texY[2]= -cos(RotY); } Q1: How does this function work? I drew it in draft, but I can`t see. Then compute the texture coordinate. //dv->xyz is the coordinate of the vertex, s->texMat is texture transform matrix ComputeAxisBase( Normal(the plane where the vertex is on), texX, texY ); x = DotProduct( dv->xyz, texX ); y = DotProduct( dv->xyz, texY ); dv->st[0] = s->texMat[0][0]*x + s->texMat[0][1]*y + s->texMat[0][2]; //u or s dv->st[1] = s->texMat[1][0]*x + s->texMat[1][1]*y + s->texMat[1][2]; //v or t Q2: Why to use DotProduct here? How to convert the 3-D coordinate into 2-D texture coordinate? Your any proposals and ideas are helpful. Thanks. /////////////////////////////////////////////////// This issue has been closed. Thanks for your attention. 2006.1.8 [Edited by - cywater2000 on January 7, 2006 8:14:20 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!