May 13, 2009, 11:43 PM

I'd like to continue this discussion after being scolded in the "How to handle entity rendering" thread for using quaternions to handle rotations in 2D.

First, I totally understand the objections and the fact that quaternions are overkill for 2D, but as worked to replace my rotation handling with scalar angles I ran into a major problem with interpolation. Here's a quote from the originating thread:

Au contraire! The problem is that angles going from -Ï€ to Ï€ (or 0 to Ï€.2 depending on your preference) can't simply be linearly interpolated when tweening. You need to find the shortest path and adjust the angles to compensate. Even when I thought I had this working I got bad artifacts, and the code was horribly ugly.

After my frustrations with scalar angles I came up with an interim solution: Use a half-quaternion (I'm making up words again, there's probably a real name for this - complex? spinor?) Anyway, I just took my quaternion code and cut it down to the Z and W components, since X and Y were always zero in the 2D cases. The math is greatly simplified, and the interpolation automagically picks the best/shortest path just like a quaternion.

So, anyone care to share a decent scalar angle interpolation function? Or should I just be happy with the half-quaternion deal I got going?

First, I totally understand the objections and the fact that quaternions are overkill for 2D, but as worked to replace my rotation handling with scalar angles I ran into a major problem with interpolation. Here's a quote from the originating thread:

warmi Wrote:If you are dealing with 2d then there is no interpolation problem whatsoever ...

Au contraire! The problem is that angles going from -Ï€ to Ï€ (or 0 to Ï€.2 depending on your preference) can't simply be linearly interpolated when tweening. You need to find the shortest path and adjust the angles to compensate. Even when I thought I had this working I got bad artifacts, and the code was horribly ugly.

After my frustrations with scalar angles I came up with an interim solution: Use a half-quaternion (I'm making up words again, there's probably a real name for this - complex? spinor?) Anyway, I just took my quaternion code and cut it down to the Z and W components, since X and Y were always zero in the 2D cases. The math is greatly simplified, and the interpolation automagically picks the best/shortest path just like a quaternion.

So, anyone care to share a decent scalar angle interpolation function? Or should I just be happy with the half-quaternion deal I got going?