Archived

This topic is now archived and is closed to further replies.

Barn Door

Are floats big enough?

Recommended Posts

Hi there, A Directx vector is defined using floats. Surely this puts a limit on the size of one''s world? I presume that if an object, say a plane, in a 3D world were to max out on one of its vector components it would wrap around and appear on the other side of the world. Has anybody had problems with this issue? Cheers, BD.

Share this post


Link to post
Share on other sites
a float is accurate enough to model a milimetre between here and the horizon

a double can model a human hair anywhere in the solar system

the wraparound is at numbers close to 2**256 which is about 65536 million million million million million million million million million million million million

Share this post


Link to post
Share on other sites
There is a good article at gamasutra (stoopid name) about this issue (was on thje front page)

I think if floats are too small for you, your not doing it right. ex. do you really NEED the distance between planets to be measured in Meters? (like in the article)

Share this post


Link to post
Share on other sites
The problem with floats is not that they'll wrap around, but it's that as you get further from the origin, you get less accurate. A float gives you about eight significant digits of accuracy. That means that when you're 101 units from the origin, you get about 7 decimal places. But if you were 107 units from the origin, you'd only get 1 decimal place.

The trick is (usually) to divide your playing area up into blocks of about 105 units. That way you always get at least 3 decimal places of accuracy, but you can have a world as big as you like. The tricky part comes when you want to cross over the boundaries of your areas...



If I had my way, I'd have all of you shot!


codeka.com - Just click it.

[edited by - Dean Harding on July 30, 2002 6:25:23 PM]

Share this post


Link to post
Share on other sites
if you''re dealing with galaxy-sized environments, just keep their positions relative to you. scale this as appropiate:

with you always in the centre of the universe,
in the solar system you are in, calculate all planets relative to you
calculate all the objects on that planet relative to that planet.

you will only see metre-sized distortions at objects about 10**7 metres away, and who''s going to notice that on a mountain in the distance?

to keep the planets accurate, store them relative to the centre of the solar system
a solar system won''t go noticed if it is a little inaccurate with the next nearest star, and any numeric fluctuations will affect the enire system and all the objects in it at once, so relatively, the change will be invisible

Share this post


Link to post
Share on other sites