Page 1 of 2

Does setFov work as the zoom function?

Posted: Thu Jan 25, 2007 6:58 pm
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.

Posted: Thu Jan 25, 2007 7:41 pm
by Halan
whats the problem with changing position of the cam?

Posted: Thu Jan 25, 2007 10:40 pm
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

Posted: Fri Jan 26, 2007 1:37 am
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.

Posted: Fri Jan 26, 2007 8:14 am
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?

Posted: Fri Jan 26, 2007 6:04 pm
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

Posted: Fri Jan 26, 2007 6:07 pm
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;
}

Posted: Fri Jan 26, 2007 8:06 pm
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?

Posted: Sat Jan 27, 2007 12:51 pm
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.

Posted: Sat Jan 27, 2007 4:25 pm
by hybrid
setFOV takes radiants, so just multiply by DEGTORAD

Posted: Sun Jan 28, 2007 5:55 am
by BlindSide
hybrid why not make it so that the function automatically does this for ease of use? And to match setRotation...

Posted: Sun Jan 28, 2007 12:09 pm
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?

Posted: Sun Jan 28, 2007 1:39 pm
by BlindSide
Maybe we will just be another OGRE if we did everything so bloated and perfect... :?

Posted: Sun Jan 28, 2007 7:17 pm
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

Posted: Sun Jan 28, 2007 7:46 pm
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?