foofel

Hi, i have been playing around with spine but cant figure out a reliable way to point a bone at the mouse cursor.

I have a test file that works http://i.imgur.com/urvsFGr.png, and one that doesn't http://i.imgur.com/4zKplbN.png (I am only trying to rotate the blue bar). The only difference are the bones below the one i want to rotate. It looks like setting the rotate needs to take into account the bones below but i cant find a way to do that.

What i want to do:
spBone *leftArm = spSkeleton_findBone(skeleton, "l_shoulder");
// point direction is the vector from our bone position to the mouse cursor
float rot = atan2(pointDirection.y, pointDirection.x) * math::TO_DEG;
// what to take into account? (actually for the "working" example i need to subtract 90 degreeds)
leftArm->rotation = rot;
Any ideas on how to make it work? :)
foofel
  • Сообщения: 13

Nate

l_shoulder inherits the rotation of the parent bone, recursively to the root. Try rot minus the world rotation of the parent bone. Or, try setting inheritRotation to false on the l_shoulder bone.
Аватара пользователя
Nate

Nate
  • Сообщения: 9766

janko

Similar question, wy this code dont rotate bone, commented code with modifying data->rotation does but if i understand data stores default vaules which are used for reset.
Using cocos2d-x.
spBone *hip;
hip = skeletonNode->findBone("hip");
//hip->data->rotation += 2;
hip->rotation += 2;
janko
  • Сообщения: 9

Nate

Probably you apply an animation, which overwrites the local SRT. Animations are relative to the setup pose SRT, so when you modify the BoneData your changes aren't overwritten. Be sure to adjust your local SRT after applying an animation, before you call updateWorldTransform.
Аватара пользователя
Nate

Nate
  • Сообщения: 9766

foofel

Nate писал(а):l_shoulder inherits the rotation of the parent bone, recursively to the root. Try rot minus the world rotation of the parent bone. Or, try setting inheritRotation to false on the l_shoulder bone.
subtracting the parents world rotation works, thanks :)
foofel
  • Сообщения: 13


Вернуться в Runtimes