void Skeleton::_updateAnimation(float animation_time, int joint_idx , int anim_idx,glm::mat4 parent_transform) { Joint* j = &joint_tree_[joint_idx]; glm::mat4 node_transform = j->transform; if (anim_idx<j->num_of_pose) { const std::vector<JointPose>& sample = animations_[anim_idx].samples; int pose_idx = j->pose_id[anim_idx]; glm::quat Q; calcInterpolatedRotation(animation_time, sample[pose_idx], Q); glm::vec3 V; calcInterpolatedTranslation(animation_time, sample[pose_idx], V); glm::mat4 T = glm::translate(glm::mat4(1.0f), V); glm::mat4 R = glm::toMat4(Q); node_transform = T * R; } glm::mat4 world_transform = parent_transform*node_transform; if (j->effective_joint_id >= 0) this->animation_matrix_[j->effective_joint_id] = world_transform*effective_[j->effective_joint_id].offset; for (size_t i = 0; i != j->children_num; ++i) { _updateAnimation(animation_time, j->children_begin + i, anim_idx, world_transform); } }
void Mesh::recurseNodeHeirarchy(float _animationTime, const aiNode* _node, const ngl::Mat4& _parentTransform) { std::string name(_node->mName.data); const aiAnimation* animation = m_scene->mAnimations[0]; ngl::Mat4 nodeTransform=AIU::aiMatrix4x4ToNGLMat4(_node->mTransformation); const aiNodeAnim* nodeAnim = findNodeAnim(animation, name); if (nodeAnim) { // Interpolate scaling and generate scaling transformation matrix ngl::Vec3 scale=calcInterpolatedScaling(_animationTime, nodeAnim); ngl::Mat4 scaleMatrix; scaleMatrix.scale(scale.m_x, scale.m_y, scale.m_z); // Interpolate rotation and generate rotation transformation matrix ngl::Quaternion rotation=calcInterpolatedRotation( _animationTime, nodeAnim); ngl::Mat4 rotationMatrix = rotation.toMat4(); // Interpolate translation and generate translation transformation matrix ngl::Vec3 translation=calcInterpolatedPosition(_animationTime, nodeAnim); // Combine the above transformations nodeTransform = rotationMatrix*scaleMatrix; nodeTransform.m_30=translation.m_x; nodeTransform.m_31=translation.m_y; nodeTransform.m_32=translation.m_z; nodeTransform.transpose(); } ngl::Mat4 globalTransform = _parentTransform * nodeTransform; if (m_boneMapping.find(name) != m_boneMapping.end()) { unsigned int boneIndex = m_boneMapping[name]; m_boneInfo[boneIndex].finalTransformation = m_globalInverseTransform * globalTransform * m_boneInfo[boneIndex].boneOffset; } for (unsigned int i = 0 ; i < _node->mNumChildren ; ++i) { recurseNodeHeirarchy(_animationTime, _node->mChildren[i], globalTransform); } }