Does setFov work as the zoom function?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
aerial
Posts: 14
Joined: Mon Sep 26, 2005 11:21 am

Does setFov work as the zoom function?

Post by aerial »

Dear friends

As I searched in Irr forums, I found that some people use setFov function for zooming. But it seems that these are different things. Consider a real camera, the field of view is related to the lens area (i.e. fish eye camera), but zoom depends on distance of two internal lenses used.

It seems that the best way to do a zoom in Irrlicht is to change the position of camera. I would like to hear your comments.
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

whats the problem with changing position of the cam?
xtheagonyscenex
Posts: 131
Joined: Fri Jun 03, 2005 7:26 pm

Post by xtheagonyscenex »

yes i use the fov for zoom when they hit a key i set it to (2).
if you change the position say in third person youll be inside your mesh
"Held in Your arms but too far from my heart." "These thoughts will carry me through the darkest nights...while your eyes rest in mine."
"How quickly I forget that this is meaningless."
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

a real life zoom is an illusion created by magnifying using two lens'

in game design it's a matter of situation... an orbital camera would change position basically as it would in real life if such a real life robotic flying camera existed. not only that but it's easier considering all the math is already done and zoom is directly equal to radius.

but a sniper rifle is something else because if you change position of the camera itself and are shooting through a window how do you see the trim and walls or even the glass?


it becomes pretty obvious while making the camera and code.
aerial
Posts: 14
Joined: Mon Sep 26, 2005 11:21 am

Post by aerial »

Thank you all for your answers. I examined the setFOV function more. The problem with this function is that the setFOV changes the position of the camera.

What is Field Of View? Try to put your eyes half closed. This changes your field of view. There is no zoom or translation in your view. But in Irrlicht when you change the FOV value, a transformation happens.

I can use a position change for camera instead of zoom, but the FOV in irrlicht seems to be a bug. I have built a system which sends a real camera's movements to PC and then changes the orientation and position of virtual camera in irrlicht due to the real camera's movements. I want both cameras' views (real cam and irrlicht cam) to be completely similar. Their FOV and zoom must be similar. But when I try to set fov in irrlicht, the camera performs a wrong action (transformation).

I am not sure if I am right about setFOV function in irrlicht. What do you think?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The problem with this function is that the setFOV changes the position of the camera.
No. It does not change the position of the camera. I find it funny that you ask us if fov does what we say it does, and then when we say yes, you tell us we are wrong... :)

A camera uses two transforamtions. There is the view transformation that controls what the camera is looking at and where it is looking from. Then there is the projection transform. It converts things from 3D world space to 2D screen coordinates. The projection matrix does not have any affect on the camera position. It only changes the shape of the view volume.

Changing the field-of-view is not really like partially closing and opening your eyes. When you squint, the view volume appears to smaller, but it really doesn't. The top and bottom of your view are are just blacked out. The projection isn't changing at all. This is similar to reducing the height of the render area.

Say the window used to render on is 1280x1024 pixels and that the field-of-view is 60°. As you change the fov, the window does _not_ get any narrower or wider, right? But when you squint your eye the 'window' does get narrower. When you reduce the fov, that reduced view volume is mapped onto the same 1280x1024 pixel screen area. You are fitting a smaller area [the back of the view volume] onto the same size output area. This is just like you are looking through a magnifying glass or zooming in.

Travis
Last edited by vitek on Fri Jan 26, 2007 6:13 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Just try the following code...

Code: Select all

#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")

using namespace irr;

class MyEventReceiver : public IEventReceiver
{
  scene::ICameraSceneNode* Camera;

public:
  MyEventReceiver(scene::ICameraSceneNode* camera)
    : Camera(camera)
  {
    Camera->grab();
  }

  virtual ~MyEventReceiver()
  {
    Camera->drop();
  }

