What you did was move your mesh and node variables to be local to that function only. With that style of function, you would need to make smgr, mesh and node global. Another method would be to simply pass them as parameters.
With the variables global:
Code: Select all
int CreateMesh()
{
mesh = smgr->getMesh("arrow.3ds");
node = smgr->addAnimatedMeshSceneNode( mesh );
}
This is a (preferred) method to do it:
Code: Select all
IAnimatedMeshSceneNode* node CreateMesh(IAnimatedMesh* mesh, ISceneManager *smgr)
{
node = smgr->addAnimatedSceneNode( mesh );
return node;
}
I personally have seperated out the scene building portions of my code out into several classes, one of which adds the "actors" (people/vehicle shaped models). A quick massively snipped implementation (and probably won't compile as I'm creating this from memory):
Code: Select all
class MySceneLoader
{
private:
core::array<*IAnimatedMesh> mesh;
core::array<*IAnimatedSceneNode> sceneNodes;
scene::ISceneNodeManager *sceneMan;
public:
bool LoadMesh();
bool LoadMesh( char * );
}
//Implementation
bool LoadMesh()
{
bool succeed = LoadMesh("arrow.3ds");
return succeed;
}
bool LoadMesh(char * filename)
{
int meshSize = mesh->size();
int sceneNodesSize = sceneNodes->size();
mesh->push_back(sceneMan->getMesh(filename));
if( meshSize < mesh->size() )
sceneNodes->push_back(
sceneMan->addAnimatedMeshSceneNode( mesh->last() );
if( sceneNodesSize < sceneNodes->size() )
return true;
return false;
}
Please note that this is typed up during my lunch break at work, it's meant as a guide only, not cut and pastable code (as I probably screwed up namespaces or what Irrlicht's specific function name is or something).
Hopefully this is enough of an example to get you back on track. I highly suggest going to google and putting in "C++ tutorial scope" and fully understanding that before moving much further on. It shouldn't take a long time to fully grasp, but will save tons of headaches later on.