Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - frag-a

#1
Hi raft, After some head banging I got it working ;D
Solution is to transform all vectors to joint's local space and do the rotation from the bind pose.
Here is the code, maybe it's useful to someone else.


private static final void targetJoint(final SimpleVector targetTranslation, final SkeletonPose pose, int handleIndex, int parentIndex) {
final Skeleton skeleton = pose.getSkeleton();
final Joint handleJoint = skeleton.getJoint(handleIndex);
final Joint parentJoint = skeleton.getJoint(parentIndex);
final Matrix parentInverseBindPose = parentJoint.getInverseBindPose();
final Matrix parentBindPose = parentInverseBindPose.invert();

final SimpleVector parentVector = pose.getLocal(parentIndex).getTranslation();
final SimpleVector handleVector = pose.getLocal(handleIndex).getTranslation();
float distance = handleVector.distance(targetTranslation);
if (distance > 0.1) {
final SimpleVector targetVector = new SimpleVector(targetTranslation);
targetVector.matMul(parentInverseBindPose);
float angle = handleVector.calcAngle(targetVector);
if (Math.abs(angle) > 0.1f) {
final SimpleVector bindPoseVector = handleJoint.getBindPose().getTranslation();
bindPoseVector.matMul(parentInverseBindPose);

final Matrix rotation = new Quaternion().fromVectorToVector(bindPoseVector, targetVector).getRotationMatrix();
rotation.matMul(parentBindPose);
rotation.matMul(pose.getSkeleton().getJoint(parentJoint.getParentIndex()).getInverseBindPose());
pose.getLocal(parentIndex).setTo(rotation);
}
}
}


Corrected some bugs.
#2
Thanks, I'll take a look at your suggestions and do some more tries.
I'll put the code here if I can make it work.
#3
Hi raft, first of all thanks for this great lib. I'm playing around with some 3D game dev stuff, but I don't have much experience...yet :)
It was relatively easy to get into jpct and bones but I suck at math, so I wonder if you could help me here with this attempt to do some IK.
The goal is to have some character to grab or to point to some other object. The below code works fine if the rotation starts from the bind pose.
But if it's not from the bind pose, it just get crazy! Could you please help me figure out whats missing? Thanks in advance.


private static final void targetJoint(final SimpleVector targetTranslation, final SkeletonPose pose, int handleIndex, int parentIndex) {
final Skeleton skeleton = pose.getSkeleton();
final Joint handleJoint = skeleton.getJoint(handleIndex);
final Joint parentJoint = skeleton.getJoint(parentIndex);
final Matrix parentInverseBindPose = parentJoint.getInverseBindPose();
final Matrix parentBindPose = parentInverseBindPose.invert();

final SimpleVector handleTranslation = pose.getGlobal(handleIndex).getTranslation();
final SimpleVector parentTranslation = pose.getGlobal(parentIndex).getTranslation();

float distance = handleTranslation.distance(targetTranslation);
if (distance > 0.1) {
SimpleVector parentHandleVector = handleTranslation.calcSub(parentTranslation);
parentHandleVector = parentHandleVector.normalize();
parentHandleVector.rotate(parentInverseBindPose);

SimpleVector parentTargetVector = targetTranslation.calcSub(parentTranslation);
parentTargetVector = parentTargetVector.normalize();
parentTargetVector.rotate(parentInverseBindPose);

float angle = parentHandleVector.calcAngle(parentTargetVector);
if (Math.abs(angle) > 0.1f) {
Quaternion quat = new Quaternion().fromVectorToVector(parentHandleVector, parentTargetVector);
final Matrix rotation = quat.getRotationMatrix();
rotation.matMul(parentBindPose);
rotation.matMul(pose.getSkeleton().getJoint(parentJoint.getParentIndex()).getInverseBindPose());
pose.getLocal(parentIndex).setTo(rotation);
}
}
}