0

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 Answer 1

2

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.

4
  • Just one more question: under which condition dynamic_cast<IMeshSceneNode*>(node) fails? In my code (i mentioned above in my question) it fails the casting process ( i know that because I added an else {cout<<"hi!"} to your code snippet)
    – PintoDoido
    Commented Aug 31, 2018 at 16:03
  • 1
    @PintoDoido It returns nullptr for any ISceneNode* that is not an IMeshSceneNode*. Not every ISceneNode* is an IMeshSceneNode*, there's IParticleSystemSceneNode* or ILightSceneNode* or also IShadowVolumeSceneNode* which coincidentally gets created in addShadowVolumeSceneNode. And many other types more. Commented Aug 31, 2018 at 16:09
  • 1
    As I wrote it would be best to store pointers to the IMeshSceneNodes you create as IMeshSceneNode*, not as ISceneNode*, then you don't need any casting later. Commented Aug 31, 2018 at 16:11
  • @PintoDoido By the way, not all ISceneNode are IMeshSceneNode. You could very well have a scene node that doesn't render anything, so that makes sense that you can't apply shadow to a scene node unless it's actually rendering something. Commented Sep 4, 2018 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.