Jump to content

  • Log In with Google      Sign In   
  • Create Account


Camera Zooming In and Out


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 05 January 2013 - 12:36 PM

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); ?


Sponsor:

#2 phantom   Moderators   -  Reputation: 6786

Like
1Likes
Like

Posted 05 January 2013 - 12:44 PM

To get a zoom effect you can adjust the field of view used in your projection matrix calculation.



#3 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 05 January 2013 - 02:51 PM

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.



#4 NewDisplayName   Members   -  Reputation: 351

Like
0Likes
Like

Posted 05 January 2013 - 03:16 PM

Your FOV is exceeding pi radians and that's why you see inverted images after some amount. It's based on the principles of focal point in optical physics.


Edited by NewDisplayName, 05 January 2013 - 03:18 PM.


#5 Paradigm Shifter   Crossbones+   -  Reputation: 5117

Like
1Likes
Like

Posted 05 January 2013 - 03:22 PM

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
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#6 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 January 2013 - 12:00 AM

@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.



#7 Hodgman   Moderators   -  Reputation: 27585

Like
0Likes
Like

Posted 07 January 2013 - 12:22 AM

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.

float regularFov = 45.0f;
float sniperFov = 5.0f;
camera->fov = DegreesToRadians( isSniping ? sniperFov : regularFov );



#8 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 07 January 2013 - 12:55 AM

@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.



#9 Hodgman   Moderators   -  Reputation: 27585

Like
1Likes
Like

Posted 07 January 2013 - 01:15 AM

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, 07 January 2013 - 01:16 AM.


#10 NewDisplayName   Members   -  Reputation: 351

Like
0Likes
Like

Posted 07 January 2013 - 02:14 AM

when I zoom in to the maximum value, I also want to zoom MORE than the maximum value

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).



#11 Evil Steve   Members   -  Reputation: 1955

Like
1Likes
Like

Posted 08 January 2013 - 12:52 PM

Don't you want to decrease the FOV to zoom in, rather than increase it?

Steve Macpherson
Senior programmer, Firebrand Games


#12 Burnt_Fyr   Members   -  Reputation: 1199

Like
0Likes
Like

Posted 08 January 2013 - 01:05 PM

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, 08 January 2013 - 01:10 PM.


#13 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 08 January 2013 - 04:15 PM

@Burnt_Fyr: Exactly, when I zoom in sometimes I see a slight moiré pattern which make the texture looks weird.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS