6
« on: March 22, 2013, 08:29:29 pm »
Hi raft,
I'm using JPCT-AE to display my ninja object on an Android phone. What I'm trying to do it to rotate different joints of the ninja. Because of the human structure people can rotate their neck around different axis (twist, bend, flexion and extension). But because all the rotations are with the same joint, I'm getting a weird problem. Once I have twisted the neck by some angle, and I'm trying to add some blending rotation the neck gets to it's original position and everything starts from scratch. I'm not sure what I'm doing wrong here, as I don't have a lot of experience in this field. Here is the section of performing rotation:
private void rotateJoint(SkeletonPose pose, int jointIndex, SimpleVector bindPoseDirection, float angle, final float targetStrength) {
final int parentIndex = pose.getSkeleton().getJoint(jointIndex).getParentIndex();
final Matrix jointInverseBindPose = pose.getSkeleton().getJoint(jointIndex).getInverseBindPose();
final Matrix jointBindPose = jointInverseBindPose.invert();
// Get a vector representing forward direction in neck space, use inverse to take from world -> neck space.
SimpleVector forwardDirection = new SimpleVector(bindPoseDirection);
forwardDirection.rotate(jointInverseBindPose);
// Calculate a rotation to go from one direction to the other and set that rotation on a blank transform.
Quaternion quat = new Quaternion();
quat.fromAngleAxis(angle, forwardDirection);
quat.slerp(Quaternion.IDENTITY, quat, targetStrength);
final Matrix subGlobal = quat.getRotationMatrix();
subGlobal.matMul(jointBindPose);
subGlobal.matMul(pose.getSkeleton().getJoint(parentIndex).getInverseBindPose());
// set that as the neck's transform
pose.getLocal(jointIndex).setTo(subGlobal);
}
Ani