Game Development Community

Gradual Zoom?

by Josiah Wang · in Torque Game Engine · 12/29/2003 (9:12 am) · 16 replies

Any ideas on how to implement a gradual zoom?

#1
12/29/2003 (10:37 am)
In theory Torque already has code to do this... Not sure what it takes to enable it. :)
#2
12/29/2003 (10:50 am)
Just adjust the FoV for the player. One way of doing this as an example is setting it using a slider onscreen. TZ used to use just that for a while - a little slider, and you could slide between 90 (slightly fisheyed) and 1, with anything in between fair game. (Instead, I went to something that was more keyboard friendly, and you toggle between four different FOV settings.)

And if you are wondering how to set the FOV - just search for "FOV" your editor of choice for the torquescript files.
#3
12/29/2003 (10:55 am)
I whipped up a little script code once to do this.
turned out pretty cool.

you just press the key it starts zooming, let go it will stop at that level.

it was pretty simple stuff.

you just need to define a step, and iterate over that step applying it to the fov while the key is pressed.
#4
12/29/2003 (11:08 am)
Sorry, I'm a newbie but thanks guys for the help!

where would I modify the FOV (field of view, right?), or zoom for that matter (ie: which script file)
#5
01/03/2004 (5:58 pm)
**bump**
#6
01/03/2004 (6:03 pm)
Default.bind.cs i believe
#7
01/03/2004 (6:05 pm)
Depends entirely on you application, Josiah. 'Tis why I didn't answer :-) Dig through the resources and forums, and there are a couple of places where people mention working with Zoom - from there, you should be able to deduce what you need and where.
#9
06/17/2005 (1:32 pm)
*takes hammer & really bumps thread*

Anybody know how to script a scope like BadGuy mentioned? Holding the toggleZoom button down and having the zoom increase until you let it up? Like from 1x to 8x?
#10
06/17/2005 (4:31 pm)
In other words, I have it set up when you right click to do toggleZoom at the FOV of 11.25, or 8x. I need it so that the right click will cause the Zoom to start at 1x and smoothly (gradually) zoom in until it reaches 8x, and if you stop right clicking it will stop the zoom wherever you are, and if you right click again, it restores the regular 1st person view.

My current code in default.binds.cs:

if($Pref::player::CurrentFOV $= "")
   $Pref::player::CurrentFOV = 11.25;

function setZoomFOV(%val)
{
   if(%val)
      toggleZoomFOV();
}
      
function toggleZoom( %val )
{
   if ($firstPerson == 1) // --> no zoom when 3rd person
   {
      if ( %val )
      {
         $ZoomOn = true;
         setFov( $Pref::player::CurrentFOV );
         ScopeGuiGroup.Visible = 1; // show scope for zoom
         Crosshair.Visible = 0;
      }
      else
      {
         $ZoomOn = false;
         setFov( $Pref::player::DefaultFov );
         ScopeGuiGroup.Visible = 0; // make scope invisible
         Crosshair.Visible = 1;
      }
   }
}


moveMap.bind(keyboard, r, setZoomFOV);
moveMap.bind(mouse0, button2, toggleZoom);
#11
06/17/2005 (5:03 pm)
Here's my guess:

if (%val) {
  if ($Pref::player::CurrentFOV <= $yourDefinedMaxZoomFOV) {
    $Pref::player::CurrentFOV -= %yourDefinedZoomIncrement;
    setFov( $Pref::player::CurrentFOV );
  }
} else {
  if ($Pref::player::CurrentFOV >= %yourDefinedMinZoomFOV) {
    $Pref::player::CurrentFOV += %yourDefinedZoomIncrement 
    setFov( $Pref::player::CurrentFOV );
  }
}

You'd have to fill in all the $yourDefined* variables yourself [as you may have guessed by their names :P ].

Why didn't you bind button2 to setZoomFOV directly?
#12
06/17/2005 (5:35 pm)
That doesn't work. lol

fps/client/scripts/default.bind.cs:
function toggleZoom( %val )
{
   if ($firstPerson == 1) // --> no zoom when 3rd person
   {
      if (%val) {
         $ZoomOn = true;
         ScopeGuiGroup.Visible = 1; // show scope for zoom
         Crosshair.Visible = 0;
        if ($Pref::player::CurrentFOV <= .25) {
          $Pref::player::CurrentFOV -= %1;
          setFov( $Pref::player::CurrentFOV );
        }
      } else {
         $ZoomOn = false;
         ScopeGuiGroup.Visible = 0; // make scope invisible
         Crosshair.Visible = 1;
        if ($Pref::player::CurrentFOV >= %90) {
          $Pref::player::CurrentFOV += %1;
           setFov( $Pref::player::CurrentFOV );
        }
     }
}
#13
06/18/2005 (9:21 am)
Mmk. So I decided to use a different version, to hit the backslash key to toggle the zoom (2x/3x/4x/5x/6x).

One problem is, if you're holding the right click (toggleZoom) and are zoomed in, and you hit TAB to go 3rd person, you do! And you're zoomed in as well, with the scopeGUI on. How do I disable TAB while holding the zoomToggle down?

//------------------------------------------------------------------------------
// Zoom and FOV functions
//------------------------------------------------------------------------------

if($Pref::player::CurrentFOV $= "")
   $Pref::player::CurrentFOV = 45;

function setZoomFOV(%val)
{
   if(%val)
      toggleZoomFOV();
}

function toggleZoom(%val)
{
   if ($firstPerson == 1) // --> no zoom when 3rd person
   {
      if ( %val )
      {
         $ZoomOn = true;
         setFov( $Pref::player::CurrentFOV );
         ScopeGuiGroup.Visible = 1; // show crosshair for zoom
         Crosshair.Visible = 0; // hide crosshair
      }
      else
      {
         $ZoomOn = false;
         setFov( $Pref::player::DefaultFov );
         ScopeGuiGroup.Visible = 0; // make zoomcrosshair invisible
         Crosshair.Visible = 1; // show crosshair
      }
   }
}

function toggleZoomFOV()
{
   %i = $Pref::player::CurrentFOV;

   switch (%i)
   {
      case 45: %i = 35; %s = "X3";
      case 35: %i = 25; %s = "X4";
      case 25: %i = 15; %s = "X5";
      case 15: %i = 05; %s = "X6";
      case 05: %i = 45; %s = "X2";
      default: %i = 45; %s = "X2";
   }
   
   $Pref::player::CurrentFOV = %i;
   if($ZoomOn)
      setFov(%i);

}

moveMap.bind(keyboard, backslash, setZoomFOV);
moveMap.bind(mouse, mouse2, toggleZoom);
#14
06/18/2005 (10:11 am)
Add a check in the function that tab calls?
#15
02/26/2010 (8:28 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);  
   }  
}
#16
02/27/2010 (7:08 am)
couldn't you just setFov and keep it within a specified range? If your defaultFOV is 90, for example, and you want to zoom between 1 and 90, have a function that sets the FOV to a number passed or global var if your in FP. Once you come out of FP to third person, set the FOV back to 90.
$fov = $Pref::player::defaultFOV;
function zoom(%val)
{
  if(%val > 0)
  {
    if($fov + 1 <= 90)
      setFov($fov + 1)
    else
      return;
  }
  else
  {
    if($fov - 1 >= 1)
      setFov($fov - 1)
    else
      return;
  }
}

...and then reset $fov to 90 and setFov($fov) at the beginning of the toggle FP/ThirdPerson (if your going into ThirdPerson). Connect zoom() to the mouse wheel and bind and unbind the mouse wheel when you go to and from FP/ThirdPerson.

...this is all psuedo-codingly speaking but it might work.