Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualuglybdavis

Posted 27 May 2013 - 07:54 AM

ALMOST THERE!

 

So, this works! Correct animation is playing, no swimming, looking good.

for (int i = 0; i < scene->mNumAnimations; ++i) {
        aiAnimation* animation = scene->mAnimations[i];
        for (int j = 0; j < animation->mNumChannels; ++j) {
            aiNodeAnim* channel = animation->mChannels[j];
            Joint& joint = m_vSkeleton[skeletonMap[channel->mNodeName.data]];
            Matrix localJoint = BuildMatrix(joint.Rotation(), joint.Translation());
            Matrix invLocal = localJoint.Inverse();
            Quaternion invQuat; invQuat.FromMatrix(invLocal);
            Quaternion localRot; localRot.FromMatrix(localJoint);
            
            for (int k = 0; k < channel->mNumRotationKeys; ++k) {
                aiQuatKey* rotationKey = &channel->mRotationKeys[k];
                joint.RotationTrack().push_back(RotationFrame());
                RotationFrame& frame = joint.RotationTrack()[joint.RotationTrack().size() - 1];
                frame.time = float(rotationKey->mTime);
                frame.rotation = Quaternion(rotationKey->mValue.w, rotationKey->mValue.x, rotationKey->mValue.y, rotationKey->mValue.z);
                
                frame.rotation = frame.rotation.Inverse() * invQuat;
            } // k
            for (int k = 0; k < channel->mNumPositionKeys; ++k) {
                aiVectorKey* positionKey = &(channel->mPositionKeys[k]);
                joint.TranslationTrack().push_back(TranslationFrame());
                TranslationFrame& frame = joint.TranslationTrack()[joint.TranslationTrack().size() - 1];
                frame.time = float(positionKey->mTime);
                frame.translation = Vector(positionKey->mValue.x, positionKey->mValue.y, positionKey->mValue.z);
                frame.translation.w = 1.0f;
                
                frame.translation = invLocal * frame.translation;
                frame.translation = localRot.ToMatrix() * frame.translation;

            } // k
        } // j
        totalDuration += float(animation->mDuration);
        numFrames += float(animation->mDuration * animation->mTicksPerSecond);
        playbackSpeed += float(animation->mTicksPerSecond);
    } // i

 

Problem is, there is a crazy ammount of jitter.  Anyone know a better way to go about this? Seems like the issue spawns somewhere in the rotation code....


#4uglybdavis

Posted 27 May 2013 - 06:49 AM

ALMOST THERE!

 

So, this works! Correct animation is playing, no swimming, looking good.

for (int i = 0; i < scene->mNumAnimations; ++i) {
        aiAnimation* animation = scene->mAnimations[i];
        for (int j = 0; j < animation->mNumChannels; ++j) {
            aiNodeAnim* channel = animation->mChannels[j];
            Joint& joint = m_vSkeleton[skeletonMap[channel->mNodeName.data]];
            Matrix localJoint = BuildMatrix(joint.Rotation(), joint.Translation());
            Matrix invLocal = localJoint.Inverse();
            Quaternion invQuat; invQuat.FromMatrix(invLocal);
            Quaternion localRot; localRot.FromMatrix(localJoint);
            
            for (int k = 0; k < channel->mNumRotationKeys; ++k) {
                aiQuatKey* rotationKey = &channel->mRotationKeys[k];
                joint.RotationTrack().push_back(RotationFrame());
                RotationFrame& frame = joint.RotationTrack()[joint.RotationTrack().size() - 1];
                frame.time = float(rotationKey->mTime);
                frame.rotation = Quaternion(rotationKey->mValue.w, rotationKey->mValue.x, rotationKey->mValue.y, rotationKey->mValue.z);
                
                frame.rotation = frame.rotation.Inverse() * invQuat;
            } // k
            for (int k = 0; k < channel->mNumPositionKeys; ++k) {
                aiVectorKey* positionKey = &(channel->mPositionKeys[k]);
                joint.TranslationTrack().push_back(TranslationFrame());
                TranslationFrame& frame = joint.TranslationTrack()[joint.TranslationTrack().size() - 1];
                frame.time = float(positionKey->mTime);
                frame.translation = Vector(positionKey->mValue.x, positionKey->mValue.y, positionKey->mValue.z);
                frame.translation.w = 1.0f;
                
                frame.translation = invLocal * frame.translation;
                frame.translation = localRot.ToMatrix() * frame.translation;

            } // k
        } // j
        totalDuration += float(animation->mDuration);
        numFrames += float(animation->mDuration * animation->mTicksPerSecond);
        playbackSpeed += float(animation->mTicksPerSecond);
    } // i

 

Problem is, there is a crazy ammount of jitter. The jitter seems to be introduced by frame.translation = localRot.ToMatrix() * frame.translation; which is needed to get rid of the swimming (basically undo the rotation of the inverse local matrix. Anyone know a better way to go about this? Seems like the issue spawns form the crazy amount of matrix to quaternions i'm doing....


#3uglybdavis

Posted 27 May 2013 - 06:36 AM

EDIT, posted something about matrix multipication that was not the issue.


#2uglybdavis

Posted 27 May 2013 - 06:22 AM

it looks like each joint is first being rotated, then translated... I'm not sure what to make of that....

It has something to do with the way i'm removing the joints position. (rotation appears to be ok)

 

for (int i = 0; i < scene->mNumAnimations; ++i) {
        aiAnimation* animation = scene->mAnimations[i];
        for (int j = 0; j < animation->mNumChannels; ++j) {
            aiNodeAnim* channel = animation->mChannels[j];
            Joint& joint = m_vSkeleton[skeletonMap[channel->mNodeName.data]];
            Matrix localJoint = BuildMatrix(joint.Rotation(), joint.Translation());
            Matrix invLocal = localJoint.Inverse();
            Quaternion invQuat; invQuat.FromMatrix(invLocal);
            
            // Changed back to seperate tracks
            for (int k = 0; k < channel->mNumRotationKeys; ++k) {
                aiQuatKey* rotationKey = &channel->mRotationKeys[k];
                joint.RotationTrack().push_back(RotationFrame());
                RotationFrame& frame = joint.RotationTrack()[joint.RotationTrack().size() - 1];
                frame.time = float(rotationKey->mTime);
                frame.rotation = Quaternion(rotationKey->mValue.w, rotationKey->mValue.x, rotationKey->mValue.y, rotationKey->mValue.z);
                
                frame.rotation = frame.rotation.Inverse() * invQuat;
            } // k
            for (int k = 0; k < channel->mNumPositionKeys; ++k) {
                aiVectorKey* positionKey = &(channel->mPositionKeys[k]);
                joint.TranslationTrack().push_back(TranslationFrame());
                TranslationFrame& frame = joint.TranslationTrack()[joint.TranslationTrack().size() - 1];
                frame.time = float(positionKey->mTime);
                frame.translation = Vector(positionKey->mValue.x, positionKey->mValue.y, positionKey->mValue.z);
                frame.translation.w = 1.0f;
                
                frame.translation = invLocal * frame.translation;
            } // k
        } // j
        totalDuration += float(animation->mDuration);
        numFrames += float(animation->mDuration * animation->mTicksPerSecond);
        playbackSpeed += float(animation->mTicksPerSecond);
    } // i

 

I'm having a hard time figuring out what tough... Maybe i've been staring at this too long...


#1uglybdavis

Posted 27 May 2013 - 06:11 AM

it looks like each joint is first being rotated, then translated... I'm not sure what to make of that....


PARTNERS