Is glRotated of a lower precision than glTranslated?

Started by
18 comments, last by Rasmadrak 18 years, 1 month ago
Hi there! In my FPS game (set in a HUGE world) I recently discovered the nasty headaches of floating point imprecision... :/ But I realized that if I don't do any rotates precision is just fine!

        glRotated(ViewPitch,1,0,0);  //comment out these for jumpfree graphics.
        glRotated(ViewYaw,0,1,0);    //comment out these for jumpfree graphics.
        glTranslated(-Pos.x,-Pos.y,-Pos.z);

Is there something wrong with my camera class, or does opengl do something funky when using glRotate? Cheers people!
"Game Maker For Life, probably never professional thou." =)
Advertisement
I think OpenGL stores the transforms internally as floats. So try keeping your own double-precision matrix for the camera and using glLoadMatrixd to send it to OpenGL. This eliminates accumulated floating point precision errors (actually it doesn't but makes them order of 2^29 times smaller because of the mantissa being 29 bits longer double vs float).

This reasoning is however only correct if OpenGL doesn't store double precision copies of the matrix stacks and use them modifying the stacks. But try it and see if it makes a difference.
Olli Salli
Rotations must be done in degrees
(only stupid answer I can come up with)
At least I got the impression his rotations and translations were working all right unless he moved in his world so that the absolute value of the translation is REALLY big and floating point inaccuracies cause movement to get all choppy and jerky.
Olli Salli
i would translate first then rotate
As oggialli said, the camera works perfect if I maintain a position close to the origin of the map.

I'll try making my own matrix, I'll let you know how it goes!

/Robert
"Game Maker For Life, probably never professional thou." =)
Quote:Original post by Glaiel_Gamer
i would translate first then rotate


That won't work the same way at all - the rotation axis will be different (with non-zero translation, that is).
Olli Salli
Ah, one more thing! When using your own matrices in OpenGL (with glMultMatrix / glLoadMatrix) be sure to remember to follow its row-column ordering. It is so that the base vectors of the 4x4 matrix are laid out contiguously in memory.
Olli Salli
dunno if I did something wrong, but it made no difference.. >_<

Any more ideas..?
"Game Maker For Life, probably never professional thou." =)
Hmm... so you are now using a matrix of your own, which is stored as double-precision, not single-precision numbers?

What is your coordinate system like? In other words, in what range are the translation values going to be?

Really strange indeed. In normal circumstances, however large your worlds might be, doubles should give you more than enough precision. Hmm... I wonder if using long doubles and then converting them to doubles before sending to OpenGL you would get any benefit. You can always try fairly easily...
Olli Salli

This topic is closed to new replies.

Advertisement