ISceneNode Inheritance

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
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

ISceneNode Inheritance

Post by knicholes »

I wrote a working text-based version of an 8 puzzle, but I want to add graphics using irrlicht. I don't want to have to re-write everything, so I want to just inherit my Tile (the pieces you move around) class from the ISceneNode class. I have this as my simple and initial attempt to inherit.

Code: Select all

class Tile : public ISceneNode
{
public:
	Tile();
	Tile(ISceneNode*,ISceneManager*,s32,const core::vector3df &,const core::vector3df &,
		const core::vector3df &);
	
	
private:
	int x;
	int y;
};

Tile::Tile(ISceneNode* parent,ISceneManager* mgr,s32 id = -1,
const core::vector3df & 	position = core::vector3df(0,0,0),
const core::vector3df & 	rotation = core::vector3df(0,0,0),
const core::vector3df & 	scale = core::vector3df(1.0f, 1.0f, 1.0f))
	:ISceneNode(parent, mgr, id, position, rotation, scale),x(0),y(0){};
Later on I try to declare this new class I've created with the following code:

Code: Select all

Tile* n = smgr->addCubeSceneNode();
I get the error:
error: invalid conversion from `irr::scene::ISceneNode*' to `
Tile*'

What am I doing wrong?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: ISceneNode Inheritance

Post by Acki »

knicholes wrote:Tile::Tile(ISceneNode* parent,ISceneManager* mgr,s32 id = -1,
const core::vector3df & position = core::vector3df(0,0,0),
const core::vector3df & rotation = core::vector3df(0,0,0),
const core::vector3df & scale = core::vector3df(1.0f, 1.0f, 1.0f))
:ISceneNode(parent, mgr, id, position, rotation, scale),x(0),y(0){};
this looks bad, I wonder you don't get an error message about it... :shock:
in the implementation of a function (here the constructor) you must not set default values, you do this with the declaration !!!
knicholes wrote:I get the error:
error: invalid conversion from `irr::scene::ISceneNode*' to `
Tile*'
are there any further errors, usually after this comes a line "because...." ??? ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

knicholes wrote:

Code: Select all

Tile* n = smgr->addCubeSceneNode(); 
The problem is that ISceneManager::addCubeSceneNode() doesn't return a Tile*, it returns an ISceneNode*. If you want a Tile, you need to create one...

Code: Select all

Tile* tile = new TileSceneNode(parent, smgr);
Travis
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Post by knicholes »

Cool, thanks for the help guys! I realized it's because I needed to just do a static_cast<Tile*> to the smgr pointer.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Uh, no. Based on what you've shown us, you've created a CCubeSceneNode, not a Tile. Casting it won't change that.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Try encapsulating:

Code: Select all

class Tile
{
public:
   Tile(ISceneNode*Node)
      : node(Node), x(0), y(0)
   {}
   
private:
   ISceneNode * node;
   int x;
   int y;
}; 

Code: Select all

Tile * n = new Tile( smgr->addCubeSceneNode() ); 
Post Reply