Jump to content
  • Advertisement
Sign in to follow this  
Stephelton

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!