All help appreciated.
Code: Select all
#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
using namespace irr;
int lcamx;
int lcamy;
int lcamz;
#pragma comment(lib, "Irrlicht.lib")
scene::ISceneNode* player = 0;
IrrlichtDevice* device = 0;
scene::ICameraSceneNode* camera = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT&&
event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
{
core::vector3df w = player->getPosition();
core::vector3df cam = camera->getPosition();
cam.Z -= 1;
w.Z -= 1;
camera->setPosition(cam);
player->setPosition(w);
return true;
}
case KEY_KEY_S:
{
core::vector3df s = player->getPosition();
s.Z += 1;
player->setPosition(s);
return true;
}
case KEY_KEY_A:
{
core::vector3df a = player->getPosition();
a.X += 1;
player->setPosition(a);
return true;
}
case KEY_KEY_D:
{
core::vector3df D = player->getPosition();
D.X -= 1;
player->setPosition(D);
return true;
}
case KEY_KEY_F:
{
core::vector3df f = player->getPosition();
f.Y += 1;
player->setPosition(f);
return true;
}
case KEY_KEY_V:
{
core::vector3df v = player->getPosition();
v.Y -= 1;
player->setPosition(v);
return true;
}
}
}
return false;
}
};
int main()
{
MyEventReceiver receiver;
device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600),
16, false, false, false, &receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
player = smgr->addTestSceneNode(1,0,-1,
core::vector3df(0.0f,0.0f,0.0f));
player->setPosition(core::vector3df(0,1,0));
player->setMaterialTexture(0, driver->getTexture("media/dummy.bmp"));
//device->getCursorControl()->setVisible(false);
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,1200.0f);
core::vector3df px = player->getPosition();
lcamx = px.X;
lcamy = px.Y;
lcamz = px.Z;
camera->setPosition(core::vector3df(lcamx,lcamz + 3,lcamy + 2));
camera->setTarget(player->getPosition());
camera->setFarValue(10000.0);