Zoom of a 3D object

Started by
4 comments, last by nb 15 years, 1 month ago
I need to do a 100% zoom of my camera in a scene object (it larger dimension has to fit exactly in the viewport). Currently, I'm zooming by translating the camera towards the object aabb center. 1) I don't know how to calculate the correct distance between the camera and the aabb center, it is hard-coded. Could someone help with the math? 2) I read that zooming by translating is worst than changing the fov. Why is that? AFAIK, fov zooming can cause scene distortion, depending on the angle used. Camera translation don't suffer from that problem. What are the advantages of fov over translating? 3) Last, the scene with the zoomed in/out object should only occupy a section of my screen (center-left). What is the best way to accomplish this? Setting the viewport area to this rendering section area? Thanks in advance.
Advertisement
By translating your cam you can easily end up in situations where you translate your cam beyond objects of your scene. Hence those objects are the behind the camera and get clipped. Adjusting the fov is the way real world physics work when zooming and that's the way you should go in your app.

To calculate the required fov get your scene's bounding box and the desired camera position. Then calculate the angle between the viewing direction from the cam pos to and the ray from the cam pos to the bounding box corner.
------------------------------------I always enjoy being rated up by you ...
waterwalker has nailed it, but here is a ramble for you to read and maybe it will shed some light on a few things too. or not.

Quote: 2) I read that zooming by translating is worst than changing the fov. Why is that? AFAIK, fov zooming can cause scene distortion, depending on the angle used. Camera translation don't suffer from that problem. What are the advantages of fov over translating?


the difference between a zoom and simply moving closer is exactly that though... the 'distortion' caused by zooming.

when you are 100 metres away from something and look at it through a scope (zoom) the viewing angle is literally different to if you are say 10 metres away from the object. even though the object in both instances 'fills' your viewing area by seemingly the same amount, what happens with everything behind and around (or even in-front of) the object is 'distorted' when comparing between the two, and in fact the zoomed situation cuts-away surrounding objects that you can otherwise see when not zoomed but standing closer.

this all starts to play on the reason why things in the distance seem to move slower than things nearer which also leads to...

!!!movie-magic-moment!!!
i wonder if you know what i mean if i ask if you know of and can picture in your mind a part from a movie where the camera is focused on someone (usually their face has a 'light-bulb moment ((oprah tm))', usually of the 'oh crap' kind of moment) and the background seems to be closing-in on the person or moving away. this is accomplished by having the camera's zoom such that the area that the person (or their face) takes up on the screen stays as similar as possible while they either move the entire camera closer or further away. they are changing the fov of the camera on-the-go to make the subject occupy the same area on the screen whilst simultaneously physically moving the camera closer or further away. this causes the background etc to do that funky effect. i have no idea what it might be called, and maybe you already know what i'm on about.

I think the answer for number 1 will work itself out if you understand what i've just been talking about. you don't know how far away you need to be to have the object fill the screen, if i understand you correctly? the thing is with 'zooming' via a change of FOV what you need to be looking into is calculating the angles to the outside edges of the object (or AABB as you have already mentioned) from the camera position and then working out the correct FOV from that information. this is what waterwalker has already explained.

assuming you have the camera looking directly at the centre of the aabb then consider the following... if you calc the angle from the camera direction to the left of the aabb then that is half the total angle you need to set your fov to e.g. if the angle to the left of the aabb is 45 degrees then your total fov should be 90 and that should fill your screen with your object. what if the angle is not 45 degrees and is instead say 61 then once again the total fov you need is 2 times that which is 122 degrees.

problem... it sounds like you probably don't actually want to go this way and want something that does not show any distortion under any circustance. in this case it sounds like you are looking in the wrong direction and instead of 'zooming' on something in a 3D environment you simply want to be able to 'resize' something in a 2D environment.


just wanted to throw some thoughts at you and see what happens.
Here's what I do to scale an object to keep its projected size independent of the distance to the camera. You could change that equation to calculate the FoV needed to achieve a certain size on the screen.
double tScale = tDistance/Math.tan(camera.getFovInRadians()/2); //tDistance is the distance between object and camera

Hope that helps.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Quote:Original post by nb
!!!movie-magic-moment!!!
i wonder if you know what i mean if i ask if you know of and can picture in your mind a part from a movie where the camera is focused on someone (usually their face has a 'light-bulb moment ((oprah tm))', usually of the 'oh crap' kind of moment) and the background seems to be closing-in on the person or moving away. this is accomplished by having the camera's zoom such that the area that the person (or their face) takes up on the screen stays as similar as possible while they either move the entire camera closer or further away. they are changing the fov of the camera on-the-go to make the subject occupy the same area on the screen whilst simultaneously physically moving the camera closer or further away. this causes the background etc to do that funky effect. i have no idea what it might be called, and maybe you already know what i'm on about.


It's called a dolly zoom. Used in Hitchcock's Vertigo.
http://en.wikipedia.org/wiki/Dolly_zoom

that's the one!

dolly zoom. hmm i shoulda known that i guess. nicely found, and of course wikipedia explains it better than i ever could so that rocks.

This topic is closed to new replies.

Advertisement