I have a problem with computing texture-space coordinates for a cylinder in raw webgl (no frameworks used). I was able to create the cylinder's polygon list and normal vectors, but somehow I'm struggling with the u,v textures. What I intended to do was:
tex_step_x = 1 / divisions;
for(var u = 0; u < divisions; u++)
{
// Top plate
textureCoordData.push(0.5); textureCoordData.push(0.5);
textureCoordData.push(1); textureCoordData.push(0.5);
textureCoordData.push(1); textureCoordData.push(0);
// The walls
textureCoordData.push(tex_step_x*u); textureCoordData.push(1);
textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(1);
textureCoordData.push(tex_step_x*u); textureCoordData.push(0);
textureCoordData.push(tex_step_x*u); textureCoordData.push(0);
textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(0);
textureCoordData.push(tex_step_x*u+tex_step_x); textureCoordData.push(1);
// Code for the bottom circle
textureCoordData.push(0); textureCoordData.push(1);
textureCoordData.push(1); textureCoordData.push(0);
textureCoordData.push(1); textureCoordData.push(1);
}
The Cylinder is made out of "cake slices" for the bottom and top plate (with different heights) and two triangles for each segment of the wall. Any Ideas on how to calculate the right u,v-coordinates?