Animation Rotation Complication

furballphat
Unregistered
 
Post: #1
Hi. I've been coding a simple animation system for OpenGL. It works by taking the rotation, translation, etc. for each key frame and interpolating (is that the right word) them over a set delay. I have absolutely no problems with translation and scaling, they work as expected.

My difficulty lies in rotation. If I tell it to rotate from 0 to 90 degrees, it will do this correctly. The same is true for any other numbers less than 360. The problem is, I would like it to realise that 0 and 360 are the same angle, and as such no movement is needed to change between the two. At current there is no way to do a full rotation, sending it from 360 to 0 will just make it quickly flip all the way back round.

Does anyone have any suggestions for a way to make this work? Any help would be appreciated.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #2
Just make sure that it never goes 360 degrees.

if (angle >= 360) angle -= 360;
Quote this message in a reply
furballphat
Unregistered
 
Post: #3
Hey - thanks. I'd thought about doing something like that for ages, but I've only just realised where to put that code. It all works beautifully now.
Quote this message in a reply
sh4ggy87
Unregistered
 
Post: #4
If your angle is an integer then you can also do:

[SOURCECODE]angle %= 360;[/SOURCECODE]

This will make sure 0 <= angle < 360.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #5
Woah, that's neat. I need to learn these little C tricks.
Quote this message in a reply
Post Reply