Easy update problem..?

Apr 26, 2008 at 11:39 PM
Hello again,
I got a problem with my update method, herei s the code:


public void update(GameTime gameTime,Camera cam)
{
KeyboardState keyState = Keyboard.GetState();
if (currentSpeed > 0)
{
myPosition += (-Matrix.CreateTranslation(0, 0, currentSpeed)
* rotation).Translation;

}
if (keyState.IsKeyDown(Keys.Right))
{
rotation *=
Matrix.CreateFromAxisAngle(Vector3.Up, -MathHelper.Pi / 25.0f);

}
if (keyState.IsKeyDown(Keys.Left))
{
rotation *=
Matrix.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi / 25.0f);
}
UpdateState(gameTime);

animator.World = rotation * Matrix.CreateTranslation(myPosition);

foreach (ModelMesh mesh in animator.Model.Meshes)
foreach (BasicPaletteEffect effect in mesh.Effects)
effect.View = cam.view;

}

the funny thing is this method is working if i don't modify the animator.world matrix in the draw method, here is the draw method:

public void drawAnimated(Camera cam, GameTime gameTime)
{
Matrix[] transforms = new MatrixmyModel.Bones.Count;
myModel.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in myModel.Meshes)
{
foreach (Effect modelEffect in mesh.Effects)
{
if (modelEffect is BasicEffect)
{
BasicEffect basic = (BasicEffect)modelEffect;
basic.View = cam.view;
basic.Projection = cam.projection;
}
else if (modelEffect is BasicPaletteEffect)
{
BasicPaletteEffect palette = (BasicPaletteEffect)modelEffect;
palette.View = cam.view;
palette.Projection = cam.projection;
palette.World = transformsmesh.ParentBone.Index * myScale * myRotation * myTranslation;

}

}
animator.World = transformsmesh.ParentBone.Index * myScale * myRotation * myTranslation; <<<< if I don't add this line my model is moving, but it's unscaled and unrotated.
animator.Draw(gameTime);
}

}

the draw method is called before the update method, and also the valor inside the animator.world seems to modify when i call the update one, but still my model doesn't move,
I really can't find the problem, also if I think it must be quite easy,
I appreciate any help,
thank in advice,

Giulio
Apr 29, 2008 at 8:02 PM
Im getting lost as to what exactly is working here... but I can suggest a few things that are probably going to cause problems.

As far as drawing the model goes.. there is an animator.draw method so there is no reason to create your own, and in fact this probably wont allow you to use the actual animation structure defeating the point of using this library.

Before using the animator.draw method however, you should know that when its setup normally this library will automatically render the model, without any draw routine called. Personally I am using multiple passes so I need to be able to control when the model is drawn, so I need to get around this, but I would take the time to consider whether your application really requires this or not.

If you still want to draw it separately then you need to first set the animator.visible property to false, and then call the draw method. Remember that you are going to still have to setup all the effects before calling it .

One other thing to note is that you are currently using animator.world and effect.world. The first I believe is linked to the automatically drawn model, and the second linked to your own separate render. So there is some definite inconsistency to be dealt with there.