- Home /
Vector3 using Doubles Instead of Floats
I'm trying to make a really detailed Solar System simulation. I want vaguely realistic distances between planets but at the same time I want to able to reliably do maths for distances as small as 1km. I've already done a bunch of work on scaling things down and shortening distances but floats just don't give me enough precision to get the distances I want whilst have the same fine control.
Is there a way to use Doubles instead of Floats?
Answer by Beugnen · Nov 14, 2012 at 04:03 AM
There are a couple of tricks which seem to be necessary with floats:
Floating Origin
http://wiki.unity3d.com/index.php?title=Floating_Origin http://answers.unity3d.com/questions/137097/scale-objects-based-on-distance.html http://www.floatingorigin.com/
...and logarithmic depth buffers
http://www.gamasutra.com/view/feature/2984/a_realtime_procedural_universe_.php
It's not perfect as Sean O'Neil says.
A better approach may be to use Floating Origin together with scaled-subspaces as per this article
Answer by Eric5h5 · Sep 05, 2011 at 10:38 PM
There's no way to use doubles in Vector3. You can make your own Vector3-like struct that uses doubles, but you won't be able to use it for Transform.position. Generally the way you handle this isn't by using doubles anyway, but by doings things like using two coordinate systems, one "global" and one "local", so you can have precision with close objects using local coords.
That's a really interesting idea. Would I be able to just add a new coordinate on top of the existing system so that I could use it with transform?
No, you'd have to create a system to handle the two coordinate systems.
God, I have no idea where to even start with that. I started thinking along the lines of new new vector3 to act as the new coord system's origin, but then I realised that would require me to reference the original coord system and I'd be back to square one. For this to work I'd have to completely circumvent the entire existing coordinate system and I'm not sure how to reference points in space without it.
There are a bunch of topics on the forums about this, so searching should reveal some info.
I went through about 20 pages of results for the keyword "coordinate". I figured anything related to this would have to have that word in there SO$$anonymous$$EWHERE? :P
Anyways, no luck. The only thing I found was this page, and it didn't have much to say about a custom coord system: http://forum.unity3d.com/threads/59476-Problem-simulating-tiny-ships-vs-huge-stations-and-planets?highlight=coordinate
I don't spose you remember any of the topics you were talking about, do you? :(