own classes with irrlicht objects in it

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
muxxxa
Posts: 3
Joined: Wed Jun 29, 2005 5:34 pm

own classes with irrlicht objects in it

Post by muxxxa »

hi,
first: please excuse my bad english.
I recently started with Irrlicht and I wanted to do a fps. I started and when I was ready with the collision, I noticed that my project wasn't really too good structured. So I started the project new and wanted to make some classes to have 'good c++ style'. But now I've got another problem: I can compile it under Dev-Cpp and then execute it. But there's only a black screen and there comes an error message that says something wants to read '0xffffffff'. When I use Dev-Cpp's debugging mode the screen turns white and it only says that there was a segmention fault. I don't know what to do. Perhaps you could help me. Thx.
Here's the code:

main.cpp

Code: Select all

#include <irrlicht.h>

#include "graphics.h"

using namespace irr;

int main(){
    system sys;
    
    map simple_room(sys);
    simple_room.lighting(false);
    
    sys.fpscamera();
    sys.cursorVisible(false);
    
    while(sys.active()){
                        sys.begin();
                        sys.draw();
                        sys.end();
    }
}
graphics.h

Code: Select all

#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_

#include <irrlicht.h>

using namespace irr;

class map;
class system;

class system{
      protected:
                IrrlichtDevice *device;
                video::IVideoDriver *driver;
                scene::ISceneManager *manager;
      public:
             system(){
                 device = createDevice(video::EDT_OPENGL,core::dimension2d<s32>(1600,1200),16,true,false,false);
                 driver = device->getVideoDriver();
                 manager = device->getSceneManager();
             }
             
             ~system(){
                       device->drop();
             }
             
             scene::IAnimatedMesh* mesh(const c8* name){
                                   return manager->getMesh(name);
             }                      
             
             scene::ISceneNode* bigNode(scene::IAnimatedMesh* m){
                                return manager->addOctTreeSceneNode(m->getMesh(0));
             }
             
             void fpscamera(){
                  manager->addCameraSceneNodeFPS();
                  return;
             }
             
             void cursorVisible(bool visible){
                  device->getCursorControl()->setVisible(visible);
                  return;
             }
             
             bool active(){
                  return device->run();
             }
             
             void begin(){
                  driver->beginScene(true,true,video::SColor(0,200,200,200));
                  return;
             }
             
             void end(){
                  driver->endScene();
                  return;
             }
             
             void draw(){
                  manager->drawAll();
                  return;
             }
};

class map{
      friend scene::ISceneNode* bigNode(scene::IAnimatedMesh*);
      protected:
                scene::IAnimatedMesh* mesh;
                scene::ISceneNode* node;
      public:
             map(system s){
                        mesh = s.mesh("maps/simple_room.x");
                        node = 0;
                        node = s.bigNode(mesh);
             }
             
             void lighting(bool activated){
                  node->setMaterialFlag(video::EMF_LIGHTING,activated);
                  return;
             }     
             
             scene::IAnimatedMesh* returnMesh(){
                                   return mesh;
             }
             
};
#endif
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

I couldn't catch anything that would be crashing, but I didn't take the time to set it up in VC to test it. I recommend you inline your functions so that it runs faster though.
________
Eddie irvine
Last edited by disanti on Thu Feb 24, 2011 10:33 am, edited 1 time in total.
NexusInteractive
Posts: 33
Joined: Sun Jun 26, 2005 4:41 pm

Post by NexusInteractive »

I dont have an answer to your question, but that is a good idea. I never thought of making your own classes.

Perhaps I will try this soon. It gets hard for me to read C++ once everything gets going. :P
Computer Specs:
AMD Duron 1.8 GHZ + 256 MB RAM + ATI Radeon 7000 Series + 20gig HDD + PCChips K7 MotherBoard
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, I create my own classes by subclassing the wanted Irrlicht classes !!!
So you have the original Irrlicht objects (classes) and you can add own vars and functions to it...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
muxxxa
Posts: 3
Joined: Wed Jun 29, 2005 5:34 pm

Post by muxxxa »

So does this mean my version doesn't work? if not why?
eXodus
Posts: 320
Joined: Tue Jan 04, 2005 10:07 am
Location: Canada
Contact:

Post by eXodus »

Code: Select all

class map{
      public:
             map(system s){
                    ...
             }
};
Try passing a reference of your 'system' object.
muxxxa
Posts: 3
Joined: Wed Jun 29, 2005 5:34 pm

Post by muxxxa »

thank you so much, eXodus, now it works.
I changed the part in graphics.cpp to

Code: Select all

             ...
map(system *s){
                        mesh = s->mesh("maps/simple_room.x");
                        node = 0;
                        node = s->bigNode(mesh);
             }
...
and in main.cpp to

Code: Select all

...
    map simple_room(&sys);
...
thx
eXodus
Posts: 320
Joined: Tue Jan 04, 2005 10:07 am
Location: Canada
Contact:

Post by eXodus »

You're welcome! It's been a while since I helped someone on the forum :)
Post Reply