You could change the attachment offset, but keep in mind that attachments are stateless and shared across all skeleton instances.
I don't quite understand why you change the attachment rotation. Also, your rotation subtraction may not work if your bones have nonuniform scale. In that case the bone's coordinate system is squashed in one direction, eg when rotated 360 degrees the bone's tip will trace an ellipse, not a circle. If you don't use nonuniform scale then subtraction is fine.
Do you need to set the bone's local rotation? It may be easiest to adjust the world rotation directly:
spBone_rotateWorld(bone, desiredWorldRotation - bone->worldRotation);
You'd have to do that after updateWorldTransform
though, which means child bones won't be affected. In fact, if the physics bodies specify the transform for every bone, you don't even need to call updateWorldTransform
. Instead you could just set the a, b, c, d, worldX, worldY
for every bone. They are const since this isn't something you normally do, though maybe we should un-const them. You can set them like this:
CONST_CAST(float, bone->a) = 123;
The center of a region attachment is the region attachment x, y
, which is in the attachment's bone's local coordinates. If you want the region attachment center in world coordinates:
float centerX, centerY;
spBone_localToWorld(bone, regionAttachment->x, regionAttachment->y, ¢erX, ¢erY);
I'm not sure exactly what you are doing, but it may be helpful to show how to set a bone's local x, y
to a desired world position. A bone is positioned in its parent bone's coordinates, so:
float localX, localY;
spBone_worldToLocal(bone->parent, desiredWorldX, desiredWorldY, &localX, &localY);
bone->x = localX;
bone->y = localY;