title: XNA: get Vector3 from Matrix
body: <p>I thought I understood matrix math well enough, but apparently I'm clueless</p>
  
  <p>Here's the setup:</p>
  
  <p>I have an object at [0,0,0] in world space.  I have a camera class controlled by mouse movements to rotate and zoom around the object such that it always looks at it.  Here is how I calculate my viewMatrix from the camera:</p>
  
  <pre><code>public Matrix viewMatrix { 
      get {
          return 
              Matrix.CreateFromAxisAngle(Vector3.Up, rotAngle)
                  * Matrix.CreateFromAxisAngle(Vector3.Left, pitchAngle)
                  * Matrix.CreateTranslation(0, 0, distance) 
          ;
      }
  }
  </code></pre>
  
  <p>I need to be able to get the position of the camera in world space so I can get its distance from the box--particularly its distance from each face of the box.  <strong>How can I get the camera's xyz position in world space coords?</strong></p>
  
  <p>I've tried:</p>
  
  <pre><code>// all of these only return [0, 0, distance];
  Vector3 pos = Vector3.Transform(Vector3.Zero, viewMatrix);
  Vector3 pos = viewMatrix.Translation;
  Vector3 pos = new Vector3(viewMatrix.M41, viewMatrix.M42, viewMatrix.M43);
  </code></pre>
  
  <p>It seems like the rotation information is being lost somehow. The strange thing is that the viewMatrix code works perfectly for positioning the camera!</p>