ChangeSceneManagerRunTime         Change the scenemanager at runtime
Print

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:

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;
}

 
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:

mWnd = Root::getSingleton().getAutoCreatedWindow();

 
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.


Contributors to this page: jacmoe111451 points  and Jheld .
Page last modified on Saturday 02 of January, 2010 23:28:14 GMT by jacmoe111451 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.