2D Terrain texture mapping

Official forum for the Chipmunk2D Physics Library.
Post Reply
anupgupta
Posts: 13
Joined: Sun Sep 19, 2010 5:04 am
Contact:

2D Terrain texture mapping

Post by anupgupta »

Hello,

i am working on a game similar to hill climb racing, but i am facing a peculiar issue.
normal ground image as the game starts
normal ground image as the game starts
IMG_0181.png (20.7 KiB) Viewed 3251 times
distorted ground image as the game progresses
distorted ground image as the game progresses
IMG_0186.png (19.67 KiB) Viewed 3251 times
after playing the game for some time my ground texture begin to stretch.
I am also attaching the (terrain.zip) source code for any inputs that could help me solve the query.
terrain.zip
(4.07 KiB) Downloaded 531 times
just roughly what i am doing is i have calculated 10 points(MAX_HILL_POINTS) which are 200 pixels apart of each other and then divided the whole with 100 segments (MAX_SEGMENTS)..and then in the update i keep checking if the points go outside screen then delete the point from the left and then add one point to the right ..thus this gives me endless terrain. the new point which is added is also 200 pixels apart in x and random in y in a given range. and the cardinal spline algorithm gives me a smooth curve across points. i guess the issue could be in the generatecoordinates() function..but am not sure and need help to understand it.

or if you have a better way of doing this..do let me know
anupgupta
Posts: 13
Joined: Sun Sep 19, 2010 5:04 am
Contact:

Re: 2D Terrain texture mapping

Post by anupgupta »

i did a little bit of debugging with respect to the texture co-ordinates which are being generated.
i think the code area:

Code: Select all

//get the hill texcoordinates
for(short i = 0; i < MAX_SEGMENTS; ++i)
{
//calculating texture co-ordinates
CCPoint pt = hillBottomVertices[i];
hillBottomTexCoords[i] = pt * (1.0f / terrainBottomTexSize);
hillBottomTexCoords[i].y = 1.0f - hillBottomTexCoords[i].y;

CCLOG("point: %f %f", hillBottomTexCoords[i].x, hillBottomTexCoords[i].y);
}
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.
As i move ahead the x co-ordinates keeps on increasing and the texture goes on stretching more.

how do i make sure that the texture co-ordinates in the x direction are close to 0...or maybe reach 256 (texture size = 256) and then reset.
Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests