Code: Select all
#include <irrlicht.h>
using namespace irr;
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
MyEventReceiver receiver;
int main()
{
IrrlichtDevice* device = 0;
device = createDevice( video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
if (device == 0)
return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
cam->setPosition(core::vector3df( 9, 12, 27));
cam->setTarget(core::vector3df( 9, 11,5));
device->getCursorControl()->setVisible(false);
scene::SMesh *mesh = new scene::SMesh();
scene::SMeshBuffer * meshbuf = new scene::SMeshBuffer();
video::S3DVertex a(0,20, -50, 1,1,0, video::SColor(255,0,255,255), 0, 1);
video::S3DVertex b(0,0, -50, 1,0,0, video::SColor(255,255,0,255), 1, 1);
video::S3DVertex c(20,0,-50, 0,1,1, video::SColor(255,255,255,0), 1, 0);
video::S3DVertex d(20,20, -50, 0,0,1, video::SColor(255,0,255,0), 0, 0);
video::S3DVertex ver2[] = {a,b,c,d};
u16 indices[] = {0, 1, 2, 2, 3, 0};
mesh->addMeshBuffer(meshbuf);
meshbuf->append((const void*)&ver2, 4, (u16*)&indices, 6);
scene::IMeshSceneNode* Node = smgr->addMeshSceneNode(mesh);
Node->setMaterialFlag(video::EMF_LIGHTING, false);
int lastFPS = -1;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"[";
str += " FPS: ";
str += fps;
str += "]";
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
device->sleep(50);
}
device->drop();
return 0;
}