# Floating point rounding errors

This topic is 2790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on a concept game that involves a smaller ball (player) that rotates around a larger ball (globe). Left and right movement alter the direction of the player's rotation around the globe.

The way I have it modeled right now, there is an imaginary axis "rotation axis" around which the player currently rotates according to his velocity. This axis is arbitrary; it is not required to align with anything (X, Y, or Z in particular). This axis is then itself rotated when the player changes direction (described above). This is achieved in the same manner: it is rotated about the player (more specifically, an axis defined from the origin (the center of the globe) to the center of the player).

Some of you experienced developers can probably already guess the problem I'm having. For this concept to work, the player-axis and the rotation axis must always be orthogonal. However, floating point rounding errors cause this condition to fail. Because I'm using OpenGL ES, I've stuck with 32-bit floats (as opposed to doubles), so this actually happens fairly quickly.

I suppose that I could detect and fix this skew. One method I've thought of is to calculate a plane that is normal to the rotation axis and intersects the origin. The player should always intersect this plane as well, so if he is significantly far from it, I can move him to the point on that plane that is closest to his current position (and then make sure he's resting on the globe -- this is some simple math involving radii).

Any thoughts?

##### Share on other sites
How are you representing your rotations? Quaternions? Matrices?

##### Share on other sites
I'm using quaternions, I derived my quaternion algorithms from:

http://www.cprogramming.com/tutorial/3d/quaternions.html

##### Share on other sites
Although I don't fully understand the control scheme you're using, generally speaking, it sounds like you have the right idea: that is, you'll have to take steps as necessary to correct any drift before it can accumulate.

What steps to take depends on the circumstance, but the ideas you put forth in your post sound fairly reasonable.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002297
×