Irrlicht: how to convert a ISceneNode into a IMeshSceneNode?

157 Views Asked by At

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

1

There are 1 best solutions below

4
Max Vollmer On BEST ANSWER

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.