title: How do I rotate meshes around their local axes in XNA?
body: <p>I have an object in my game that has a few meshes and when I try to rotate either of the meshes either way, it only rotates it around world axis, and not its local axis. I have a <code>rotation = Matrix.Identity</code> in a class constructor. Every mesh has this class attached to it. Then this class also contains methods:</p>
  
  <pre><code>...
  public Matrix Transform{ get; set; }
  public void Rotate(Vector3 newRot)
  {
      rotation = Matrix.Identity;
      rotation *= Matrix.CreateFromAxisAngle(rotation.Up, MathHelper.ToRadians(newRot.X));
      rotation *= Matrix.CreateFromAxisAngle(rotation.Right, MathHelper.ToRadians(newRot.Y));
      rotation *= Matrix.CreateFromAxisAngle(rotation.Forward, MathHelper.ToRadians(newRot.Z));
  
      CreateMatrix();
  }
  
  private void CreateMatrix()
  {
      Transform = Matrix.CreateScale(scale) * rotation * Matrix.CreateTranslation(Position);
  }
  ...
  </code></pre>
  
  <p>And now the Draw() method:</p>
  
  <pre><code>foreach (MeshProperties mesh in model.meshes)
  {
      foreach (BasicEffect effect in mesh.Mesh.Effects)//Where Mesh is a ModelMesh that this class contains information about
      {
          effect.View = cam.view;
          effect.Projection = cam.projection;
          effect.World = mesh.Transform;
          effect.EnableDefaultLighting();
      }
      mesh.Mesh.Draw();
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  I am afraid either I screwed somewhere up, or your tehnique does not work, this is what I did. Whenever I move the whole object(Parent), I set its <code>Vector3 Position;</code> to that new value. I also set every MeshProperties <code>Vector3 Position;</code> to that value. And then inside <code>CreateMatrix()</code> of MeshProperties I did like so:</p>
  
  <pre><code>...
  Transform = RotationMatrix * Matrix.CreateScale(x, y, z) * RotationMatrix * Matrix.CreateTranslation(Position) * Matrix.CreateTranslation(Parent.Position);
  ...
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>public void Rotate(Vector3 newRot)
  {
      Rotation = newRot;
      RotationMatrix = Matrix.CreateFromAxisAngle(Transform.Up,          MathHelper.ToRadians(Rotation.X)) * 
      Matrix.CreateFromAxisAngle(Transform.Forward, MathHelper.ToRadians(Rotation.Z)) * 
      Matrix.CreateFromAxisAngle(Transform.Right, MathHelper.ToRadians(Rotation.Y));
  }
  </code></pre>
  
  <p>And <code>Rotation</code> is <code>Vector3</code>.
  <code>RotationMatrix</code> and <code>Transform</code> are both set to <code>Matrix.Identity</code> in the constructor.</p>
  
  <p>The problem is if I try to rotate around for example Y axis, he should rotate in a circle while "standing still". But he moves around while rotating.</p>