Adding custom parent/child relation in a new 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
jockey
Posts: 6
Joined: Tue Dec 30, 2014 8:06 pm

Adding custom parent/child relation in a new ISceneNode

Post by jockey »

hi,

Am creating my own scenenode (CMyNode) and have a question about the children and rendering a node without any parent. Since I am learning the engine, I need some preventive advice.

The scenenode contains his own custom scenenodes (CMyOtherNode). These 'children' scenenodes shouldn't be accesible outside of this cMyNode class. Therfor the parent of the CMyOtherNode isn't set to the instance of CMyNode nor it it set to sceneManager->getRootSceneNode(). They are not added to ISceneNode::Children but to an array member.

Since both classes decent from ISceneNode I have overridden the OnRegisterSceneNode, as below, for both. Now all m_myOthers are rendered too, yeah.

My question: Is this correct or am I heading towards a nasty bug in my application?

Code: Select all

 
class CMyOtherNode;
class CMyNode : public scene::ISceneNode
{
    core::array<CMyOtherNode*> m_myOthers; // can have nulled entries
    
    public:
    CMyNode ::CMyNode(...) : ISceneNode( parent, sceneManager, id, position, rotation, scale )
    {
 
        for( u32 i = 0; i < 4; --i )
        {
 
            // Add other
            CMyOtherNode* other = new CMyOtherNode( 0, SceneManager ); // No parent!
            m_myOthers.push_back( other );
 
        }
 
    }
    void OnRegisterSceneNode()
    {
         // Same for CMyOtherNode
 
            if( IsVisible )
            {
 
                SceneManager->registerNodeForRendering( this );
 
                u32 size = m_myOthers.size();
                for( u32 i = 0; i < size; ++i )
                    m_myOthers[ i ]->OnRegisterSceneNode();
 
            }
 
        ISceneNode::OnRegisterSceneNode();
 
    }
}
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Adding custom parent/child relation in a new ISceneNode

Post by CuteAlien »

Absolute position functions will likely not regard the parent if it's not a real parent. Not sure if you need that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
jockey
Posts: 6
Joined: Tue Dec 30, 2014 8:06 pm

Re: Adding custom parent/child relation in a new ISceneNode

Post by jockey »

After a quick glance I have rewritten the OnRegisterSceneNode of CMyOtherSceneNode. It does work although it seems a bit lame. There must be a better solution to this.

Code: Select all

 
    CMyNode* CMyOtherNode::m_myNodeParent = instance CMyNode; // ISceneNode::Parent is still 0
    void CMyOtherNode::OnRegisterSceneNode()
    {
 
        if( IsVisible )
        {
 
            setPosition( m_myNodeParent->getAbsolutePosition() );
            setRotation( m_myNodeParent->getAbsoluteTransformation().getRotationDegrees() );
            setScale( m_myNodeParent->getAbsoluteTransformation().getScale() );
            updateAbsolutePosition();
 
            SceneManager->registerNodeForRendering( this );
 
        }
 
        ISceneNode::OnRegisterSceneNode();
 
    }
 
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Adding custom parent/child relation in a new ISceneNode

Post by Mel »

When Irrlicht processes the node hierarchies, the nodes create their local transformation matrix out of the rotation, position and scale vectors, which then multiply by its parent's local transformation matrix to get their own correct transformation, in a nutshell. This goes down to the child list and so on and that's how things go. This is done in the "OnAnimate" method.

What i wonder is what kind of hierarchy do you need that you have to create your own list of nodes to store another nodes? Irrlicht scene nodes handle this on their own very well. It is simpler to just link the nodes as child nodes and process them elsewhere keeping a track of their pointers, but that is what i would do anyway
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply