Floating Point Numbers

Started by JBR, November 07, 2019, 19:20:47

Previous topic - Next topic

JBR

Hi,

I know that if the 'play area' gets too far from 0,0,0 then floating point numbers can get unusable.

I have a planet at 0,0,0 but the player can fly far off. Should I limit this or will single floating point be ok?

Thanks, Jim.

GrindalfGames

you could do a simple test and just move you player further and further away. You should see shaking in the camera and character when it starts getting bad.
A floating point only has so many digits(I seem to remember its 16 but it was a long time ago so im probably wrong) so at first your x position would be 0.000000000000000
but after you've moved to far away you have 10000000.00000000 and you have less precision after the point for accuracy. Im not really why this results in the shaking but that's what happens :P

RemiD

#2
best approach i have found for this  is to split the unit system in a 2 units system
a world (or global) coordinate (for example from 000x,000y,000z to 999x,999y,999z )
a zone (or local) coordinate (for example from 0.0x,0.0y,0.0z to 1000.0x,1000.0y,1000.0z )

your player will only move/turn in this 1000x1000y1000z zone, and the environments and others entities will be repositionned depending on player repositionning.
so when player moves/turns in the 1000x1000y1000z space, all environments/othersentities are updated normally.
but when player goes beyond one border of the 1000x1000y1000z zone, he will be repositionned in the 1000x1000y1000z space, at the position it would have been in the new zone
then all environments/othersentities are repositionned to the positions they would have been related to player.
then you update the world position because player moved in a new zone...
in this way your world can be extremely big, and you will never have any problem concerning float precision...
clear ?

Xaron

Floating point precision is just 6-7 digits.

For stuff like planets you need double precision or use some tricks:
a) reposition everything around the origin
b) use scaling, e.g. don't move the planets far away, just scale them down when reaching a distinct distance

JBR

Thanks guys, I'll have another go at it. Jim.