XNA Creators Club Online
Page 1 of 1 (11 items)
Sort Posts: Previous Next

3d skinned model doesnt rotate on spot!!!!

Last post 7/7/2009 7:24 AM by Lintford Pickle. 10 replies.
  • 3/25/2009 9:14 PM

    3d skinned model doesnt rotate on spot!!!!

    hi,

    im in great need to know how to make the 3d skinned model in xna to rotate i have added

    float rotation = 45.0f;


     then in update section:

    if(keyboardstate.iskeyUp(keys.m) && lastkeyboardstate.iskeydown(keys.m))
    {
      rotation =+ 1.0f;
    }


     then in the skinnedmodel drawer added this to the end of the 'effect' line which is also were i added the position movement and works fine:

    matrix.createrotation.Y(rotation);

    but all i get is the model going around in a big circle around the arena i just want it to rotate on spot!

    any suggestions???

    thank you
  • 3/25/2009 9:37 PM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    Classic problem, normally you have to center the model inside your 3d program (MAX, Maya, blender or whatever) on the center of the grid (0,0,0).
  • 3/26/2009 9:03 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    hi,

    Poya Shohani:
    then in the skinnedmodel drawer added this to the end of the 'effect' line which is also were i added the position movement and works fine:

    matrix.createrotation.Y(rotation);


    actually I think the problem is that you need to apply the rotation to the model world matrix BEFORE you apply the translation.  Otherwise, like you said, you will be rotating the model and the translation.

    I believe this is the 'general purpose' world matrix structure,

    Matrix world = Parent.World * Matrix.CreateScale(1.0f) * Matrix.CreateRotationY(0.0f) * Matrix.CreateTranslation(Vector3.Zero); 


    hope it helps :)

    -John
  • 3/29/2009 5:32 PM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    i tried that already and still no luck,

    i have already added:

    effect.World = Matrix.CreateScale(25.0f) * Matrix.CreateTranslation(anim.Position)* Matrix.CreateRotationY(rotation);
                       
    thats the line i use.

  • 3/29/2009 5:45 PM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    hi again,

    Poya Shohani:
    effect.World = Matrix.CreateScale(25.0f) * Matrix.CreateTranslation(anim.Position)* Matrix.CreateRotationY(rotation);
                       
    thats the line i use.


    just to be sure, I meant the rotation should come before the translate part in the worl matrix... like this:

    effect.World = Matrix.CreateScale(25.0f) * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(anim.Position);


  • 4/1/2009 12:25 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    thank you so much, it actually workd fine after i changed the order around :)

    thank you again
  • 4/1/2009 10:26 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

  • 7/6/2009 7:40 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    Hi Guys, I have another problem on translation. In the skinning model, it uses customer effect for the skin/bone transformations. So we can not use the BasicEffect, right? the problem is I cant find the World parameter in the effect.  I have already solved the problem by multiplying the world martix to transformed bones matrix arrary (this works fine).  But my question is does the sample not support world transforms by default or I am overlooking something.

    Another efficient way I can think of is to add a parameter myself in the Skinnigneffect.fx myself for better performance.

    Update: Found another thread on the issue
    The world transformation is already done in the AnimationClip.Update method. So if we multiply the world matrix in the draw call it will be redundant. See thread below
    http://forums.xna.com/forums/p/10307/54041.aspx#54041

    But I think moving it to .fx file would still be more efficient.
  • 7/6/2009 9:12 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    hi Xia,

    Xia:
    But my question is does the sample not support world transforms by default or I am overlooking something.


    It's not a question of the effect 'not supporting' the world matrix, because matrices are just variables.  But no, the skinning sample does not have a world matrix by default in the shader, but there's no reason why you can't add this your self should you need it.

    You can add as many matrices to the shader as you want/need (keeping within the limits of each shader models instruction/register count), but what is important is how you multiply them together, because each matrix will change the final position of the vertices.  Also, each extra matrix calculation will have a slight overhead.

    you will need to add to the shader in the following order:

    bone * world * view * projection.


    Xia:
    The world transformation is already done in the AnimationClip.Update method. So if we multiply the world matrix in the draw call it will be redundant. See thread below
    http://forums.xna.com/forums/p/10307/54041.aspx#54041

    But I think moving it to .fx file would still be more efficient.


    I haven't read the other thread (no time), but I think his is more a question of project organisation and structure.  The difference in computing a few matrices on the CPU or GPU is probably so little it would be slower sending them to the GPU all in the first place (I can't back this up, but it's just a feeling).  And it wouldn't make sense sending a full scenegraph's worth of matrices to the GPU to try and save time multiplying them together.  So I think calculating the world matrices in the Update() should be fine.

    hope it helps,

    John

  • 7/7/2009 4:07 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    Lintford Pickle:
    Thanks for the input but I think you didnt read my post completely. I mentioned that I have already added the world matrix multiplication and it is working fine. The reason I asked was to see if that is already implemented in the sample and if I am duplicating the multiplication part (as I thought it is bit strange if the sample doesnt considtion the translation).
    Later I found out that it was already implemented in the sample under AnimationPlayer.Update(), all I needed to do was pass on the rotation/translation matrix. I know there could be number of ways to do it but just wanted to make sure that there is no duplicate computations that would degrade the performance.
  • 7/7/2009 7:24 AM In reply to

    Re: 3d skinned model doesnt rotate on spot!!!!

    hi Xia,

    Ok I get what you mean.  But whther or not you calculate the world matrix in the amination.update(), the draw() or within the shader is up to you.  It is just a variable.  I don't have the animationSample source with me, but I'm pretty so I caluculated the world matrices and added them the the effect myself.

    -John
Page 1 of 1 (11 items) Previous Next