Problem accessing to SceneNodes

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
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Problem accessing to SceneNodes

Post by Ryoga2k »

Hi,

I'm making a class to encapsulate the main actions I´ll use in my game. This class will be the only one that access the Irrlich engine.

To add a player to the scene, I have the following method:

Code: Select all

bool CGameEngine::AddPlayerToScene (char *model,int playerID)
{	
   IAnimatedMesh *pMesh = pScene->getMesh(model);

   if (pMesh == NULL)
      return false;
	
   IAnimatedMeshSceneNode *pNode = pScene->addAnimatedMeshSceneNode(pMesh,playersOrigin,playerID);

   if (pNode == NULL)
      return false;

   return true;
}
PlayersOrigin is the SceneNode parent of all players. Well, to set the new position for a player I use this other method:

Code: Select all

bool CGameEngine::SetPlayerPosition(int playerID, vector3df position)
{
   ISceneNode *pNode = pScene->getSceneNodeFromId(playerID,playersOrigin);

   if (pNode == NULL)
      return false;	

   pNode->setPosition(position);

   return true;
}
When I call the AddPlayerToScene, the player is loaded and showed into the scene, ok. The problem is that, when I call to SetPlayerPosition, the program crashes (not during the call, but while rendering - maybe a lost pointer?).

Is my code correct? Is there other way to do this? Help me, please.
Last edited by Ryoga2k on Sat Jun 19, 2004 9:04 pm, edited 1 time in total.
"There's always a way, if desire meets courage"
Conan of Cimmeria
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Hmm, not sure but I think you have to pas pointer to scenemanager (smgr) to your function.

Here is my sample which is class for creating and manipulating asteroid object:

declaration:

Code: Select all

class rockObject
{
   public:
   rockObject(irr::IrrlichtDevice* device,  const irr::c8 *filename,
      float X = 0, float Y = 0, float Z = 0, float xs1 = 0, float ys1 = 0, float zs1 = 0);
      
   ~rockObject();
   
   void control();
   
   protected:
   irr::core::vector3df rotation;
   irr::scene::IAnimatedMesh *mesh;
   irr::scene::IAnimatedMeshSceneNode *node;
};
constructor:

Code: Select all

rockObject::rockObject(irr::IrrlichtDevice* device,  const irr::c8 *filename, 
   float X, float Y, float Z, float xs, float ys, float zs)
{
   rotation = irr::core::vector3df(xs, ys, zs);
   
   mesh = device->getSceneManager()->getMesh(filename);
   node = device->getSceneManager()->addAnimatedMeshSceneNode(mesh);
   if (node)
   {
      node->setMaterialFlag(irr::video::EMF_LIGHTING, true);
      node->setPosition(irr::core::vector3df(X,Y,Z));
   }
}
You see that I had to pass IrrlichtDevice pointer to function in order to use it for loading mesh and creating node. You should do the same with scenemanager may be....
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

Yes, I know a pointer to the sceneManager is needed. But my CGameEngine class has several members which are pointers to the main elements of the Irrlicht Engine. It's something like this:

Code: Select all

class CGameEngine
{
private:
   IrrlichtDevice *m_pEngine;
   IVideoDriver *m_pDriver;
   ISceneManager *m_pScene;
   IGUIEnvironment *m_pGui;
   IFileSystem *m_pFileSystem;

   ISceneNode *m_pMainOrigin;
   ISceneNode *m_pPlayersOrigin;

   // ... many other members

public:
   CGameEngine(...);
   ~CGameEngine();

   bool InitEngine(...);
   bool SetMainOrigin (...);
   bool SetPlayersOrigin (...);

   bool AddPlayerToScene(char *model,int playerID);
   bool SetPlayerPosition(int playerID, vector3df position);
   bool SetPlayerAnimation(int playerID, char *animationName);

   bool Render();

   // ... many other methods
};
In fact, the AddPlayerToScene method works properly, but the SetPlayerPosition doesn't :?
"There's always a way, if desire meets courage"
Conan of Cimmeria
Post Reply