Code: Select all
//Loads a .bsp
#include<stdlib.h>
#include <irrlicht.h>
#include <windows.h>
#pragma comment (lib,"Irrlicht.lib")
using namespace irr;
using namespace scene;
using namespace gui;
using namespace video;
using namespace core;
void Shoot(void);
class EventReciever:public IEventReceiver
{
public:
virtual bool OnEvent(SEvent Event)
{
if(Event.KeyInput.Key==KEY_ESCAPE)
{
PostQuitMessage(0);
}
if(Event.KeyInput.Key==KEY_SPACE)
{
Shoot();
}
return false;
}
};
EventReciever reciever;
IrrlichtDevice *Device=createDevice(EDT_OPENGL,dimension2d<s32>(480,640),16,false,false,&reciever);
IVideoDriver* Driver=Device->getVideoDriver();
ISceneManager* Smgr=Device->getSceneManager();
ICameraSceneNode* camPlayer=Smgr->addCameraSceneNodeFPS();
ITriangleSelector* tsrSelector;
int main()
{
Device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
IAnimatedMesh* mshLevel=Smgr->getMesh("20kdm2.bsp");
ISceneNode* nodLevel=0;
nodLevel=Smgr->addOctTreeSceneNode(mshLevel->getMesh(0));
tsrSelector=Smgr->createOctTreeTriangleSelector(mshLevel->getMesh(0),nodLevel);
nodLevel->setPosition(vector3df(-1370,-130,-1400));
nodLevel->setTriangleSelector(tsrSelector);
tsrSelector->drop();
nodLevel->setMaterialFlag(EMF_LIGHTING,true);
ISceneNodeAnimator* anmAnim=Smgr->createCollisionResponseAnimator(tsrSelector,camPlayer);
camPlayer->addAnimator(anmAnim);
anmAnim->drop();
while(Device->run())
{
Driver->beginScene(true,true,SColor(100,100,100,100));
Smgr->drawAll();
Driver->endScene();
}
Device->drop();
return 0;
}
void Shoot(void)
{
vector3df start=camPlayer->getPosition();
vector3df end=(camPlayer->getTarget() - start);
end.normalize();
end=start+(end*camPlayer->getFarValue());
triangle3df triTriangle;
line3d<f32> line(start,end);
ISceneNode* nodBullet;
nodBullet=Smgr->addBillboardSceneNode(0,dimension2d<f32>(25,25),start);
nodBullet->setMaterialTexture(0,Device->getVideoDriver()->getTexture("..\\..\\media\\particle.bmp"));
nodBullet->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
if(Smgr->getSceneCollisionManager()->getCollisionPoint(line,tsrSelector,end,triTriangle))
{
ISceneNodeAnimator* anmBullet=0;
anmBullet=Smgr->createFlyStraightAnimator(start,end,2000);
nodBullet->addAnimator(anmBullet);
anmBullet->drop();
anmBullet=Smgr->createDeleteAnimator(2000);
nodBullet->addAnimator(anmBullet);
anmBullet->drop();
}
}