   # Mapping between vertex coordinate and texture coordinate
  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 normalvoid 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 normalRotY = -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 texYtexX[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 matrixComputeAxisBase( 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 sdv->st[1] = s->texMat[1][0]*x + s->texMat[1][1]*y + s->texMat[1][2]; //v or tQ2: 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]