Sign in to follow this  

Floating point rounding errors

Recommended Posts

Stephelton    122
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 this post

Link to post
Share on other sites
jyk    2094
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this