## Camera Zooming

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I'm trying to simulate a gun scope into my game and am having trouble figuring out the math behind zooming the camera. I don't want to change the actualPosition or actualView of the camera so I have created a lookPosition and lookView which are the vectors put into the gluLook() function.

Here's what I have so far:
Code:
```actualPosition - vector containing the true position of the camera actualView - vector containing the true view direction of the camera zoomLevel - float value of the amount to zoom lookPosition - vector containing the presumed position of the camera for zooming (when zoomLevel==0, the lookPosition==actualPosition) lookView - vector containing the presumed view of the camera for zooming (again when zoomLevel==0, the lookView==actualView)```

I have already figured out the lookPosition = actualPosition + (actualDirection * zoomLevel) but I can't find a good way to get the lookView. Does anyone have any ideas on how to accomplish this or have a better way to simulate the scope (this way will allow my scope to go through objects technically and I'm not sure how to fix that)?
Moderator
Posts: 133
Joined: 2008.05
Post: #2
I've never done this before, so I can't guarentee this works, but it seems reasonable. Say you have 3 levels of zooming, 100m, 50m, and 10m. You flip on the 10m scope and the position the player is actually viewing moves up 10m, so playerPosition + 10*playerDirection. Then you'd set a new look vector to that. Then you'd check for any collisions between the player and that new vector, starting at the new vector, and if there is one you just replace the look vector with the difference between the object you are colliding with and the player's actual position.

Then if you set it to 50m, you'd do the same thing but check everything between 50m and the player. Basically, what it will do is move the scope to the right spot unless there's something blocking you, and it'd just put you right in front of that object so you're view is completly obscured by it. However, this wouldn't work to well if there was something that was blocking half you're view or it was transparent or something. You're entire idea of just moving the camera wouldn't work, and I wouldn't know how to do that. But otherwise, this is a good start.
kberg
Unregistered

Post: #3
Hrm, I bet there is a way to get a good effect for almost no work on your part... I might try different numbers for your viewport and projection matrix... This way you should be able to smoothly switch between zoomed out to zoomed in without worry of colliding with any objects, the objects would just appear super huge in your scope (which is probably the effect you are looking for).
Moderator
Posts: 365
Joined: 2002.04
Post: #4
You don't want to move the camera to effect zoom, because you'll end up inside objects or behind walls. Instead, change the camera angle with gluPerspective(). Narrower angles (FoV) will result in a greater degree of zoom. That's more or less how telescopic zooming works in the real world.

Neil Carter
Nether - Mac games and comic art
Puzzler183
Unregistered

Post: #5
Yeah, this is a field of view issue. And btw, you might want to reconsider your use of gluLookAt in actual production code since it's very slow and can be quite readily optimized.
Member
Posts: 184
Joined: 2004.07
Post: #6
Puzzler183 Wrote:Yeah, this is a field of view issue. And btw, you might want to reconsider your use of gluLookAt in actual production code since it's very slow and can be quite readily optimized.

If you're calling gluLookAt only once per frame (or any other function that performs a constant number of arithmetic operations, for that matter), there's no sense in wasting time optimizing it any further. Only optimize things you call many, many times per frame, or that run in non-constant time.
Sage
Posts: 1,066
Joined: 2004.07
Post: #7
I'm only calling gluLookAt once per frame.

The changing of the perspective angle did exactly what I wanted. Never would've thought of it. Thanks for that help. I'm still working on the various angles to get the look I want. I'm going to do some searching for ways to figure out the angle I need to replicate 2x, 5x, 10x, and other such zooms.

That leads me to a quick opinion poll: what zoom levels should a first person shooter have? I don't know much about guns at all so I'm curious which ones are actually used.
Puzzler183
Unregistered

Post: #8
No point other than understanding what's going on (the main reason) and making it go a little faster. But mostly to know what is happening.

As for zoom, I'm pretty sure that UT uses like 2 to 10x for their sniper rifle or something to that effect. You could always check the field of of view in Counter Strike for example when you zoom in and out with guns to get a realistic idea too.