Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a person model that is animated and a suitcase model that is not. The person can pick up the suitcase and it should move to the location of the hand bone of the person model. Unfortunately the suitcase doesn't follow the animation correctly. it moves with the hand's animation but its position is under the ground and way too far to the right. I haven't scaled any of the models myself. Thank you. The source code (forgive the rough prototype code):

        Matrix[] tran = new Matrix[man.model.Bones.Count];// The absolute transforms from the animation player
        man.model.CopyAbsoluteBoneTransformsTo(tran);

        Vector3 suitcasePos, suitcaseScale, tempSuitcasePos = new Vector3();// Place holders for the Matrix Decompose
        Quaternion suitcaseRot = new Quaternion();

        // The transformation of the right hand bone is decomposed
        tran[man.model.Bones["HPF_RightHand"].Index].Decompose(out suitcaseScale, out suitcaseRot, out tempSuitcasePos);

        suitcasePos = new Vector3();
        suitcasePos.X = tempSuitcasePos.Z;// The axes are inverted for some reason
        suitcasePos.Y = -tempSuitcasePos.Y;
        suitcasePos.Z = -tempSuitcasePos.X;

        suitcase.Position = man.Position + suitcasePos;// The actual Suitcase properties
        suitcase.Rotation = man.Rotation + new Vector3(suitcaseRot.X, suitcaseRot.Y, suitcaseRot.Z);

I am also copying the bone transforms from the animation player in the Person class like so:

        // The transformations from the AnimationPlayer
        Matrix[] skinTrans = new Matrix[model.Bones.Count];
        skinTrans = player.GetBoneTransforms();

        // copy each transformation to its corresponding bone
        for (int i = 0; i < skinTrans.Length; i++)
        {
            model.Bones[i].Transform = skinTrans[i];
        }

EDIT:

Unfortunately I can't add screenshots, as this specific project has been lost to time. I still want to know why it didn't work, though.

share|improve this question
    
I still haven't been able to make this work... D: :'( –  annonymously Dec 23 '11 at 0:34
    
I've added a 100-rep bounty for your question. Please dispense it wisely. And please add a screenshot. –  ashes999 Feb 29 '12 at 3:03
    
So the accepted answer solved the problem? –  ashes999 Mar 4 '12 at 4:16
add comment

1 Answer 1

up vote 0 down vote accepted
+100

My initial guess was that CopyAbsoluteBoneTransforms gave you the bone's position in world coordinates instead of model coordinates, but that would only be true if you moved the model by modifying the transform of the root bone. (Not entirely sure how animation is done in XNA)

Something else to note is that you're taking the XYZ components of a quaternion and using them in a vector3 (that I'm assuming is a euler angle), which doesn't work as you would expect.

share|improve this answer
    
My guess is also the Quaternion usage, X Y Z W are not normal coordinates, try this for converting a Quaternion to a Matrix4x4 and then to a Vector3 (Unity code but idea should be similar) answers.unity3d.com/questions/11363/… –  Roy T. Feb 29 '12 at 11:10
    
So this solved the problem? @annonymously –  ashes999 Mar 4 '12 at 4:16
    
@ashes999 I stored the rotation in a Quaternion wherever I used a Vector3 and it worked. –  annonymously Mar 4 '12 at 6:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.