• Advertisement
Sign in to follow this  

Correct texture rotation along object rotation

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

The next problem that I have concering the icosahedron rotation is when applying
a texture on the icosahedron when I am drawing it manually by using active edge list.

I use a 2D array that contains MxN sample points of a checkerboard data and each
sample point contains a RGB color value. When I am drawing each pixel of each triangle
in the icosahedron, a color value sample is obtained based upon the current position of
a pixel that is drawn from the checkerboard data.

Now when the icosahedron is rotated and when I apply the texture during the drawing,
the texture is applied and rotated correctly IF I am rotating the drawing process and
at the same time keeping every vertex in each triangle in the icosahdron constant,
which is shown in the attached image 'icotexrotalt.png'.

But as you can see there are triangles that are not drawn at all and a solution to it
is rather to rotate every vertex instead and keep the drawing process constant.
All of the triangles will be drawn. But when it comes to the texturing part it doesnt
map correctly on every triangle at all and during rotation it doesnt rotate along
the icosahedron but instead it stays still as a constant image. This can be seen in
the attached image 'icotexnotcorrect.png'.

In short this is what I am doing in the code as a comparison between the two rendering
process:


1:
-------------Every vertex is kept constant while the drawing process is rotated---------------

FaceFillDrawRot(face f, float angle)

if (texture)
{

//The texture mapping
texValueR = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][0];
texValueG = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][1];
texValueB = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][2];


//Sets current texture color
glColor3f(texValueR, texValueG, texValueB);
}

//Rotation around x-axis

if (aroundX)
{
xrot = currX;

scanlinerot = scanline*cos(angle) - currDZDX*sin(angle);
zrot = scanline*sin(angle) + currDZDX*cos(angle);
}

// Draw at the current scanline
if(zrot < zbufferdata[(int)xrot+1000][(int)scanlinerot+1000])
{
glVertex2f((xrot)/1000.0f,
(scanlinerot)/1000.0f);
zbufferdata[(int)xrot+1000][(int)scanlinerot+1000] = zrot;
}
-------------------------------------------------------------------------------------------------------------

2:
--------------------Every vertex is rotated while the drawing is constant------------------------
Faces rotFaceX(Faces f, float angle)
{

f.v1.x = f.v1.x;
f.v1.y = f.v1.y * cos(angle) - f.v1.z * sin(angle);
f.v1.z = f.v1.y * sin(angle) + f.v1.z * cos(angle);

f.v2.x = f.v2.x;
f.v2.y = f.v2.y * cos(angle) - f.v2.z * sin(angle);
f.v2.z = f.v2.y * sin(angle) + f.v2.z * cos(angle);

f.v3.x = f.v3.x;
f.v3.y = f.v3.y * cos(angle) - f.v3.z * sin(angle);
f.v3.z = f.v3.y * sin(angle) + f.v3.z * cos(angle);

return f;

}


FaceFillVertexRot(face f)


if (texture)
{

//The texture mapping
texValueR = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][0];
texValueG = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][1];
texValueB = (float)checkImage[(int)(abs(currX-abs(xStart))/4.0f)]
[(int)(abs(scanline-abs(scanlineStart))/4.0f)][2];


//Sets current texture color
glColor3f(texValueR, texValueG, texValueB);
}


// Draw at the current scanline
if(currDZDX < zbufferdata[(int)currX+1000][(int)scanline+1000])
{
glVertex2f((currX)/1000.0f, (scanline)/1000.0f);
zbufferdata[(int)currX+1000][(int)scanline+1000] = currDZDX;
}
-----------------------------------------------------------------------------------------------------

Share this post


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

  • Advertisement