# # Mapping between vertex coordinate and texture coordinate

This topic is 4699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 cant 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 cant 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]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633319
• Total Posts
3011342
• ### Who's Online (See full list)

There are no registered users currently online

×