//This is the code that is used to calculate the new vertex positions //based on the current frame and bone datavoid //Authored by Chris McKee and Kevin Ubay-Ubay SkinMesh::calcInterpolatedPosition(aiVector3D& Out, float AnimationTime, const aiNodeAnim* pNodeAnim) { if (pNodeAnim->mNumPositionKeys == 1) { Out = pNodeAnim->mPositionKeys[0].mValue; return; } unsigned int PositionIndex = findPosition(AnimationTime, pNodeAnim); unsigned int NextPositionIndex = (PositionIndex + 1); float DeltaTime = pNodeAnim->mPositionKeys[NextPositionIndex].mTime - pNodeAnim->mPositionKeys[PositionIndex].mTime; float Factor = (AnimationTime - (float)pNodeAnim->mPositionKeys[PositionIndex].mTime) / DeltaTime; const aiVector3D& Start = pNodeAnim->mPositionKeys[PositionIndex].mValue; const aiVector3D& End = pNodeAnim->mPositionKeys[NextPositionIndex].mValue; aiVector3D Delta = End - Start; Out = Start + Factor * Delta; } void SkinMesh::calcInterpolatedRotation(aiQuaternion& Out, float AnimationTime, const aiNodeAnim* pNodeAnim) { if (pNodeAnim->mNumRotationKeys == 1) { Out = pNodeAnim->mRotationKeys[0].mValue; return; } unsigned int RotationIndex = findRotation(AnimationTime, pNodeAnim); unsigned int NextRotationIndex = (RotationIndex + 1); float DeltaTime = pNodeAnim->mRotationKeys[NextRotationIndex].mTime - pNodeAnim->mRotationKeys[RotationIndex].mTime; float Factor = (AnimationTime - (float)pNodeAnim->mRotationKeys[RotationIndex].mTime) / DeltaTime; const aiQuaternion& StartRotationQ = pNodeAnim->mRotationKeys[RotationIndex].mValue; const aiQuaternion& EndRotationQ = pNodeAnim->mRotationKeys[NextRotationIndex].mValue; aiQuaternion::Interpolate(Out, StartRotationQ, EndRotationQ, Factor); Out = Out.Normalize(); } }