We do all of the calculations in what we call simulation space (using double precision values)... and then we convert everything into game space to render it on screen.
The camera, in game space, always stays at 0,0,0 and everything is moved and scaled around it (meaning we track the position of the camera using double precision values in the simulation space).
Every frame we calculate the ScaleFactor based on what we are closest to:
ScaleFactor = Math.Min(1d, 1d / (0.000001d + DistanceToClosestSurface));
And then for each planet and moon we calculate a game space position and scale:
Body.gameSpace.position = Transform(Body.Position, out gameScaleFactor);
Body.gameSpace.localScale = Vector3.one * (float)(radius * gameScaleFactor);
Here's the Transform code that's called above:
public static Vector3 Transform(Vector3D position, out float scale)
{
Vector3D.Subtract(ref position, ref CameraPosition, ref position);
Vector3D.Scale(ref position, ScaleFactor);
scale = (float)(ScaleFactor);
return position.ToVector3();
}
Note:
Body.Position is a Vector3D with the position of the body in meters.
CameraPosition is a Vector3D with the camera position in meters.
Vector3D is a collection of 3 doubles.
Vector3 is a collection of 3 floats.
Does that help?