  virtual bool OnEvent(irr::SEvent event)
  {
    if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
      event.KeyInput.PressedDown)
    {
      f32 newFOV = Camera->getFOV();

      switch(event.KeyInput.Key)
      {
      case irr::KEY_PLUS:
        newFOV = core::min_(newFOV + core::DEGTORAD, core::PI * .5f);
        Camera->setFOV(newFOV);
        return true;

      case irr::KEY_MINUS:
        newFOV = core::max_(newFOV - core::DEGTORAD, core::PI * .0125f);
        Camera->setFOV(newFOV);
        return true;
      }
    }

    return false;
  }
};

int main(int argc, char* argv[])
{
  IrrlichtDevice *device =
    createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600));
  if (!device)
    return 1;

  video::IVideoDriver* driver = device->getVideoDriver();
  scene::ISceneManager* smgr = device->getSceneManager();

  device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");

  scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
  if (mesh)
  {
    scene::ISceneNode* node =
      smgr->addOctTreeSceneNode(mesh->getMesh(0));
    if (node)
      node->setPosition(core::vector3df(-1300,-144,-1249));
  }

  scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();

  MyEventReceiver receiver(camera);
  device->setEventReceiver(&receiver);

  while(device->run())
  {
    if (device->isWindowActive())
    {
      if (driver->beginScene(true, true, video::SColor(0,200,200,200)))
      {
        smgr->drawAll();

        driver->endScene();
      }

      const core::vector3df pos = camera->getAbsolutePosition();

      wchar_t caption[64];
      _snwprintf(caption, 64, L"fov=%0.2f pos=[%0.2f %0.2f %0.2f]",
        camera->getFOV() * core::RADTODEG, pos.X, pos.Y, pos.Z);

      device->setWindowCaption(caption);
    }
  }

  device->drop();

  return 0;
}
aerial
Posts: 14
Joined: Mon Sep 26, 2005 11:21 am

Post by aerial »

I think setFOV cannot be used as zoom. Because increasing the FOV yields a panorama cam which is different from what we expect from a zoom function.
vitek wrote: I find it funny that you ask us if fov does what we say it does, and then when we say yes, you tell us we are wrong
I was not sure about this, and I asked if others use it for zooming or not.

You are right about the difference between FOV and squinting. I got my answer. I was not considering the aspect ratio which changes the vertical view angle.

Now could anyone help me to measure a real camera's FOV?
Prott
Posts: 104
Joined: Sun Jan 14, 2007 12:01 pm

Post by Prott »

I use setFOV as zoom and it works :) . Only thing that I need to do (because I store FOV in degrees - like real camera`s FOV) is this:

Code: Select all

camera->setFOV(3.14-((FOVdegree)*(0.022)));
(FOVdegree is FOV in degrees)

Maybe it`s a little bit "strange" way to handle it, but it works for me.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

setFOV takes radiants, so just multiply by DEGTORAD
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

hybrid why not make it so that the function automatically does this for ease of use? And to match setRotation...
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

There are functions such as setRotationDegrees() and setRotationRadians(). It's kinda hard to get it wrong when its as clearly labelled as that.

I'm not advocating renaming/duplicating every function that accepts Euler angles, though, as that would seem like overkill. :wink: Or is it?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Maybe we will just be another OGRE if we did everything so bloated and perfect... :?
aerial
Posts: 14
Joined: Mon Sep 26, 2005 11:21 am

Post by aerial »

Why setFOV cannot be used for zooming

Take a look at the following pics.
1st pic: no change in fov or zoom
2nd pic: effect of increasing FOV
3rd pic: effect of zoom back (performed by cam. movement)

Image

Notice the degradation of the tiles in second pic. related to change in FOV. In order to get a view of what FOV does, think of a fisheye camera (like the lens installed on home doors to see who's behind the door).

Refer to this link if you were unable to see the pics.
http://ykhatami.googlepages.com/fovnzoom2.jpg
KG
Posts: 35
Joined: Wed Jun 07, 2006 12:00 am

Post by KG »

In all the FPS games I have played zooming has been achieved by reducing (not increasing) the FOV, whether it was a built in function or a user made macro. Does Irrlicht's camera really function differently?
Post Reply