ly000 Temat założony przez niniejszego użytkownika |
[irrlicht] Problem z klasami » 2012-06-14 19:32:58 Witam, postanowiłem przenieść irrlicht w klasy, lecz niestety słaby jestem w posługiwaniu się klasami, dlatego coś mi to nie idzie. Kod: main.h #ifndef MAIN_H_INCLUDED #define MAIN_H_INCLUDED #include <irrlicht.h> #include <iostream> using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui;
class irr_init { public: IrrlichtDevice * device; IVideoDriver * driver; ISceneManager * smgr; IGUIEnvironment * guienv; IAnimatedMesh * mesh; IAnimatedMeshSceneNode * node; public: void go(); };
class irr_gui : public irr_init { public: void go(); };
class irr_gfx : public irr_init { public: void model(); void camera(); void draw(); };
#endif
main.cpp #include "main.h"
void irr_init::go() { device = createDevice( EDT_OPENGL, dimension2d < u32 >( 640, 480 ), 32, false, false, false, 0 ); device->setWindowCaption( L"Hello World! - Irrlicht Engine Demo" ); driver = device->getVideoDriver(); smgr = device->getSceneManager(); guienv = device->getGUIEnvironment(); }
void irr_gui::go() { guienv->addStaticText( L"TEST", rect < int >( 0, 0, 300, 80 ), true ); }
void irr_gfx::model() { mesh = smgr->getMesh( "E:/Altair Model/model.3ds" ); node = smgr->addAnimatedMeshSceneNode( mesh ); node->setMaterialFlag( EMF_LIGHTING, true ); }
void irr_gfx::camera() { smgr->addCameraSceneNode( 0, vector3df( 20, 100, - 60 ), vector3df( 0, 120, 0 ) ); smgr->setAmbientLight( video::SColorf( 0.6, 0.6, 0.6 ) ); }
void irr_gfx::draw() { while( device->run() ) { driver->beginScene( true, true, SColor( 0, 200, 200, 200 ) ); smgr->drawAll(); guienv->drawAll(); node->setPosition( vector3df( 0, 00, 0 ) ); driver->endScene(); } device->drop(); }
int main( int argc, char ** argv ) { irr_init init; irr_gfx gfx; init.go(); std::cout << "init.go"; gfx.model(); std::cout << "gfx.model"; gfx.camera(); std::cout << "gfx.camera"; gfx.draw(); std::cout << "gfx.draw"; return 0; }
Po jego uruchomieniu, program dochodzi do funkcji init.go(), a następnie wywala typowy windowsowski błąd z "Wyślij raport", (zapomniałem jak on się nazywa dokładnie). Więc co chodzi? Podejrzewam, że namieszałem coś z wskaźnikami. Z góry dziękuje za pomoc. |
|
Admixior |
» 2012-06-14 21:47:21 Sprawdź w tej funkcji czy wartość zwrócona przez createdevice jest dobra (czy device nie jest null lub nie ma kodu błędu, sprawdź jak to jest w dokumentacji). Chociaż ja bardziej obstawiam że to nie twoja funkcja zawodzi gdyż debugger zgłosił by: 0x2f5468a2 has access to memory 0x00000000, czy coś podobnego. Sprawdź czy funkcje wywoływane są dobre, ew. czy biblioteki których używasz po twoją appke, twój system itp |
|
ly000 Temat założony przez niniejszego użytkownika |
» 2012-06-14 21:57:12 Sama biblioteka raczej nie ma tu nic do rzeczy. Wszystkie funkcje z mego kodu działały normalnie przed opakowaniem ich w klasy. |
|
Admixior |
» 2012-06-14 22:25:24 A mógłbyś podrzucić kod który działał sprawnie. Wtedy zobaczy się różnice. |
|
ly000 Temat założony przez niniejszego użytkownika |
» 2012-06-14 22:33:23 Nie ma problemu. Proszę: #include <irrlicht.h> using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui;
int main( int argc, char ** argv ) { IrrlichtDevice * device = createDevice( EDT_OPENGL, dimension2d < u32 >( 640, 480 ), 32, false, false, false, 0 ); device->setWindowCaption( L"Hello World! - Irrlicht Engine Demo" ); IVideoDriver * driver = device->getVideoDriver(); ISceneManager * smgr = device->getSceneManager(); IGUIEnvironment * guienv = device->getGUIEnvironment(); guienv->addStaticText( L"TEST", rect < int >( 0, 0, 300, 80 ), true ); IAnimatedMesh * mesh = smgr->getMesh( "E:/Altair Model/model.3ds" ); IAnimatedMeshSceneNode * node = smgr->addAnimatedMeshSceneNode( mesh ); node->setMaterialFlag( EMF_LIGHTING, true ); smgr->addCameraSceneNode( 0, vector3df( 20, 100, - 60 ), vector3df( 0, 120, 0 ) ); smgr->setAmbientLight( video::SColorf( 0.6, 0.6, 0.6 ) ); while( device->run() ) { driver->beginScene( true, true, SColor( 0, 200, 200, 200 ) ); smgr->drawAll(); guienv->drawAll(); node->setPosition( vector3df( 0, 00, 0 ) ); driver->endScene(); } device->drop(); return 0; }
Ten kod robi dokładnie to samo co tamten ma zamiar zrobić. |
|
« 1 » |