Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Basicly when i set the position of my camera (my character in game) to a high value, the geometries seems to be shaking, the higher the position value, the more they shake. On low position values you can't seem to notice any shaking.

I create a video to make it easyer to explain: http://www.youtube.com/watch?v=dxg6wIl1U1Q

In the video i'm changing to chunkAmount from 100 -> 100000 this is a value i use in the following:

player.position.z = blocksize*((chunksamount/2)*blocksPerRow);
player.position.x = blocksize*((chunksamount/2)*blocksPerRow);

Which is something like 50'000 * 32 * 16 => position.x = 25600000

share|improve this question
2  
Wild guess: are you using single precision floats anywhere? That could be loss of floating point precision. –  amitp Jun 17 '13 at 0:48

1 Answer 1

up vote 5 down vote accepted

Floating point values lose precision when they get larger. Keep your values as close to zero as you can. For large worlds, split them into chunks (addressed by integer chunk coordinates) and then make world coordinates relative to the "current" chunk (where the player or camera is), shifting objects whenever you move to another chunk. With this approach your world coordinates will snap back closer to zero when you move far enough, avoiding precision problems.

For instance, if you're in chunk 3,2 and your chunks are 64 units wide then the world coordinate used for the center of chunk 4,7 would be (64,320). If the camera moved to chunk 4,5 then chunk 4,7 would be centered at world coordinate (0,192) instead, being shifted along with all of its children.

You can either update all chunk/object world positions as you move between chunks or you can store everything in a tree and recalculate hierarchical model-world matrices using the delta of integer coordinates for each chunk from the cameras chunk.

For large distances, scale down the objects being rendered. You don't need centimeter precision for a view where each pixel is roughly a meter of terrain. Use scaled coordinates for rendering if you can.

You could also switch to using doubles but then you'd need recent hardware and things will be slower; better to spend effort on fixing your world basis.

share|improve this answer
3  
One addition: The distance to zero is not of any importance. Scaling your range by eg dividing by 10000 gets you closer to zero but does not change precision eg 1000.001 -> 0.001000001. Whats important is the distance between the highest non zero and the lowest non zero digit. When they move to much apart from each other the lower end can no longer be expressed. –  Archy Jun 17 '13 at 9:06
    
@Archy: that's true only inasmuch as scaling an already large number with lost precision doesn't buy back any lost precision. My point was to keep all the numbers close to zero since then you never lose the precision in the first place. Deltas as you mention are important because you're moving everything to a zero origin in the world-view matrix anyway; however, two large numbers with a small delta will still have the worst precision from those two numbers. –  Sean Middleditch Jun 17 '13 at 16:10
    
What I tried to say is that it's all relative. Two small numbers with a VERY small delta will have exactly the same precision issue as two large numbers with a small delta. The difference is only in the exponential part of the floating point number which is not the reason of the precision issues. –  Archy Jun 17 '13 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.