For our demo, we will be making a very simple camera that follows behind the dwarf.
  • Add these member variables:
    // Add these as member variables
    // This stores the cameras position relative to the dwarf
    Vector3 camOffset = new Vector3(0, 15, -20);
    Vector3 dwarfPosition = Vector3.Zero;
    Matrix rotation = Matrix.Identity;
  • In the Update method, update the dwarf's world matrix and the view matrix so that the camera is looking at the dwarf and offset by camOffset:
    // Add this to the Update method
    dwarfAnimator.World = rotation * Matrix.CreateTranslation(dwarfPosition);
    view = Matrix.CreateLookAt(
         dwarfAnimator.World.Translation+camOffset,
         dwarfAnimator.World.Translation,
         Vector3.Up);
  • Also in the Update method, update the effects for both models:
    // Add this to the Update method
    foreach (ModelMesh mesh in dwarfAnimator.Model.Meshes)
        foreach (BasicPaletteEffect effect in mesh.Effects)
            effect.View = view;

    foreach (ModelMesh mesh in ground.Model.Meshes)
        foreach (BasicEffect effect in mesh.Effects)
            effect.View = view;

Last edited Mar 7, 2007 at 9:50 PM by dastle, version 6

Comments

No comments yet.