# Invalid bone transformations in skinned mesh

This topic is 1351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all

I am using skinned meshes with hierarchical bones in my application. Strangely i get rather mixed results for different models. The problem right now is that i am not sure if i am reading the values wrong or doing the math wrong. Let me first show you 2 different videos of different models:

N°1:

https://www.dropbox.com/s/n6r7wzyfxdw20rl/2014-10-11_17-49-35.mp4?dl=0

As you can see it doesnt look that bad, yet there are strange bumps in the animation and the character seems to be moving up and down as well.

N°2:

https://www.dropbox.com/s/qgn785i5x7y1jhn/2014-10-11_17-50-59.mp4?dl=0

For this nice fella however the animations seem to completely wrong...

The main code i am using to calculate my matrices looks like that:

void M2AnimationBone::updateMatrix(uint32 time, uint32 animation, Math::Matrix& matrix, M2Animator* animator) {
auto position = mTranslation.getValueForTime(animation, time, animator->getAnimationLength());
auto scaling = mScaling.getValueForTime(animation, time, animator->getAnimationLength());
auto rotQuat = mRotation.getValueForTime(animation, time, animator->getAnimationLength());

matrix = mPivot * Math::Matrix::translation(position) * Math::Matrix::rotationQuaternion(rotQuat) * Math::Matrix::scale(scaling) * mInvPivot;

if (mBone.parentBone >= 0) {
matrix = matrix * animator->getMatrix(time, mBone.parentBone);
}
}


With getMatrix like this:

const Math::Matrix& M2Animator::getMatrix(uint32 time, int16 matrix) {
assert(matrix >= 0 && (uint32) matrix < mBones.size());

if (mCalculated[matrix]) {
return mMatrices[matrix];
}

auto& mat = mMatrices[matrix];
mBones[matrix]->updateMatrix(time, mAnimationId, mat, this);
mCalculated[matrix] = true;

return mat;
}


Ive been looking through several tutorials and explanations online and found - in my opinion - several different versions of it. Mostly it seems that the whole pivot stuff is a bit different everywhere. Am i doing it the right way?

Thanks for any help

Plerion

##### Share on other sites

Hello all

Its me again! It was a combination of two problems:
1. matrix = matrix * animator->getMatrix(time, mBone.parentBone);

This has to be parent * matrix and not matrix * parent since i first want to transform by my local matrix and then apply the parents transformation!

2. The rotation values were wrong. I had to conjugate the quaternion with the rotation.

Now it all works fine.

Greetings

Plerion

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×