Okay, here's my whole code. I use two
#defines to activate or deactivate parts of the code without having to comment or decomment lots of stuff every time, so:
#ifdef TRIANGLESELECTOR encloses the collision code I copied from this topic
#ifdef THIS_CAUSES_A_CRASH encloses the actual line that causes the program to crash if it is compiled
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")
#define TRIANGLESELECTOR
#define THIS_CAUSES_A_CRASH
int main()
{
IrrlichtDevice *device = createDevice(EDT_OPENGL,dimension2d<s32>(800,600),32,true,false,false,0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
smgr->addLightSceneNode(0, core::vector3df(0,0,0),video::SColorf(1.0f,1.0f,1.0f,1.0f), 50000.0f);
// Desert
IAnimatedMesh* mesh9 = smgr->getMesh("modelli/deserto1.3ds");
IAnimatedMeshSceneNode* node9 = smgr->addAnimatedMeshSceneNode( mesh9 );
if (node9)
{
node9->setMaterialFlag(EMF_LIGHTING, false);
node9->setFrameLoop(0, 310);
node9->setMaterialTexture( 0, driver->getTexture("modelli/deserto1.bmp") );
node9->setPosition(core::vector3df(0,-123,272));
}
// Pyramid
IAnimatedMesh* mesh10 = smgr->getMesh("modelli/piramide1.x");
IAnimatedMeshSceneNode* node10 = smgr->addAnimatedMeshSceneNode( mesh10 );
if (node10)
{
node10->setMaterialFlag(EMF_LIGHTING, true);
node10->setFrameLoop(0, 310);
node10->setMaterialTexture( 0, driver->getTexture("modelli/piramide.bmp") );
node10->setPosition(core::vector3df(0,-2,1000));
// node10->setScale(core::vector3df(10,10,10));
}
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
camera->setFarValue(120000.0f);
device->getCursorControl()->setVisible(false);
#ifdef TRIANGLESELECTOR
scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
scene::ITriangleSelector * selector1 = 0;
camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta, camera, core::vector3df(30,30,30),core::vector3df(0,-3,0),core::vector3df(0,50,0));
meta->drop();
camera->addAnimator(anim);
anim->drop();
scene::ISceneNodeAnimator* an = smgr->createCollisionResponseAnimator(selector1, camera, core::vector3df(30,30,30),core::vector3df(0,0,0),core::vector3df(0,50,0));
#ifdef THIS_CAUSES_A_CRASH
selector1->drop();
#endif
camera->addAnimator(an);
an->drop();
#endif
while(device->run())
{
driver->beginScene(true, true, SColor(255,50,101,190));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
For all that's worth, I also uploaded the models I used, and you can get them from
here. Just unzip the file to the same directory of the executable. The models and their textures will be placed in a subdirectory called "modelli".