I have a camera that rotates around a center point using a rotation matrix and radius for the zoom from the object. I need to add right mouse button panning in.

Here is the problem: when I change center.x and center.y depending on my cameras rotation around the object the camera ends up moving closer or farther from the camera. What I want is no matter which way the camera is facing to the object it should move on the cameras forward and up, not the models. What kind of math do I need to use for this?

My code to change the "center" or view target is as follows

var xdelta = mousestate.X - PreviousMouseState.X;
var ydelta = mousestate.Y - PreviousMouseState.Y;
if (ydelta != 0 | xdelta != 0)
    center += Vector3.Transform(new Vector3(0, ydelta * .02f, 0), rotation);
  • \$\begingroup\$ what is center.x and center.y ? is it the camera position? and how are you changing them exactly ? \$\endgroup\$ – concept3d Oct 1 '13 at 16:36
  • \$\begingroup\$ Sorry, center is the vector3 of the target. I am changing them by getting the mouse x/y delta and adding that value to the target. \$\endgroup\$ – Paul Wade Oct 1 '13 at 16:48
  • \$\begingroup\$ Also I am specifically modifying the modelviewer camera from engine nine which you can see the code for here nine.codeplex.com/SourceControl/latest#Source/Nine.Graphics.3D/… \$\endgroup\$ – Paul Wade Oct 1 '13 at 16:50
  • \$\begingroup\$ It looks like what is happening to me is that the target x/y changes are made on the original x/y of matrix identity? and one the camera is looking down at the model y moves on the CAMERAS Z axis pulling it closer. when the center should change based on the cameras x/y at all times? \$\endgroup\$ – Paul Wade Oct 1 '13 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.