I have collada (dae) model created in blender. I load the dae file using assimp and display it using opengl in c++. The model displays correctly (image below).
The sceleton has following structre:
root, id: 0
Armature, id: 2
Armature_SPINE_NAVAL, id: 3
Armature_SPINE_CHEST, id: 4
Armature_NECK, id: 5
Armature_HEAD, id: 6
Armature_NOSE, id: 7
Armature_CLAVICLE_RIGHT, id: 8
Armature_SHOULDER_RIGHT, id: 9
Armature_ELBOW_RIGHT, id: 10
Armature_WRIST_RIGHT, id: 11
Armature_HAND_RIGHT, id: 12
Armature_HANDTIP_RIGHT, id: 13
Armature_THUMB_RIGHT, id: 14
Armature_CLAVICLE_LEFT, id: 15
Armature_SHOULDER_LEFT, id: 16
Armature_ELBOW_LEFT, id: 17
Armature_WRIST_LEFT, id: 18
Armature_HAND_LEFT, id: 19
Armature_HANDTIP_LEFT, id: 20
Armature_THUMB_LEFT, id: 21
Armature_HIP_RIGHT, id: 22
Armature_KNEE_RIGHT, id: 23
Armature_ANKLE_RIGHT, id: 24
Armature_FOOT_RIGHT, id: 25
Armature_HIP_LEFT, id: 26
Armature_KNEE_LEFT, id: 27
Armature_ANKLE_LEFT, id: 28
Armature_FOOT_LEFT, id: 29
I want to apply rotation to a single bone. However after applying rotation of 90 degrees around z axis to the Armature_WRIST_RIGHT, the bone arm gets streached. Below is my code. What I'm doing wrong?
void CalculateBoneTransform(Bone* bone, glm::mat4 parentTransform)
{
std::string boneName = bone->GetBoneName();
glm::mat4 boneTransform = bone->GetLocalTransform(); // aiNode->mTransformation
if(boneName == "Armature_WRIST_RIGHT"){
float RotationAngle = 1.5708;
float x = 0 * sin(RotationAngle / 2); // x * sin()
float y = 0 * sin(RotationAngle / 2); // y * sin()
float z = 1 * sin(RotationAngle / 2); // z * sin()
float w = cos(RotationAngle / 2);
glm::quat rot(w,x,y,z);
boneTransform *= glm::toMat4(rot);
}
glm::mat4 globalTransformation = parentTransform * boneTransform;
if (m_BoneInfoMap.find(boneName) != m_BoneInfoMap.end())
{
int index = m_BoneInfoMap[boneName].id;
glm::mat4 offset = m_BoneInfoMap[boneName].offset; // mesh->mBones[boneIndex]->mOffsetMatrix
m_FinalBoneMatrices[index] = globalTransformation * offset * glm::scale(glm::vec3(0.2f,0.2f,0.2f));
}
for (Bone* j : bone->getChildren())
CalculateBoneTransform(j, globalTransformation);
}
Above is my code. What I'm doing wrong? How should I apply the rotation transform to correctly rotate chosen bones?