Sign in to follow this  
Medo Mex

Camera Zooming In and Out

Recommended Posts

Medo Mex    891
I thought zooming in can be accomplished by moving the camera forward but unfortunately it doesn't work like that.
 
Lets say I want to zoom in for a sniper sight, moving the camera forward will cause a problem if there is something close, for example: A close wall.
 
How do I create a method like: Camera::Zoom(float amount); ?

Share this post


Link to post
Share on other sites
Medo Mex    891

I have the field of view set to "D3DX_PI / 4" by default, how do I change it to add zoom in/out amount so when I call the method Zoom(float amount); I can change the field of view accordingly?

 

I tried:

 

camera->fov = (D3DX_PI / 4) + amount;

Not sure if the above is correct, however it cause a problem when amount reach certain number, the camera get up side down.

Share this post


Link to post
Share on other sites
You want to multiply the field of view by a float between 0 and 1 to zoom in. Use 1 for normal zoom, experiment for the zoomed in value. You can interpolate the zoom amount to zoom in smoothly. Try 0.5 to start with (should make everything twice the size) and tweak from there.

camera->fov = (D3DX_PI / 4) * amount; // amount = 1.0f -> no zoom

Share this post


Link to post
Share on other sites
Medo Mex    891

@Paradigm Shifter: What If I want to zoom in more?

 

Also, I notice two problems when I zoom in till the maximum value:

1. The textures get weird effect

2. The camera can see what is the behind the mesh (like it's penetrating the mesh) which is not realistic.

Share this post


Link to post
Share on other sites
Hodgman    51234

Don't treat "D3DX_PI / 4" as some kind of magic number -- Pi/4 radians == 45 degrees.

You can work in degrees to make things more obvious if you want to, e.g.[code]float regularFov = 45.0f; float sniperFov = 5.0f; camera->fov = DegreesToRadians( isSniping ? sniperFov : regularFov );[/code]

Share this post


Link to post
Share on other sites
Medo Mex    891

@Hodgman: When zooming, the value shouldn't change suddenly, instead, the zoom should be changing smoothly.

 

I have the same problems that I mentioned when earlier when I zoom in to the maximum value, I also want to zoom MORE than the maximum value.

Share this post


Link to post
Share on other sites
Hodgman    51234

It was just an example of using intuitive values in degrees, you can animate them however you like, e.g.

 

inline float lerp( float a, float b, float f ) { return b*f + a*(1-f); }
float fovDegrees = lerp( regularFov, sniperFov, zoomFraction )

 

 

What is your maximum zoom value -- what fov value are you using as the 'maximum'? If you use an fov of 0, then you'd end up with an infinitely thin frustum with no area... but any value greater than 0 should work (and smaller than 180º...)

Can you post a picture of your "weird" textures?

Edited by Hodgman

Share this post


Link to post
Share on other sites

[quote name='Medo3337' timestamp='1357541721' post='5018480']
when I zoom in to the maximum value, I also want to zoom MORE than the maximum value
[/quote]

Only way you can achieve this is to set your "maximum" value as some value, which is slightly short of the absolute maximum value (pi radian).

Share this post


Link to post
Share on other sites
Burnt_Fyr    1665

As Steve curiously asked, a small FOV should result in more zoom(And by asking, I'm sure it was more a question you should ask yourself). As Hodgman noted, a FOV of 0 results in just that. 0 field of view, your frustum essentially becomes a 2d slice(whose angle would depend on the aspect ratio), rather than a volume. A FOV = epsilon is the maximum zoom you could possibly get.

 

Sidenote: Hodgman, you asked if we could see the "weird textures" I'm guessing here, but are you expecting a moiré pattern?

Edited by Burnt_Fyr

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this