PDA

View Full Version : Accuracy at large translations



w00tguy123
12-18-2011, 09:55 PM
I don't understand why when I translate something very far (like to an X of 100,000) the object being drawn snaps around while moving instead of being smooth. I figured it was because I was using floats (only had a couple decimal points of precision at that distance), but when I started using glTranslated the result was the same.

The object being drawn has vertices defined by floats, but I figure that shouldn't matter because the object itself is very small. Does gltranslate add an offset to all of the vertices or something? If that's true, then making the object use double precision vertices should fix the problem right?

Alfonse Reinheart
12-18-2011, 11:54 PM
I figured it was because I was using floats (only had a couple decimal points of precision at that distance), but when I started using glTranslated the result was the same.

I wouldn't expect the "double` versions of the matrix functions to actually use doubles internally. They probably just cast them to floats.

You need to use doubles to generate your ModelView matrix manually (ie: not with OpenGL functions), then convert that matrix back to floats when you hand it to OpenGL (via glLoadMatrix). That way, your large translation from model-to-world will cancel out with your equally large but negative world-to-camera translation.

overlay
12-19-2011, 12:01 AM
read the "Floating point precision and accuracy" section here:

http://www.opensg.org/wiki/HDI/HugeScenes

www.floatingorigin.com/pubs/thorneC-FloatingOrigin.pdf (http://www.floatingorigin.com/pubs/thorneC-FloatingOrigin.pdf)

As well as this detailed blog post:

http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/

w00tguy123
12-19-2011, 12:21 AM
@Alfonse: Thanks, that did the trick!
@Overaly: Also thanks, I'll check those out.