Skip to main content

History: ChangeSceneManagerRunTime

Source of version: 3 (current)

Copy to clipboard
            I made a tool for editing a .scene and therefore I needed to swich between ST_GENERIC and ST_EXTERIOR_CLOSE to support landscape in scenes.

You can also use this code to switch between any type of SceneManager, e.g. to switch between outdoor and indoor rendering.

__Note:__ For a whole framework around this code, check out ((Basic Tutorial 8)). If you just want the essential code, read on.

__Code:__

{CODE(wrap="1", colors="c++")}void SwitchManager(SceneType mType)
{
    mWnd->removeAllViewports();
    mScene->removeAllCameras();
    mScene = Root::getSingleton().getSceneManager(mType);
    mCam = mScene->createCamera("Main Camera");
    mCam->setPosition(0, 0, 300);
    mCam->lookAt(0, 0, 0);
    mWnd->addViewport(mCam);
    currSceneType = mType;
}{CODE}

''mWnd'' is a RenderWindow pointer to the window that I created in my Init function. ''mScene'' is a SceneManager pointer and ''mCam'' is a Camera pointer.

If your window is automatically created, you can add this code before the ''removeAllViewports()'' to get it:
{CODE(wrap="1", colors="c++")}mWnd = Root::getSingleton().getAutoCreatedWindow();{CODE}

The idea is that you can change your SceneManager if you remove your viewport. So this code removes the viewports, changes the SceneManager and recreates the viewport and camera.

__Note:__ The camera has to be recreated, otherwise it will display the old scene.