I have a method that calculates the angle a bone should be rotated when the user clicks and drags the bone around. This worked fine until I updated Spine last week (I think, did not test it until now). The method in my listener looks like this:
/**Returns the angle to move the Gun part.*/
private float getAngleToMove( float centerX, float centerY, float previousX, float previousY, float currentX, float currentY ){
float angle = calculateAngleToMove(centerX, centerY, previousX, previousY, currentX, currentY);
float crossProduct = calculateCrossProduct(centerX, centerY, previousX, previousY, currentX, currentY);
/*Counter-clockwise move*/
if ( crossProduct <= 0 )
return -angle;
/*Clockwise move*/
else
return angle;
}
where
private float calculateAngleToMove(float centerX, float centerY, float previousX, float previousY, float currentX, float currentY){
float a_squared = (centerX - previousX)*(centerX - previousX) +
(centerY - previousY)*(centerY - previousY);
float b_squared = (centerX - currentX)*(centerX - currentX) +
(centerY - currentY)*(centerY - currentY);
float c_squared = (currentX - previousX)*(currentX - previousX) +
(currentY - previousY)*(currentY - previousY);
return (float) (Math.acos((c_squared - a_squared - b_squared) / (-2 * Math.sqrt(a_squared * b_squared))) * 180.0f / Math.PI);
}
private float calculateCrossProduct(float centerX, float centerY, float previousX, float previousY, float currentX, float currentY){
return ( previousX - centerX ) * ( currentY - centerY ) - ( currentX - centerX ) * ( previousY - centerY );
}
I invoke the method like this:
float angleToMove = getAngleToMove(target.getGunBone().getWorldX(), target.getGunBone().getWorldY(), previousX, previousY, event.getStageX(), event.getStageY());
I believe the error is in the getWorldX() and getWorldY(). This is the location of the bone that it should be rotated around, but it looks like they return way to small values. Any pointers on how to fix this issue?