[img]http://spic.uploadd.com/2032/E75/small/35AF59CEB2QWPEV4U[GQIIK5ARG6L[test.jpg[/img]
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
IrrlichtDevice *device;
bool shoot=false;
class MyEventReceiver : public IEventReceiver
{
public:
bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
event.KeyInput.PressedDown == false)
{
device->closeDevice();
return true;
}
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
shoot=true;
return true;
}
shoot=false;
return false;
}
};
int main()
{
MyEventReceiver receiver;
device = createDevice(EDT_DIRECT3D9,dimension2d<s32>(800,600),32,
true, false, false,&receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* env = device->getGUIEnvironment();
IAnimatedMesh* mesh = smgr->getMesh("map.b3d");
ISceneNode* node;
device->getCursorControl()->setVisible(false);
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
node->setPosition(vector3df(0,-50,0));
ITriangleSelector* selector;
selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 32);
node->setTriangleSelector(selector);
env->addImage(driver->getTexture("cur.png"),position2d<s32>(385,285));
SKeyMap keyMap[4];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_KEY_W;
keyMap[1].Action = EKA_MOVE_BACKWARD;
keyMap[1].KeyCode = KEY_KEY_S;
keyMap[2].Action = EKA_STRAFE_LEFT;
keyMap[2].KeyCode = KEY_KEY_A;
keyMap[3].Action = EKA_STRAFE_RIGHT;
keyMap[3].KeyCode = KEY_KEY_D;
ICameraSceneNode* camera =smgr->addCameraSceneNodeFPS(0,100,300,-1,keyMap,4);
camera->setPosition(vector3df(0,50,0));
ISceneNodeAnimator* anim =smgr->createCollisionResponseAnimator(
selector, camera, vector3df(30,30,30),
vector3df(0,-2,0),
vector3df(0,30,0));
camera->addAnimator(anim);
selector->drop();
anim->drop();
IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture("bull.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setSize(dimension2d<f32>(10.0f, 10.0f));
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,0,0,100));
smgr->drawAll();
env->drawAll();
line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start +(camera->getTarget() - line.start).normalize() * 1000.0f;
vector3df intersection;
triangle3df tri;
if (smgr->getSceneCollisionManager()->getCollisionPoint(
line, selector, intersection ,tri))
{
if(shoot==true){
bill->setPosition(intersection);
}
}
driver->endScene();
}
device->drop();
return 0;
}