I decided to go OOP on my project and started to rewrite it from scratch to see how it goes. Here is my problem : when I try to set an MD2 animation to my node everything crashes. Here is my code below:
the cgame.h header:
Code: Select all
#ifndef CGAME_H_INCLUDED
#define CGAME_H_INCLUDED
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
class cgame
{
private:
void setMap(stringw path)
{
IMesh * mapmesh = smgr->getMesh(path);
IMeshSceneNode * map = smgr->addMeshSceneNode(mapmesh);
map->setMaterialFlag(EMF_LIGHTING, false);
}
SIrrlichtCreationParameters setParams()
{
SIrrlichtCreationParameters params;
params.WindowSize = dimension2d<u32>(800,600);
params.DriverType = EDT_OPENGL;
return params;
}
ICameraSceneNode * makeCamera()
{
camera = smgr->addCameraSceneNodeFPS(0);
}
public:
IrrlichtDevice *device = createDeviceEx(setParams());
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
ICameraSceneNode * camera = makeCamera();
cgame(stringw path)
{
setMap(path);
}
// MAKING THE NODE HERE <---
IAnimatedMeshSceneNode * setChar(stringw path, stringw texture_path)
{
IAnimatedMeshSceneNode * charnode = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
charnode->setMaterialTexture(0, driver->getTexture(texture_path));
charnode->setMaterialFlag(EMF_LIGHTING, false);
}
};
#endif
Code: Select all
#include <irrlicht.h>
#include "cgame.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
int main()
{
cgame game("map2.3ds");
IAnimatedMeshSceneNode *character = game.setChar("sydney.md2", "sydney.bmp");
// crash when setting animation
character->setMD2Animation(EMAT_STAND);
while(game.device->run())
{
game.driver->beginScene(true, true, SColor(0,200,200,200));
game.smgr->drawAll();
game.driver->endScene();
}
game.device->drop();
return 0;
}
Cheers!