texture mapping on uneven 2D terrain
Posted: Thu May 01, 2014 4:57 pm
the game i am making is like hill climb racing.. my car moves ahead and the ground is uneven and i have mapped the texture on the ground which work great. but after playing the for a while my ground texture starts to stretch and keeps on stretching as i move forward.
the texture coordinates values are like
point: 0.937500 0.594344
point: 0.937500 1.000000
point: 1.093750 0.565063
point: 1.093750 1.000000
point: 2.031250 0.347375
point: 2.031250 1.000000 …so on
point: 166.875000 0.280531
point: 166.875000 1.000000 … till
point: 260.937500 0.308594
point: 260.937500 1.000000 .. until the X co-ordinates goes beyond 256 which is also the size of the texture(size = 256) ..that the stretch starts to appear.
is there any solution which can be used to handle this issue. Any Suggestions
after some debugging, i found that the texture co-ordinates in x direction become too large and the image distorts after the co-ordinates go beyond 256.Code: Select all
//calculating texture co-ordinates
for(short i = 0; i < MAX_SEGMENTS; ++i)
{
CCPoint pt = hillBottomVertices[i];
hillBottomTexCoords[i].x = pt.x/(terrainBottomTexSize/CC_CONTENT_SCALE_FACTOR());
hillBottomTexCoords[i].y = 1.0f - pt.y/(terrainBottomTexSize/CC_CONTENT_SCALE_FACTOR());
CCLOG("point: %f %f", hillBottomTexCoords[i].x, hillBottomTexCoords[i].y);
}
point: 0.937500 0.594344
point: 0.937500 1.000000
point: 1.093750 0.565063
point: 1.093750 1.000000
point: 2.031250 0.347375
point: 2.031250 1.000000 …so on
point: 166.875000 0.280531
point: 166.875000 1.000000 … till
point: 260.937500 0.308594
point: 260.937500 1.000000 .. until the X co-ordinates goes beyond 256 which is also the size of the texture(size = 256) ..that the stretch starts to appear.
is there any solution which can be used to handle this issue. Any Suggestions