Smooth Camera Zoom
by Jeremy Noetzelman · in Torque Game Builder · 03/04/2005 (9:01 am) · 7 replies
I've bound the mouse wheel to zoom the camera in and out, initially with an increment of 0.1 (picked arbitrarily).
What I'm finding is that at the 'default' zoom level, zooming works about how I'd expect. The fun comes when you zoom in or out a bit ... after zooming out a little bit, that 0.1 increment suddenly has a huge effect. Conversely, after zooming in a bit, that same 0.1 increment has little effect on the camera view.
Is there a way to have the zoom 'look' be consistent?
What I'm finding is that at the 'default' zoom level, zooming works about how I'd expect. The fun comes when you zoom in or out a bit ... after zooming out a little bit, that 0.1 increment suddenly has a huge effect. Conversely, after zooming in a bit, that same 0.1 increment has little effect on the camera view.
Is there a way to have the zoom 'look' be consistent?
#2
There are lots of ways to zoom really. You could use a logarithmic zoom e.g. "setCurrentCameraZoom( mLog( zoom+1 ) );" (approximately)
Zoom is essentially logarithmic in nature so you could use log or pow to give you the effect you desire.
T2D zooms by the original viewport in a linear fashion therefore 0.5 shows you (1/2)=x0.5, (1/10)=x0.1 the view etc.
- Melv.
03/04/2005 (9:53 am)
Jeremy,There are lots of ways to zoom really. You could use a logarithmic zoom e.g. "setCurrentCameraZoom( mLog( zoom+1 ) );" (approximately)
Zoom is essentially logarithmic in nature so you could use log or pow to give you the effect you desire.
T2D zooms by the original viewport in a linear fashion therefore 0.5 shows you (1/2)=x0.5, (1/10)=x0.1 the view etc.
- Melv.
#3
I'll add some code later tonight to make my point clearer.
03/04/2005 (11:11 am)
Not sure if this matters in your case Jeremy but my experience with zoom alerted me to a pit fall. It appears that the value returned is a 'strength' factor of how hard the wheel was turned. So if someone is really wailing on the wheel and you use that value it in your zoom formula it will affect the zoom a lot more than a normal wheeler? I hope that make sense?I'll add some code later tonight to make my point clearer.
...coming soon...
#4
Phil, I see the same behavior when the zoom function is bound to keys but I'll keep that in mind.
03/04/2005 (11:15 am)
I'll try the log/pow stuff tonight, Melv, thanks.Phil, I see the same behavior when the zoom function is bound to keys but I'll keep that in mind.
#5
02/26/2010 (8:05 am)
For a gradual FOV zoom, a little recursion is your friend. Here is a gradual FOV zoom function(s) for you:function ZoomInGradual()
{
if (LocalClientConnection.camera.getCameraFov() > 25){
ZoomInRecursive(25);
}
echo("Zoomed FOV to:25" );
}
function ZoomInRecursive(%myFinalZoom)
{
%myFOV = LocalClientConnection.camera.getCameraFov();
if ( %myFOV>%myFinalZoom){
%myFOV =%myFOV/1.1;
setFov(%myFOV);
}
if ( %myFOV>%myFinalZoom){
schedule(10,0,ZoomInRecursive, %myFinalZoom);
}
}
#6
02/26/2010 (8:08 am)
The previous post was 5 years ago and it was a different product (TGB) which doesn't use FOV code. :)
#7
02/26/2010 (8:27 am)
right, well I imagine the same concept could be incorporated without too much trouble
Torque 3D Owner Matthew Langley
Torque