Code: Select all
#include <irrlicht.h>
#include <iostream>
#include <string>
#include "shadermaterial.h"
#include "shadergroup.h"
using namespace irr;
using namespace video;
using namespace scene;
using namespace core;
using namespace gui;
int rolka_g = 0;
bool poxl = false;
bool poxr = false;
ShaderGroup* hdr = 0;
//================================================================================
// funkcje kamery :)
void makeCockpit(irr::scene::ICameraSceneNode *camera,
irr::scene::ISceneNode *node,
irr::core::vector3df offset)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
m.transformVect(frv);
irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
m.transformVect(upv);
m.transformVect(offset);
offset += node->getPosition();
camera->setPosition(offset);
camera->setUpVector(upv);
offset += frv;
camera->setTarget(offset);
camera->updateAbsolutePosition();
}
void move(irr::scene::ISceneNode *node, irr::core::vector3df vel)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
m.transformVect(vel);
node->setPosition(node->getPosition() + vel);
node->updateAbsolutePosition();
}
void rotate(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
irr::core::matrix4 n;
n.setRotationDegrees(rot);
m *= n;
node->setRotation( m.getRotationDegrees() );
node->updateAbsolutePosition();
}
void turn(irr::scene::ISceneNode *node, irr::f32 rot)
{
rotate(node, irr::core::vector3df(0.0f,rot,0.0f) );
}
//==================================================================================
//==================================================================================
// event reciever
bool keys[KEY_KEY_CODES_COUNT];
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if(event.EventType == EET_MOUSE_INPUT_EVENT)
{
if(event.MouseInput.Wheel > 0)
{
rolka_g = 1;
return true;
}
if(event.MouseInput.Wheel < 0)
{
rolka_g = 2;
return true;
}
return false;
}
if(event.EventType == EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
return true;
}
};
int main()
{
//=============================================================================
//START SILNIKA
MyEventReceiver receiver;
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1280,1024),32,true,false,false,& receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getCursorControl()->setVisible(false);
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
//===============================================================================
//===============================================================================
// DODAWANIE ELEMENTÓW
ISceneNode* skyboxNode;
skyboxNode = smgr->addSkyBoxSceneNode(
driver->getTexture("irrlicht2_up.jpg"),
driver->getTexture("irrlicht2_dn.jpg"),
driver->getTexture("irrlicht2_lf.jpg"),
driver->getTexture("irrlicht2_rt.jpg"),
driver->getTexture("irrlicht2_ft.jpg"),
driver->getTexture("irrlicht2_bk.jpg"));
IAnimatedMesh* mesh1 = smgr->getMesh("czlowiek1.x");
ISceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh1 );
node1->setMaterialFlag(EMF_LIGHTING, false);
node1->setMaterialTexture( 0, driver->getTexture("czlowiek1.jpg") );
node1->setPosition(vector3df(0.0f,0.0f,-50.0f));
IAnimatedMesh* mesh2=smgr->getMesh("mapa1.x");
ISceneNode* node2=smgr->addOctTreeSceneNode(mesh2->getMesh(0));
//video::ITexture* colorMap = driver->getTexture("Floor11.jpg");
//node2->setMaterialTexture(0, colorMap);
node2->setMaterialFlag(EMF_LIGHTING, false);
hdr = new ShaderGroup(device, smgr);
hdr->add(node2);
scene::ICameraSceneNode *camera = device->getSceneManager()->addCameraSceneNode();
camera->setFarValue(100000);
//===================================================================================
//===================================================================================
// KOLIZJA
scene::ITriangleSelector* selector = 0;
selector = smgr->createOctTreeTriangleSelector(mesh2->getMesh(0), node2, 128);
node2->setTriangleSelector(selector);
selector->drop();
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, node1, core::vector3df(15,50,20),
core::vector3df(0,-3,0),core::vector3df(0,-50,-5),0.002);
node1->addAnimator(anim);
anim->drop();
vector3df poz = vector3df(10,60,-50);
while(device->run())
{
hdr->render();
//==============================================================================
//przesówanie - na boki :)
if(keys[irr::KEY_KEY_O])
{
hdr->range += .01f;
}
if(keys[irr::KEY_KEY_L])
{
hdr->range -= .01f;
}
if (poxl == true)
{
printf("ruch w lewo");
poxl=false;
}
if (poxr == true)
{
printf("ruch w prawo");
poxr = false;
}
if (rolka_g == 1)
{
if (poz == vector3df(10,60,-10))poz = vector3df(poz.X,poz.Y,poz.Z);
else poz = vector3df(poz.X,poz.Y,poz.Z+5);
rolka_g = 0;
}
if (rolka_g == 2)
{
if (poz == vector3df(10,60,-70))poz = vector3df(poz.X,poz.Y,poz.Z);
else poz = vector3df(poz.X,poz.Y,poz.Z-5);
rolka_g = 0;
}
if(keys[irr::KEY_KEY_D])
{
turn(node1, 1.5);
}
if(keys[irr::KEY_KEY_A])
{
turn(node1, -1.5);
}
// przód i tył
if(keys[irr::KEY_KEY_W])
{
if(keys[irr::KEY_SHIFT])
{
move(node1, core::vector3df(0,0,3.0));
}
else move(node1, core::vector3df(0,0,1.0));
}
if(keys[irr::KEY_KEY_S])
{
move(node1, core::vector3df(0,0,-1.0));
}
//strafy
if(keys[irr::KEY_KEY_Q])
{
if(keys[irr::KEY_SHIFT])move(node1, core::vector3df(-2.0,0,0));
else move(node1, core::vector3df(-1.0,0,0));
}
if(keys[irr::KEY_KEY_E])
{
if(keys[irr::KEY_SHIFT])move(node1, core::vector3df(2.0,0,0));
else move(node1, core::vector3df(1.0,0,0));
}
//===============================================================================
makeCockpit(camera, node1, poz);
}
device->drop();
return 1;
}
I can't compile it. It running and then... error
I'm using dev-cpp.