Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a DirectX scene. I want zoom in using mouse wheel to the mouse location. I am able to zoom the view to center of screen but I need to zoom to mouse location. Please suggest how it can be done. Thanks

share|improve this question

1 Answer 1

You need to send a ray from the mouse cursor along the camera view direction through the scene and see where it intersects (take the intersect position closest to the camera position) to know the 3D position. After that you can easily zoom in there by placing the camera closer.

This is often called unprojecting and can be done by fiddling a bit with your projection matrix and the screen coordinates of your mouse cursor.

share|improve this answer
    
Thanks for the reply Roy T. I am able to get the 3D position and able to unproject but I am able to zoom to the center of screen as my camera always looks at the center of viewing area. So, my question here is how do I place the camera around the mouse cursor point so that it looks like it is zooming to mouse position. –  Pankaj Sep 6 '11 at 13:14
    
First set your camera look at to the 3D position of the mouse, then move closer to that point. Of course this will make the mouse cursor position the center of the screen. Alternatively you could figure out the distance between the screen-position of the mouse and the center of the screen. Then calculate what the same distance in screen space units would be zoomed in and use a parallel ray to move the camera along, this way the 3d position of the cursor will stay in the same relative screen space area but will come closer. –  Roy T. Sep 6 '11 at 14:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.