Page 1 of 1

ISceneNode Inheritance

Posted: Sun Dec 14, 2008 4:01 am
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?

Re: ISceneNode Inheritance

Posted: Sun Dec 14, 2008 5:03 am
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...." ??? ;)

Posted: Sun Dec 14, 2008 9:28 pm
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

Posted: Sun Dec 14, 2008 11:10 pm
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.

Posted: Sun Dec 14, 2008 11:59 pm
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.

Posted: Mon Dec 15, 2008 1:07 am
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() );