View Full Version : Moving objects BIG distances

C5C6ARG

11-18-2009, 06:06 PM

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!!!!!!

scratt

11-18-2009, 07:06 PM

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.

overlay

11-18-2009, 07:09 PM

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)."

wSpace

11-19-2009, 11:32 AM

We've (http://insight3d.com/) had to deal with similar precision issues. Check out here (http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/) for more information and other options.

Dark Photon

11-19-2009, 12:02 PM

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.

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.

C5C6ARG

11-19-2009, 02:47 PM

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!!

scratt

11-19-2009, 08:01 PM

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...

Dark Photon

11-20-2009, 05:32 AM

I'm using doubles as variable types.

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.

C5C6ARG

11-20-2009, 01:33 PM

I'm using doubles as variable types.

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.

that sounds interesting...could you give me an example??

Dark Photon

11-20-2009, 05:23 PM

that sounds interesting...could you give me an example??

An example of what?

C5C6ARG

11-20-2009, 05:38 PM

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

Dark Photon

11-21-2009, 06:23 PM

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 );

Dark Photon

11-21-2009, 06:33 PM

And just to clarify:

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.

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..."

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.