# 2D Rotation Floating-point Error

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

## 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 on other sites
[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.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633325
• Total Posts
3011370
• ### Who's Online (See full list)

There are no registered users currently online

×