Author Topic: getBindPose() is Late  (Read 22674 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
getBindPose() is Late
« on: July 07, 2018, 08:32:52 pm »
Can I forcefully update it in order to have an item keep up with my character's hand?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: getBindPose() is Late
« Reply #1 on: July 08, 2018, 11:39:19 pm »
My next best attempt was this (but it doesn't look quite right):

Code: [Select]
weapon.getRotationMatrix().interpolate(weapon.getRotationMatrix(), skeletonPose.getLocal(rightHandIndex), 1f);
weapon.getRotationMatrix().matMul(model.get(0).getWorldTransformation());

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: getBindPose() is Late
« Reply #2 on: July 10, 2018, 11:44:19 pm »
Yet another attempt. This is based off of SkeletonDebugger. It's still not quite right:

Code: [Select]
     private void updateWeaponPos() {
SimpleVector o = weapon.getTransformedCenter();
SimpleVector d = getJointPosition(rightHand);
SimpleVector left = model.get(0).getXAxis();
weapon.translate(d.x-o.x, d.y-o.y+.1f, d.z-o.z);//d.x-o.x, d.y-o.y+.125f, d.z-o.z

//NOW ROTATION:
Skeleton skeleton = model.get(0).getSkeleton();

final int parentIndex = skeleton.getJoint(rightHandIndex).getParentIndex();
if (parentIndex != Joint.NO_PARENT) {
     Object3D bone = weapon;
     updateWeapon(bone, skeletonPose.getGlobal(parentIndex), skeletonPose.getGlobal(rightHandIndex));
}
     }
     private void updateWeapon(Object3D weapon, final Matrix start, final Matrix end) {
SimpleVector from = start.getTranslation();
SimpleVector to = end.getTranslation();
SimpleVector direction = to.calcSub(from);

weapon.getRotationMatrix().setTo(direction.getRotationMatrix());
weapon.rotateY((float)Math.PI+rotY);//rotY IS SO THAT THE WEAPON ROTATES ALONG WITH model.getRoot()
weapon.rotateAxis(weapon.getZAxis(), (float)Math.PI*.2f);
     }

Notes:
-Adding the weapon to the root of the character breaks the whole thing.
-I'm having to rotate the weapon by the same amount as the root because it otherwise doesn't chase the hand.
-It kind of looks right until you look straight at the hand and you see that the weapon is not facing the right direction during any given animation