title: How to rotate a camera around its own axis in WPF viewport3D?
body: <p>I am working on a 3D application in WPF and having trouble with the camera. It should be possible to rotate the camera around its own axis (with other words, look around) using the mouse but I can not get it to work properly. I create the camera with the following code:</p>
  
  <pre><code>PerspectiveCamera perspectiveCamera = new PerspectiveCamera(new Point3D(0, 30, 0), new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), 90);
  perspectiveCamera.NearPlaneDistance = 0.001;
  perspectiveCamera.FarPlaneDistance = 1000;
  
  center = new TranslateTransform3D(0, 30, 0);
  rot_x = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0);
  rot_y = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
  rot_z = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0);
  zoom = new ScaleTransform3D(1, 1, 1);
  
  Transform3DGroup t = new Transform3DGroup();
  t.Children.Add(zoom);
  t.Children.Add(new RotateTransform3D(rot_x));            
  t.Children.Add(new RotateTransform3D(rot_y));
  t.Children.Add(new RotateTransform3D(rot_z));
  t.Children.Add(center);
  perspectiveCamera.Transform = t;
  myViewport3D.Camera = perspectiveCamera;
  </code></pre>
  
  <p>And then I try to rotate it using the following code:</p>
  
  <pre><code>private void OnViewportMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  {
      if (mouseLeftIsDown)
      {
          Point position = e.GetPosition(this);
          double rotZAngle = (rot_z.Angle % 360) + oldLeftPosition.X - position.X;
          double rotXAngle = (rot_x.Angle % 360) + position.Y - oldLeftPosition.Y;
          if (rotZAngle &lt; 0) //rotZAngle is negative, make it positive
          {
              rotZAngle = 360 + rotZAngle;
          }
          if (rotXAngle &lt; 0) //rotXAngle is negative, make it positive
          {
              rotXAngle = 360 + rotXAngle;
          }
          rot_z.Angle = rotZAngle;
          rot_x.Angle = rotXAngle;
          oldLeftPosition = position;
      }
  }
  </code></pre>
  
  <p>However, it seams that the rotation is not happening around the camera and instead somehere else. The model that I load at position (0,0,0) is becoming visible after I rotate 180 degrees around the z axis which should not be the case.</p>
  
  <p>What am I missing?</p>