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 made a ModelBatch class that batches and draw rigged/unanimated and skinned/animated models. For now, BasicEffect is assigned to rigged models (XNA Model Processor) and SkinnedEffect is assigned to skinned models (Based on Microsoft's Skinned Model Sample). The problem occurs when setting the shaders parameters. In the RenderBatch() method, I wrote:

...
foreach (Effect effect in mesh.Effects)
{
    if (effect is BasicEffect) // if it's a rigged model.
    {        
        effect.Parameters["WorldViewProj"].SetValue(modelInfo.world * viewProjection);
    }

    else // it's a skinned model.
    {              
        effect.Parameters["WorldViewProj"].SetValue(viewProjection);
        effect.Parameters["Bones"].SetValue(modelInfo.boneTransforms);
    }
}
...

When running the game, the rigged model's position is locked to the camera position for the first few frames. Afterwards, everything works perfectly (the rigged model position's is correct). The skinned model doesn't have that position displacement problem at runtime even if I only set the "WorldViewProj" parameter (so it's not because of the "Bones" parameter).

In order to work perfectly, I had to changed the rigged model part to:

    if (effect is BasicEffect) // if it's a rigged model.
    {        
        BasicEffect basicEffect = effect as BasicEffect;

        basicEffect.World = modelInfo.world;
        basicEffect.View = this.camera.View;
        basicEffect.Projection = this.camera.Projection;
    }

This way, the rigged model is instantly placed at the right place, but I don't like it. Also, what is really stange is that if I do not set any view or projection for the rigged model, like this:

    if (effect is BasicEffect) // if it's a rigged model.
    {        
        // do nothing.
    }

I will still see the rigged model locked to the camera's position. Anyone knows why setting "WorldViewProj" parameter of a SkinnedEffect works perfectly, but not for a BasicEffect?

I hope there's enough informations and thank you for answering!

* EDIT ANSWERED **

I found the source of the problem. The scale and rotation of the rigged model were changed in the content processor options, so the model was modified at runtime. I changed those options back to their default values and set the rotation and scale in the code instead (Matrix.CreateScale and Matrix.CreateRotationX) and the model was at the right place. Hence, I think that changing the model world information at runtime created the displacement lag.

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.