Moving objects BIG distances

Hi!! I’m making a space simulator using VB and for that I’m drawing a sphere of radius=1738000. Obviously the objects floating around must be outside this sphere so they have xyz coordinates as big as the radius.

The problem I’m having is: when moving the objects only fractions of units (for example moving from 1739000 to 1739000,05 - 1739000,10 - 1739000,15 - etc) the object seems to ‘shake’ in the axis where the object is moving. The cammera is commanded to follow the center of the object so I believe the problem is there, maybe the glLookAt cannot process such big numbers, I don’t know…but when I work with small numbers it does not ‘shake’…

Thanks!!!

I would suggest refactoring the numbers you are using.
For example let’s say a planet is 6000km in radius, use 6.00f for it’s radius size, and scale everything else accordingly. You’ll be making better use of the accurate range of your floating point numbers then. There are also doubles (I presume you have those in VB?).

I have been working on various space sim engines for quite a while and as a rough rule of thumb if you use that number base then you can represent a fairly decent planetary system (modelled on our own) without jitter, all the way out to Pluto!

If you need to represent coordinates larger than that then you’ll need to use a custom number system which could be as simple as having integer sector coordinates, and doubles for coordinates inside each sector.

This is a common problem. Try to scale your scene down.

OpenGL has 32-bit floating-point precision, which is about 7 decimal digit of precision.

ref: http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers

“Single precision, […]. This is a binary format that occupies 32 bits (4 bytes) and its significand has a precision of 24 bits (about 7 decimal digits).”

We’ve had to deal with similar precision issues. Check out here for more information and other options.

Use doubles to compute your composite MODELVIEW transform. Then thunk down to float only when you hand the finished product to OpenGL.

Think about it this way. float gets you ~7 sigfigs. For your world-space, you’re eating pretty near all of those on the shear magnitude of the numbers. You’ve got nothing left, so your quantization error is huge.

What does this mean for objects close to the eye? HUGE translate in MODELING, HUGE inverse translate in VIEWING. Resulting MODELVIEW translate – pretty tiny. But sorry, you lost all your bits doing that matrix compute in float, so you’ll never really know how tiny to any accuracy.

So don’t. Use doubles.

Thank you for your answers!!

I’m using doubles as variable types. The video located on Wspace’s site shows exactly what’s happenning with my simulator. Unfortunately I’m such a beginner I cannot fully understand everything, it will take time to solve the problem.

Wspace, if there’s any way you could explain it to me any further I’ll appreciate!! Thanks anyway!!

It’s worth checking out Celestia. It’s Open Source. Has a great community and there has been much discussion on ‘Universal Coordinates’ and the issues they pose both at local and universal levels…

Are you using GL to do all your matrix math (glScale/glRotate/glTranslate/gluLookAt/etc.)? If so, there’s your problem.

Even if you provide double to GL, that’s thunked down to float. GL/GPU pipeline is based on float, not double.

Do your matrix math for building your MODELVIEW outside GL using your own math library. Then just hand the result to GL at the end via glLoadMatrixd.

Are you using GL to do all your matrix math (glScale/glRotate/glTranslate/gluLookAt/etc.)? If so, there’s your problem.

Even if you provide double to GL, that’s thunked down to float. GL/GPU pipeline is based on float, not double.

Do your matrix math for building your MODELVIEW outside GL using your own math library. Then just hand the result to GL at the end via glLoadMatrixd.
[/QUOTE]that sounds interesting…could you give me an example??

An example of what?

Of a program using glLoadMatrix after processing the data using a math library…

Here you go:


double matrix[4][4];
// Fill matrix here
glLoadMatrixd( (double *)matrix );

And just to clarify:

I didn’t state explicitly but should have: “Do your matrix math for building your MODELVIEW outside GL in double precision using your own math library…”