c++game-developmentirrlicht

Irrlicht: how to convert a ISceneNode into a IMeshSceneNode?


I have got a complex code that is fully loaded with references to ISceneNode objects. I would like to enable shadows for these. However, the function that let us enable shadows is addShadowVolumeSceneNode(), which is only available for the class IMeshSceneNode.

My question is, how do I convert a ISceneNode into a IMeshSceneNode in order to apply shadows to it?

ps: I know it is not possible to apply shadows to a ISceneNode: http://irrlicht.sourceforge.net/forum/viewtopic.php?t=42174


Solution

  • You can cast an ISceneNode pointer to an IMeshSceneNode pointer, if it actually points to an IMeshSceneNode object:

    void AddShadowToSceneNodeIfPossible(ISceneNode* node)
    {
        IMeshSceneNode* meshNode = dynamic_cast<IMeshSceneNode*>(node);
        if (meshNode)
        {
            meshNode->addShadowVolumeSceneNode(...);
        }
    }
    

    But the better solution would be to store IMeshSceneNode pointers as IMeshSceneNode pointers from the start.