The only difference is that I didn't put the ninja model in the scene.
Code: Select all
#include "include/irrlicht.h"
using namespace irr;
class EventReceiver: public IEventReceiver{
public:
virtual bool OnEvent(const SEvent &event){
if(event.EventType == irr::EET_KEY_INPUT_EVENT){
keyIsDown[event.KeyInput.Key] == event.KeyInput.PressedDown;
return false;
}
}
virtual bool IsKeyDown(EKEY_CODE keyCode) const{
return keyIsDown[keyCode];
}
EventReceiver(){
for(u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i){
keyIsDown[i] = false;
}
}
private:
bool keyIsDown[KEY_KEY_CODES_COUNT];
};
int main(){
EventReceiver receiver;
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(800, 600), 16, false, false, false, &receiver);
if(!device){
return -1;
}
video::IVideoDriver *driver = device->getVideoDriver();
scene::ISceneManager *smgr = device->getSceneManager();
scene::ISceneNode *node = smgr->addSphereSceneNode();
if(node){
node->setPosition(core::vector3df(0, 0, 30));
node->setMaterialTexture(0,driver->getTexture("wall.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
}
scene::ISceneNode *cube = smgr->addCubeSceneNode();
if(cube){
cube->setMaterialTexture(0, driver->getTexture("t351sml.jpg"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ISceneNodeAnimator *anim = smgr->createFlyCircleAnimator(core::vector3df(0,0,30), 20.0f);
if (anim)
{
cube->addAnimator(anim);
anim->drop();
}
}
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
u32 then = device->getTimer()->getTime();
const f32 MOVEMENT_SPEED = 5.f;
while(device->run()){
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
then = now;
core::vector3df nodePosition = node->getPosition();
if(receiver.IsKeyDown(irr::KEY_KEY_W)){
nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
}
else if(receiver.IsKeyDown(irr::KEY_KEY_S)){
nodePosition.Y -= MOVEMENT_SPEED *frameDeltaTime;
}
else if(receiver.IsKeyDown(irr::KEY_KEY_A)){
nodePosition.X -= MOVEMENT_SPEED *frameDeltaTime;
}
else if(receiver.IsKeyDown(irr::KEY_KEY_D)){
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
}
node->setPosition(nodePosition);
driver->beginScene(true, true, video::SColor(255, 113, 113, 113));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if(lastFPS != fps){
core::stringw tmp(L"Movement [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
Why is this not working?