Endless terrain distortion

General discussion about Box2D tutorials
Post Reply
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Endless terrain distortion

Post by vkreal »

I have an endless terrain that looks fine at beginning but when it get further and further the graphic(terrain) becomes distorted. I think the further away precision floating point values for x and y positions fall. Anyone have an ideas or suggestion on how to fix this?

Iforce did you see the same issue with DHS?

I am using code below.

Thanks!!!

Code: Select all

glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, _hillVertices);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, _hillTexCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nHillVertices);
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Endless terrain distortion

Post by iforce2d »

No, DHS terrain is not endless.
There is a ShiftOrigin function in b2World which you might find useful: http://code.google.com/p/box2d/source/b ... orld.h#196
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: Endless terrain distortion

Post by vkreal »

THanks for b2World::ShiftOrigin, that will help fix perf on box2d, but prob wont help rendering issue i am having.
kyle.bong2@gmail.com
Posts: 41
Joined: Thu May 29, 2014 5:01 am

Re: Endless terrain distortion

Post by kyle.bong2@gmail.com »

Hi all,

You guys have any examples how to use b2World::ShiftOrigin?

Best!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Endless terrain distortion

Post by iforce2d »

All it does is move all bodies in the world. You can check out the source code here:
https://code.google.com/p/box2d/source/ ... d.cpp#1258

So if your game starts centered around (0,0) and then the player runs a long way to the right (positive x) then you might want to do world->ShiftOrigin( b2Vec2(100,0) )
After that all the coordinates you use for everything would need to be altered by the same amount.
Post Reply