Inherit from ISceneNode?

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
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Inherit from ISceneNode?

Post by danielmccarthy »

How would I inherit from ISceneNode? Their are so many virtual functions. All I want to do is be able to extend the ISceneNode for my player class and my object class so they can have their own custom functions in the scene node

Thanks,
Dan
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Inherit from ISceneNode?

Post by Seven »

not sure of your experience, so take this with a grain of salt.......

one thing to research is the theory behind whether the player is a scenenode, or whether the player has a scenenode.
if the player (is) a scenenode, then you should derive from scenenode, however, if the player only (has) a scenenode, it might be better to create an object class that houses a scenenode.

I find that it normally (has) a scenenode. this allows me to do things like

object_class campfire
has a 'stack of wood' scenenode
has a 'particle fire' scenenode
has a 'smoke trail' scenenode
has a 'crackling fire sound' wave file
has a physX representation (trigger)

and the likes. If I tried to derive campfire from IScenenode, I would soon get bogged down in the implementation because the scenenode now needs to know about all of the other systems in the game, like the sounds and physx engine.

instead, I just create an object class and it creates / manages / and destroys all of the scenenodes, sounds, physx, etc...

my $0.02 worth.....
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Inherit from ISceneNode?

Post by danielmccarthy »

I see your point. At the moment it does house the scene node. I have an object class and my player class extends that class. The object class houses the scene node. My problem is when using things like rays it will return a scenenode so I cannot reference to my object class. Any tips?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Inherit from ISceneNode?

Post by Seven »

if you decide to derive from ISceneNode, the easiest would be to locate the CSceneNode.H and CSceneNode.cpp files, copy and rename them, and then modify them as you need.
or the CAnimatedMeshSceneNode files, or the CParticleSceneNode files, etc........
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Inherit from ISceneNode?

Post by danielmccarthy »

But you think its a bad idea to derive do you know a way to keep it housed and still use the ray?

One of my old ideas and what I was doing originally was to split the 32 bit ID into 16 bits and use the lower 16 bits as the type and the upper 16 bits as the ID. Then you just set the id using setID. Is their like any type functions in irrlicht like setNodeType or something?
Last edited by danielmccarthy on Fri Jul 25, 2014 8:31 pm, edited 1 time in total.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Inherit from ISceneNode?

Post by Seven »

yes, tips.........

i have object class that has multiple scenenodes, sounds, physx etc....
each object has a 'primaryscenenode" that I use for identifying the object.

in this class, I have a function called

Code: Select all

 
    void CSObject::setId(int id)
    {
        m_Id = id;
        if (getPrimarySceneNode()) getPrimarySceneNode()->setID(id);
        if (getPhysXObject()) getPhysXObject()->setUserData(id);
        if (m_Children)
        {
            CSObject* obj = m_Children->getNextObject(true);
            while (obj)
            {
                obj->setId(id);
                obj = m_Children->getNextObject(false);
            }
        }
    }
 
as you can see, I set the objects ID, the primaryscenenode, the PHYSX object and all of the children to the same ID number

now, if the editor wants to select an object, i can use the normal picknode functions and I get an ID back (this is the normal primaryscenenode->getID().
all I have to do is search the list of objects and find the one with the same ID
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Inherit from ISceneNode?

Post by danielmccarthy »

I see what you mean like an object container?

Ok thanks mate
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Inherit from ISceneNode?

Post by Seven »

the good thing about this system, is that I allow the user to select via scenenode OR via physx structures.
since the object::id == physx::id == scenenode::id

it is easy to select by any method and then convert to the object instance for manipulating.
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Inherit from ISceneNode?

Post by danielmccarthy »

Say I wanted to modify the source of irrlicht instead and add a setNodeType method inside the ISceneNode. How would I do that since the only files I see in the irrlicht source is CAnimatedMeshSceneNode. I do not see any CSceneNode file or anything.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Inherit from ISceneNode?

Post by Seven »

danielmccarthy wrote:Say I wanted to modify the source of irrlicht instead and add a setNodeType method inside the ISceneNode. How would I do that since the only files I see in the irrlicht source is CAnimatedMeshSceneNode. I do not see any CSceneNode file or anything.

i think iscenenode is just an interface and all scenenodes are derived from it...

you need to modify ISceneNode.h and then all scenenodes will auto have your additions.
this might be a slippery slope that you are going down so be careful :)
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Inherit from ISceneNode?

Post by danielmccarthy »

Yeah I think your right. I think maybe if I use 16 bits of the ID for the type and 16 bits for the ID would that make sense? Thats what is was before but I thought it was a bit hacky
Post Reply