I’ve a difficulty with calculating transformation matrices for animation mesh deformation utilizing glm in c++
I’ve a category Bone which does the fundamental calculation which does have a present native place (vec3) and native roation (quaternion) and in addition the bind native place and rotation.
After loading the skeleton i name the next technique for the foundation bone:
void Bone::calculateBindTransform(glm::mat4 parentBindTransform) {
_localBindTransform = glm::translate(_localBindTransform, getStartPosition());
_localBindTransform *= glm::mat4_cast(getStartQuaternion());
_bindTransform = glm::translate(parentBindTransform, getStartPosition());
_bindTransform *= glm::mat4_cast(getStartQuaternion());
_inverseBindTransform = glm::inverse(_bindTransform);
for(auto &little one: getChildren()) {
child->calculateBindTransform(_bindTransform);
}
}
Than I’ve the next technique to calculate the mannequin house remodel of the present bone state:
glm::mat4 Bone::getTransform() const {
glm::mat4 remodel{1.0f};
auto mother or father = getParent().lock();
if(mother or father) {
remodel = parent->getTransform();
}
remodel = glm::translate(remodel, getPosition());
remodel *= glm::mat4_cast(getQuaternion());
return remodel;
}
For debugging I at the moment render cubes for each bone utilizing the remodel, that works positive and the skeleton appears the way it’s suppose to look.
At the moment I might move to the shader the next matrix for each bone: getTransform() * _inverseBindTransform
. However as quickly as I transfer a single bone out of the bind pose the mesh will get completely destroyed.
To check if that works I modified the rendering of the debug cubes to the next remodel _bindTransform * getTransform() * _inverseBindTransform
which I anticipated to work however the skeleton than breaks as quickly as I alter the foundation bone too.
That is how the debug cubes appear to be with the bind pose: https://imgur.com/a/XLSVJNC
However once I change the foundation bone’s y to 50 as a substitute of 0 the skeleton kinda explodes: https://imgur.com/a/omCB5Es
I suppose I’ve a logic drawback someplace however I am too blind to see it