Jump to content
  • Advertisement
Sign in to follow this  
CmasterG

Box Zoom

This topic is 1893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

After my fit to screen question I have the next problem. Now I want to box select a section of my screen and then zoom in that selection. So I have four corner points (my rectangle which I can drag with the mouse) in pixel coordinates. I have a perspective projection.

Can anyone help me with this? I have no idea how to do that. I guess that I have to calculate maybe a view frustum for my section?

 

Respectfully,

                   CmasterG

Share this post


Link to post
Share on other sites
Advertisement

Not sure if the question is for selection or zooming. For selection :

 

You could parametrize the corners of the selection as world coordinate rays. After you are able to calculate the plan normals of your trapezoide and should be able to check if the origin / bounding box min/max are inside the box with scalar product for each of your plans.

 

For zooming, it's about finding the right forward offset and move the camera there. I guess you could compute the min/max of your selection and use the diagonal length, modulated by your view ratio. Worked well for focusing.

Edited by Extremophile

Share this post


Link to post
Share on other sites

Hi!

I mean zooming. I already have the corner points from my rectangle, and now I want to zoom in. The rectangle can be everywhere on the screen and I use perspective projection.

Can you give me a link for the formulas ? I don't know how to calculate it.

Thanks :)

Share this post


Link to post
Share on other sites


I already have the corner points from my rectangle, and now I want to zoom in.

 

in what manner?

 

do you want to move the camera so the screen matches the selected area, but the camera still points the same way?

 

or do you want to turn the camera to the direction of the selected area, then zoom in until the inside or outside of the area is at the screen edges?

 

to point it the same way, you could use size ratios and offsets between the screen size and area selected, and the centers of each (perhaps), that's sort of solving it in screen space.

 

or you could backsolve the screen back to world space, and then forward solve to the selected area, taking into account offsets. but it sounds harder.

 

generally speaking, the size ratio should be proportional to the amount to  move the camera forwrd andd back, and the offset of the scenters should be proportional to the amount to move the camera side to side.

 

off the top of my head i'd say that area width = 1/2 screen width => move it twice as close. and in general area * % to move closer * 100 = screen width. 

 

screen width 1600, area selected 800 wide, 1600/800=2, move it twice as close.  but twice as close to what?   how far is twice as close?

 

well, that gets a but ugly....

 

if you can select any area, even sky, who's to say how far away it is. 

 

if however if its a more top down kind of thing, then you can treat the area as being at the distance of the point where it intersects the ground.

 

this would be a raypick kind of thing to get the distance. 

 

for a true top-down select-area and zoom-in effect its trivial: move the camera til the centers align, then zoom based on ratio of screen size to area size.

 

unless you draw an area at the same aspect ratio as the screen, you'll have to come up with a convention as to whether you zoom til reach the inner or outer of the two sets of edges, as you'll almost always reach one (top and bottom, or left and right) before the other, if they can select areas of arbitrary aspect ratio.

 

while a cool effect, you may want to think of an alternative that may be easier to implement, such as simply turning in the direction of a mouse click and zooming by some constant amount, or perhaps click to turn the camera, then roll the mouse wheel to zoom (in OR out) as desired.

 

but give it a go, it may not be as hard as it sounds.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!