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

Post by aerial »

KG wrote: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.
Could you please name some games? Irrlicht's camera works properly. When you increase the FOV, a larger area must be shown in the predefined window (refer to post above by vitek). Showing a larger area is possible by showing objects smaller; because the objects are shown smaller we think a zoom-back has happened, which is not true.

Take a look at the stairs (Top-Right of the pic) in the 2nd pic above, and notice the red walls in the top-left corner which is not seen in the 3rd pic related to a real zoom. In 2nd pic camera's FOV has been increased and the camera must cover a larger space, then it shows stairs more smaller than a real zoom.

Using FOV for zooming could be tricky, everyone may use it for zooming and it may not harm in many games, but leads to false views in some applications such as mine.
KG
Posts: 35
Joined: Wed Jun 07, 2006 12:00 am

Post by KG »

Well, any game based off of any of the Quake engines gives you a zoom effect if you decrease FOV. Half-Life 2 does that too, and it's very far removed from its Quake engine roots if it even has any of the original code left in it. I haven't played any Unreal Engine games since Unreal Tournament, but Unreal, UT, and Deus Ex all gave zoom effects at lowered FOV as well.

Is that enough games?
aerial
Posts: 14
Joined: Mon Sep 26, 2005 11:21 am

Post by aerial »

If HL2 does not use fov, you better not use it too. I dont remember UT using FOV.

I am trying to write code to perform zooming by cam movements. I wrote a simple code, used setPosition func. and it worked but then I decided to add collision detection to the code. The problem is that the collision detection does not work for setPosition function.

I tried to send a keyboard (i.e. up key) event to camera, but when I send an event the cam does not stop moving. Anyone got an idea? I could use setTarget too, but seems to cause flickers on view, I'll check it. Here is the code: (press z after running to see the result).

Code: Select all

#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;

f32 DEGTORAD = 0.01745f;
f32 RADTODEG = 1.0f/DEGTORAD;
bool bZ = false;

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 + DEGTORAD, core::PI * .5f);
        Camera->setFOV(newFOV);
        return true;

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

      case irr::KEY_KEY_Z:
		bZ = true;
        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");
    scene::ISceneNode* node =
      smgr->addOctTreeSceneNode(mesh->getMesh(0));
    if (node)
      node->setPosition(core::vector3df(-1300,-144,-1249));
 

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

 //********* Collision *********
	scene::ITriangleSelector* selector = 0;
	if (node)
	{		
		//room->setPosition(core::vector3df(-1370,-130,-1400));
		selector = smgr->createTriangleSelector(mesh->getMesh(0), node);
		node->setTriangleSelector(selector);
		selector->drop();
	}

	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(10,10,10),
		core::vector3df(0,0,0), 
		core::vector3df(0,0,0));
	camera->addAnimator(anim);
	anim->drop();
//********* Collision *********

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

  SEvent event;
  event.EventType = EET_KEY_INPUT_EVENT;
  event.KeyInput.Key = irr::KEY_UP;
  event.KeyInput.PressedDown = true;

	bool bSendEv = true;

  while(device->run())
  {
	  if (bZ)
	  {
		  bZ = 0;
		  camera->OnEvent(event);
	  }


    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() * RADTODEG, pos.X, pos.Y, pos.Z);

      device->setWindowCaption(caption);
    }
  }

  device->drop();

  return 0;
} 
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You need to send the camera a key pressed and a key released event. If you just send it the key pressed event it thinks you are holding the key down.
KG
Posts: 35
Joined: Wed Jun 07, 2006 12:00 am

Post by KG »

You can try device->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(), and then do collision on that line to find the best place to put the camera. I don't think that would produce a good zoom effect, though. It would look really strange if something suddenly walked in front of you.
aerial wrote:If HL2 does not use fov, you better not use it too. I dont remember UT using FOV.
Go search Google for "half-life 2" fov and you'll get lots of results talking about how Half-Life 2's lower than default FOV (75 degrees instead of the 90 used in many games) causes motion sickness. You'll also find instructions about how to change it. If you set it to something really low, such as 15 or 20 degrees, you get a zoom effect that can help aim with weapons that normally can't zoom. For that reason, changing the FOV is locked in multiplayer unless the server has cheats enabled.
ansu832001
Posts: 95
Joined: Thu Mar 01, 2007 6:39 am

Change Position

Post by ansu832001 »

Hi All,

I want to Change the Camera Position when i Zoom in/Out.ANy Idea??

Best Regards.
Post Reply