tags:

views:

256

answers:

1

hi I've got a quite specific problem.

I want to draw a Map, consisting of 256x256 pixle Tiles (a lot of them). These cover a big area.

The transformation to convert lat|lon(from the globe) to x|y (map) spawns quite big values. With these big values goes accurcy and so, if I go far away from the 0/0 Point, I get inaccuracies of multiple pixels between textures of two Tiles being next to each other (e.g. 2E8 | 0 and 2E8-1 | 0).

How can I fix these messy unwanted grid appearences? The current failing implementaition is to use float to draw the primitives (this should not matter, as all Tiles are clipped to multiples of 256 in both coordinate directions).

I hope this makes any sense to you.

Feel free to ask and be patient with me, at least for me this got a very complex subject.

Note: I allready tried to use glTranslate*d* for offset but either double's accurcy is not enough too, or this is not the reason for the glitches.

Sincerely

Edit: If you experienced this to at some point at your learning curve it would be nice to know how to fix it, or if I am currently fighting a driver bug.

+4  A: 

Actually, I have recently run into the exact same problem in my implementation of rendering entire planets from space to ground. In fact, what you have to do is create a new position structure that splits the accuracy between different floats. For example,

struct location
{
     vec3 metre;
     vec3 megametre;
     vec3 terametre;
     vec3 examtre;
     vec3 yottametre;
};

Then you code all of the operators and type cast functions for this structure (+, -, *, /, toVec3), you then use this location struct to encode the location of your camera and each grid tile. On rendering time, you dont translate the camera, but instead you translate the tiles by difference. For example:

void render()
{
     // ...
     location diff = this->position - camera.position;
     vec3 diffvec = diff.toVec3();
     glPushMatrix();
     glTranslatef(diffvec.x, diffvec.y, diffvec.z);

     // render the tile
     glPopMatrix();
}

What it does is removes the difference calculation from the OpenGL pipeline which only has up to double precision and puts the work on your program which can essentially have infinite precision. Now the precision and accuracy fall the further away you are from the camera instead of the further away you are from the orgin.

Happy Coding.

Ned
What do you mean by <this-position>, the origin or the last point of the camera position?Thanks a lot for answer
penguinpower
It is written in C++, and the function render() belongs to the tile class or structure, therefore this is a pointer to the tile that is being rendered. So this->position is the position of type location of the tile that is currently being rendered.
Ned
Thanks very much :) you really helped me out of the mud.. keep coding
penguinpower