April 02, 2020, 10:49:25 AM

Author Topic: Floating Point Numbers  (Read 860 times)

Offline JBR

  • Jr. Member
  • **
  • Posts: 75
Floating Point Numbers
« on: November 07, 2019, 07:20:47 PM »

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.

Offline grindalf

  • Jr. Member
  • **
  • Posts: 90
Re: Floating Point Numbers
« Reply #1 on: November 07, 2019, 07:28:09 PM »
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

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1039
Re: Floating Point Numbers
« Reply #2 on: November 07, 2019, 08:58:32 PM »
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 ?
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Xaron

  • Sr. Member
  • ****
  • Posts: 278
Re: Floating Point Numbers
« Reply #3 on: November 19, 2019, 04:02:50 PM »
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

Offline JBR

  • Jr. Member
  • **
  • Posts: 75
Re: Floating Point Numbers
« Reply #4 on: November 19, 2019, 06:46:27 PM »
Thanks guys, I'll have another go at it. Jim.


SimplePortal 2.3.6 © 2008-2014, SimplePortal