float r = frames[frame + ROTATION] - prevRotation;
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
r = prevRotation + r * percent;
if (setupPose) {
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
bone.rotation = bone.data.rotation + r * alpha;
} else {
r = bone.data.rotation + r - bone.rotation;
r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360;
bone.rotation += r * alpha;
}
After some time with my boss, scratching our heads, this is pretty neat code for wrapping angles!
although... :punch:
I feel less happy about our solution to clamping the angles after alpha.
We had a problem long ago, where because of increasing bone rotations, and turning IK's on and off, Bones controlled by IK's would spine around when turning the IK on. This is due to the, bone.rotation += r * alpha as if bone.rotation = 179 and r = 180 and alpha = 1, bone.rotation can increase past the -180, 180 limits.
To stop this we did the following code at the end of the apply function in rotation timeline:
//ADDED
float amount = bone.rotation;
while (amount > 180)
amount -= 360;
while (amount < -180)
amount += 360;
bone.rotation = amount;
//ADDED
which would wrap the rotation of the bone again.
above code still works, but I'm unsure of the maths to put it in your new fancy calculation.
I thought it might be something like:
bone.rotation -= (16384 - (int)(16384.499999999996 - bone.rotation / 360)) * 360;
is this correct (its a little hard to see if it is)
[/i]
17 Nov 2016, 12:30
(and that 16384.499999999996 really needs to be defined, because people reading this in a chat room where I posted it are yelling at me)