using the camera to zoom and scroll

mskeel

Well-known member
Joined
Oct 30, 2003
Messages
913
Location
Virginia, USA
I have a picture drawn on the x-y plane and I am looking down at it from somwhere on the z plane giving a 2-dimensional map from above feel to it. I would like to be able to use the mouse to scroll the map around - drag it similiar to an adobe pdf document. I have figured out a way to do this by setting the camera vectors in the dev.transform.view matrix. The problem is, depending on my level of zoom, the map will scroll at a rate faster or slower than the cursor so a small, precise movement of the mouse yeilds a large shift in the map.

How can I fix this problem?
 
Use Vector3.Unproject. Compute result on Vector3(mouseX, mouseY, 0) and Vector3(mouseX, mouseY, 1), the other parameters fetched from device. This gives you a ray in world space as defined by the mouse position. You can compute the intersection of this ray with your plane, giving you a 3D position of the mouse. Computing this at two times and subtracting it gives you the amount you have to move with the view matrix.
 
Back
Top