PDA

View Full Version : A bug in glrotated?



chowie
06-17-2003, 03:56 AM
hi. i'm calling glrotated(angle, x, y, z) when a mouse button is down and it is dragged along the window. it is to rotate an object in 3d space. it works for like about 500 degrees, and then the thing gets stuck, and it can't rotate anymore. any idea what's happening?

Relic
06-17-2003, 04:03 AM
Almost zero chance that glRotated has a bug.
Your mouse left the window or hit the border of your desktop?

chowie
06-17-2003, 04:14 AM
yar i guess it shouldn't be a opengl bug.. probably me. the mouse has not left the window. rather, the left mouse button is down, drag, button up, OK. then u repeat this for about 3 times then it gets stuck (the object has been rotated cumulatively for about 500 degrees).

what i did was that i took note on the mouse down position, then on mousemove i keep calculating the distance between mouse down position and current mouse position. then using ratios i calculate an angle to rotate. this angle is passed to glrotated(xrotate, 1, 0, 0) etc. that should be all, right?

Relic
06-17-2003, 04:35 AM
Yes, that's how I would do it too, except that I always keep angles in the interval from [0, 360)
Add a simple



if (angle < 0)
angle += 360;
else if (angle >= 360)
angle -= 360;

and see if that helps.

[This message has been edited by Relic (edited 06-17-2003).]

Omaha
06-17-2003, 07:01 PM
Don't perform incremental translations over time (i.e. lots of glRotated(small_angle_here, 1, 0, 0) and expect them to work properly. Due to precision problems, eventually the transformations will produce a matrix that does not perform the transformation it should at all.

You should keep track of a "net transformation" and apply it to a known base matrix each frame.