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;
}