Jump to content
  • Advertisement
Sign in to follow this  

2D Rotation Floating-point Error

This topic is 3983 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 have a quaternion that converts to a rotation matrix for a 2D(really 3D) quad. For some reason when there is a slight floating-point imprecision in the axis/angle->quaternion->matrix conversion the rotation matrix becomes "invalid" (the quad does not appear to render at all). So if I interpolate the angle across time, the quad rotates fine but flickering, when an element in the matrix is close to 1.0f, but not quite. For example, the quad doesn't render if its rotation-matrix is [ +0.00000000, +0.99999994, +0.00000000, +0.00000000, -0.99999994, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.99999994, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +1.00000000 ] This is at a PI/2 rotation angle, so the matrix should of course be [ 0, 1, 0, 0 -1, 0, 0, 0 0, 0, 1, 0 0, 0, 0, 1 ] In fact if I edit these values in the debugger the quad renders fine... The vertex shader that renders that quad is as straight forward as you can get, (pos * worldviewproj). No inverse trig functions to clamp to or anything. I understand the imprecision, but why would it affect the visibility of the quad besides a micoscopically different angle than PI/2? From googling this type of thing seems to be a common problem, but how is it resolved and why does it occur? I will give it a try debugging the shader to see what is actually happening, but I don't know if that will help.

Share this post


Link to post
Share on other sites
Advertisement
[Solved]

Well, it wasn't what I expected, but it rarely is. I had been clearing the z-buffer to 0.0f, and when the XY rotation was not precise enough it would affect the z value in projection space, either putting the pixel behind the camera or behind the z-buffer. Pretty stupid.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!