Referencing smgr from another class

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
Guest

Referencing smgr from another class

Post by Guest »

In a class called CIrrlichtManager I have this code sniplet:


ISceneManager* smgr = device->getSceneManager();

Then, in another class called CModelManager I want to use that smgr. So I have this:

scene::IAnimatedMesh* weaponMesh = CIrrlichtManager::smgr->getMesh("models/meshFile.obj");

But, that gives me this error:

CModelManager.cpp(13) : error C2227: left of '->getMesh' must point to class/struct/union
type is ''

Obviously it thinks smgr is not a defined? How can I fix this? Thanks.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Well, is CIrrlichtManager::smgr static? If it is, did you allocate memory for it
(as gloabal variable

Code: Select all

ISceneManager* CIrrlichtManager::smgr =0;
)?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

If it is in seperate classes then even doing that won't work. You will need a base class that all the other classes where it is used derive from.
Guest

Post by Guest »

Ah..so say CIrrlicht was my base class, I would do:

class CBlahManager : CIrrlicht

?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

You got it. Make the pointers to stuff like the scene manager virtual so that the child classes can use them and you are away :)
Guest

Post by Guest »

Eh..what do you mean make them virtual? (sorry) :oops:
Guest

Post by Guest »

Also, currently I have this code in a function in CIrrlicht called initIrrlicht.

Code: Select all

IrrlichtDevice* device =		createDevice(EDT_OPENGL, dimension2d<s32>(800,600), 16, false, false, 0);

//Define video driver, GUI environment and scene manager
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

//Create our FPS camera
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 30, 50, -1);
If I want that to be the Irrlicht base class so I can use CBlah : CIrrlicht for child classes, should I move that code into the constructor? or..?

Thanks.
Guest

Post by Guest »

Nevermind, I figured it out :)

Thanks for all the help guys.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Am I missing something? What I showed works fine for me. I have a class called CGame and in it a public member declared like this

Code: Select all

static ISceneManager *smgr;
At the beginning of game.cpp I allocate memory for the static variable like

Code: Select all

ISceneManager *CGame::smgr=0;
In the constructor of my class CPlayer (which does not inherit from CGame) I have

Code: Select all

mesh=CGame::smgr->getMesh("player.x");
All works fine for me.
Post Reply