# Maximum world size

I know, I can take default units as tens, or hundreds of meters. But. How much space I have in those units? How far from central point I can go?
For scengraph to properly work?
For physics and collision detection?
For raytest?

It depends on how much accuracy you desire. A float only has so many bits. You can use it for really big numbers or you can use it for really close together numbers but not both at the same time.

Maybe if you told us what you were actually trying to achieve we could provide a better answer and better advice on how to proceed.

Short answer: Put the player in the center of the coordinate system and you’ll be fine unless you need astronomical distances.

A float has 24 bits of accuracy, that’s a bit better than 7 decimal digits.
If you assume 1.0f = 1 meter, then accuracy will be 1 mm at 2^24 = 16,777,216 mm = 16.8 km.

If your game world is larger than that, you need to store world coordinates as doubles (52 bits, millimeter precision at 4,500 mio km, that’s about a quarter of a light second, or ten times the Earth-Moon distance).
The next option would be a long (63 bits, 9,000,000,000 km, six times Earth-Sun).
After than, you’d need BigIntegers.

For the scenegraph, you usually place the player’s position at (0,0,0), so everything up to 17 km distance is at millimeter accuracy.
For collisions, you usually keep the colliding scene well below the limits.
Raycasting will work for the vast majority of cases - you can simulate a laser ray going from Earth to Moon and back and still have sub-millimeter precision. If you need to do that kind of simulation at larger distances, you’ll have to use floats (that means writing your own raycasting code).

<cite>@pspeed said:</cite> Maybe if you told us what you were actually trying to achieve we could provide a better answer and better advice on how to proceed.
Space/flight sort of thing. And as much scale and precision as I can get without inventing my own coordinate system.
<cite>@toolforger said:</cite> A float has 24 bits of accuracy, that's a bit better than 7 decimal digits. If you assume 1.0f = 1 meter, then accuracy will be 1 mm at 2^24 = 16,777,216 mm = 16.8 km.
Thank you for detailed answer. What format jmonkey store positions in? Yesterday i flew freelook camera beyond 32 000, and everything seems to be smooth and working.

JME stores positions in float because that’s what OpenGL will use.

You will want to make your world camera-relative, ie: camera is always at 0,0,0… then translate your game coordinates into “float relative to camera”. You may have been able to fly to 32,000 units but physics and other things will start to become really unstable. Basically, when you fly out to 32,000 units you will not be able to properly represent mm accuracy and that’s more serious than you might think. And it gets much worse the further you go.

If you keep the camera at 0,0,0 and move the world around you then you won’t have this problem. Accuracy will only suffer for things that are too far away for the errors to matter.

You will already have to be paging in and out parts of your world… so it should be relatively easy to keep them camera-relative once loaded.

Note that a) you are not bound to encode your positions with only one primitive per dimension and b) as paul said you won’t (and can’t) display a whole solar system at millimeter accuracy on one monitor anyway. So keep your display system and data system apart, don’t try to store your planetary data inside the scenegraph, construct the scene based on what the user sees. If he looks at the whole galaxy he can’t see single ships or bases anyway and when he zooms into one station he can’t see the planets in the next solar system, if at all thats just a star at the horizon. Check out the “World of Inception” example class to see how you can have infinitely fine resolution while still using normal 32bit values. Finally note that this is not a jME limitation, OpenGL (and GPUs) work with 32bit values.