Intermediate Tutorial 4: Using multiple SceneManagers

Original version by Clay Culver

OrgeDotNet C# port/conversion by DigitalCyborg.

Note: This was written for Ogre 1.2, and is known to compile against it. Any problems you encounter while working with this tutorial should be posted to the OgreDotNet Forum.

Introduction

In this tutorial we will be covering how to use multiple SceneManagers in an Ogre application. Mr Turner has written a quick snippet of the the essential code to make this work. If you are not interested in a full walkthrough, you should start there instead and you should think about converting his snippet to C# and putting it up in the code snippets section of the ODN wiki..

The full code for this tutorial is included at the bottom if you get lost, but try to follow along without looking! As you go through the tutorial you should be slowly adding code to your own project and watching the results as we build it.

Prerequisites

We will be using the Dictionary class (.NET framework 2.0 System.Collections.Generic) in this tutorial. If you are not familiar with this you should brush up on it before you begin this tutorial. We will also use the conditional operator ? : in several places, so if you are not familiar with it you should brush up on that too.

Getting Started

Create a file called SMTutorial.cs and add the following code to it:

using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial 
 {
    class IntermediateTutorial4 : ExampleApplication
    {
        protected MultiSceneManager mMSM;     // The multiScene Manager
        ushort mSceneType;                    // The current SceneManager type
        float mTimeUntilNextToggle;
        ushort tsmType;                       // Terrain SceneManager type
        ushort gsmType;                       // Generic SceneManager type 
 
        public IntermediateTutorial4()
        {
            mMSM = new MultiSceneManager();
            gsmType = (ushort) SceneType.Generic;
            tsmType = (ushort) SceneType.ExteriorClose;
            mSceneType = gsmType;
            mTimeUntilNextToggle = 1.0f;
        }
        
        ~IntermediateTutorial4() { }
        
        protected override void  CreateSceneManager() { }
            
        protected override bool FrameStarted(FrameEvent e)
        {
            if(! base.FrameStarted(e)) 
                return false;           
            return true;
        }
 
        protected override void CreateScene() { }
        protected override void CreateCamera() { }
        protected override void CreateViewPort() { }
 
        protected override void KeyClicked(KeyEvent e)
        {
            base.KeyClicked(e);
        }
 
        static void Main(string[] args)
        {
            using (IntermediateTutorial4 app = new IntermediateTutorial4())
            {
                app.Start();
            }
        }
    }
 }

Next create another file called SceneManagerState.cs and add the following code to it:

using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial
 {
    // SceneManagerState
    class SceneManagerState
    {
        protected Vector3 mCamPosition; 
        protected Quaternion mCamOrientation;  // The camera orientation
        protected SceneManager mSceneManager; // The SceneManager this object wraps
        protected RenderWindow mRenderWindow; // The RenderWindow the application uses
 
        public SceneManagerState(SceneManager sceneManager, RenderWindow renderWindow)
        {
            mSceneManager = sceneManager;
            mRenderWindow = renderWindow;
        }
 
        ~SceneManagerState() { }
 
        // Called when this SceneManager is being displayed
        public void showScene() { }
 
        // called when this SceneManager is no longer being displayed
        public void hideScene() { }
 
        // returns the SceneManager
        public SceneManager getSceneManager()
        {
            return mSceneManager;
        }
    }
 }

Finally create one more file MultiSceneManager.cs with this code:

using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial
 {
    // MultiSceneManager
    class MultiSceneManager
    {
        protected Dictionary<ushort, SceneManagerState> mStateMap; // The map of registered states
        protected SceneManagerState mCurrentSMState;  // the current state
        protected Root mRoot;                       // the Root object
        protected RenderWindow mRenderWindow;       // the RenderWindow
 
        public MultiSceneManager()
        {
            mCurrentSMState = null;
            mRoot = null;
            mRenderWindow = null;
            mStateMap = new Dictionary<ushort, SceneManagerState>();
        }
        
        ~MultiSceneManager( ) { }
 
        // sets the Root object
        public void setRoot( Root root )
        {
            mRoot = root;
        }
        
        // sets the RenderWindow
        public void setRenderWindow( RenderWindow renderWindow )
        {
            mRenderWindow = renderWindow;
        }
        
        // registers a scene manager class for usage, you cannot call
        // setSceneManager on any type without first calling registerSceneManager
        public void registerSceneManager( ushort st )
        {
        }
 
        // makes st the current SceneManager
        public void setSceneManager( ushort st ) 
        {
        }
 
        // returns the SceneManager that's currently rendering
        public SceneManager getCurrentSceneManager( )
        {
               return null; 
        }
 
        // returns the SceneManager associated with type st (must already be registered)
        public SceneManager getSceneManager( ushort st ) 
        {
                return null;
        }
 
        // finds and returns the SceneManagerState associated with st    
        protected SceneManagerState findState( ushort st )
        {
                return null;
        }
    }
 }

Note: This code should compile at this point, but don't run it yet.

Before we Begin

In this tutorial we will be using multiple SceneManagers in a single OgreDotNet application. Generally speaking this really only involves three steps.
First, destroy all Viewports and Cameras associated with the current SceneManager.
Second, get the SceneManager you want to use next and register it using Root._setCurrentSceneManager.
Finally, recreate your cameras and viewports. This is a fairly straightforward process. In this tutorial we will be building a very simplistic MultiSceneManager class which allows us to swap back and forth between several different SceneManagers. In the next tutorial we will be extending this simplistic manager class into a more powerful version able to handle multiple contexts of the same SceneManager type.

'''Note: At the time of writing this tutorial _setCurrentSceneManager is not available in OgreDotNet without making a small change to OgreRoot.i, reswigging and recompiling''' thankfully, this is a relatively painless process. just open OgreRoot.i & remove the line which says %ignore _setCurrentSceneManager, reswig and then recompile. I've asked Rastaman to make this change in the CVS source or to update this tutorial with a better (or the proper) way to do what that function does.

One thing you will notice in this tutorial is that the Example Framework gets in our way a LOT. The Example Framework was written with the idea that the mCamera variable would be permanent after you create it, which is simply not the case when we are swapping SceneManagers. I have opted to keep the Example Framework for the Tutorial so that you do not have to learn a new framework as you learn other concepts. However, if you are actually going to do something like this in a program, you need to stop using the Example Framework and write your own Application class that's tailored to your needs instead.

The SceneManagerState class

We've defined two classes to handle swapping SceneManagers - SceneManagerState and MultiSceneManager The MultiSceneManager class will be the public interface for swapping SceneManagers, and the SceneManagerState will keep track of SceneManager variables which get destroyed when we swap SceneManagers.

The SceneManagerState class contains basic information about the Camera, because when we destroy the camera, we lose position and orientation that has been set. The showScene method is called whenever the SceneManager wrapped by this class is about to be shown. The hideScene method is called whenever we are going to unload this SceneManager and display another one.

The showScene method needs to create the Camera for use, set the aspect ratio, and restore the Camera's position and orientation. Add this code to the showScene method:

// create the camera and viewport
            Camera cam = mSceneManager.CreateCamera("SceneCamera");
            Viewport vp = mRenderWindow.AddViewport(cam);
            vp.SetBackgroundColour(Color.Black);
 
            // Set the aspect ratio
            cam.SetAspectRatio((float)vp.GetWidth() / (float)vp.GetHeight());//p.GetActualWidth() / (float)vp.GetHeight());
            cam.SetNearClipDistance(5.0f);
 
            // Set the camera's position and orientation
            cam.SetPosition(mCamPosition);
            cam.SetOrientation(mCamOrientation);

The hideScene method needs to save the Camera's position and orientation, then destroy all viewports and cameras. This is done in a very straight forward manner in the hideScene method:

int numViewports;
 
            // save camera position and orientation
            Camera cam = mSceneManager.GetCamera("SceneCamera");
            mCamPosition = cam.GetPosition();
            mCamOrientation = cam.GetOrientation();
 
            // destroy the camera and viewport
            numViewports = mRenderWindow.GetNumViewports();
            for (int i = 0; i < numViewports; i++)
            {
                mRenderWindow.RemoveViewport(i);
            }
            mSceneManager.DestroyAllCameras();

The MultiSceneManager class



The other half of this system is the MultiSceneManager class. In order to use this object, you must first feed it the Root object and the RenderWindow object. After this is done, you will need to register every SceneManager type that you wish to use, such as SceneType.Generic, SceneType.ExteriorClose, etc. After you have set the Root/RenderWindow objects and registered SceneManager types, you can then begin to use the class and set up your SceneManagers.

To configure a SceneManager (such as setting it up for initial display), call the getSceneManager method with the SceneManager type you wish to manipulate. This will return a SceneManager object which you can then manipulate. In order to set the current SceneManager (or swap during runtime), simply call the setSceneManager method with the type of SceneManager you wish to use.

We will start with the registerSceneManager method first. This method needs to create an entry in mStateMap pretaining to the SceneType specified. To do this, we need to create a new SceneManagerState object and have st map to it, like so:

mStateMap[st] = new SceneManagerState(mRoot.CreateSceneManager(st),
                mRenderWindow);

We will now implement the helper function findState. The findState function searches the map for the specified state, and returns it (or 0 if it's not found).

SceneManagerState retval;
            // Search map
            //return the result or null
            if(mStateMap.TryGetValue(st,out retval))            
                return retval;
            else
                return null;

Now that findState is implemented, we can implement the getSceneManager function easily. The getSceneManager function returns the SceneManager assocated with the SceneType specified, but does NOT set it as the current SceneManager. We will first search for the requested SceneType, then return it (or 0 if the SceneType was not registered):

SceneManagerState sms = findState(st);
            if (sms != null)
                return sms.getSceneManager();
            else
                return null;

The last function we have to implement is the setSceneManager method. The basic flow of the method is to first hide the current SceneManager, find the requested SceneManager and start it rendering:

// hide the current SceneManager
            if (mCurrentSMState != null)
                mCurrentSMState.hideScene();
 
            // find the next SceneManager
            mCurrentSMState = findState(st);
 
            // set the current SceneManager in the Root class after initializing
            if (mCurrentSMState != null)
            {
                mCurrentSMState.showScene();
                mRoot._setCurrentSceneManager(mCurrentSMState.getSceneManager());
            }

That wraps up the MultiSceneManager class. Be sure your code compiles before continuing.

The SMTutorialApplication class

The first thing we have to do in the SMTutorialApplication class is stop the ExampleApplication class from trying to create cameras and viewports on its own. To do this, we've overridden the createCamera and createViewports with empty functions in the protected portion of the class:

// We overide this method with an empty class and hide the base method
     // since all of this functionality is contained in the CreateSceneManager
     // method now.
     void createCamera() { }
     
     // We overide this method with an empty class and hide the base method
     // since all of this functionality is contained in the CreateSceneManager
     // method now.
     void createViewports() { }

Now we need to set up the MultiSceneManager class. We do this by adding code to the chooseSceneManager method. First we register the information that the MultiSceneManager class needs to operate. We cannot pass these as constructor values, since at the time the mMSM object is constructed the Root and RenderWindow variables are not yet set.

// Set the required information
            mMSM.setRoot( mRoot );
            mMSM.setRenderWindow( mRenderWindow );

Now we need to register the SceneTypes that we will be using in the application. You may register these as you use them instead of all at the beginning if you like. The only restriction is that a SceneType must be registered before you call setSceneManager or getSceneManager with that type.

// Register SceneTypes we will be using: 
            mMSM.registerSceneManager( gsmType );
            mMSM.registerSceneManager( tsmType );

Now we need to set the startup SceneManager:

// Set the startup SceneType:
            mMSM.setSceneManager( gsmType );

Normally this would be all that you need to do during your SceneManager creation method. However, ExampleApplication uses two internal variables mSceneMgr and mCamera, which we should populate if we are using the ExampleFramework. Note however that as soon as we swap states both variables are invalid. If you rewrite the Example framework you should make the classes aware of this and query for the SceneManager/Camera when they are needed. This is the last chunk of code that is needed in the chooseSceneManager method:

// Add variables that ExampleApplication expects
            mSceneManager = mMSM.getSceneManager( gsmType );
            mCamera = mSceneManager.GetCamera("SceneCamera");

Now we are going to setup the scene for each of our SceneManagers. Find the createScene method. We will set the Terrain and sky box for the TerrainSceneManager, and add a Robot to the Generic SceneManager:

// Setup the TerrainSceneManager
            SceneManager tsm = mMSM.getSceneManager(tsmType);
            mMSM.setSceneManager(tsmType);
            mCamera = tsm.GetCamera("SceneCamera");
            
            tsm.SetWorldGeometry("terrain.cfg");
            tsm.SetSkyBox(true, "Examples/SpaceSkyBox", 50);
            mCamera.SetPosition(new Vector3(60, 60, 500));
            mCamera.LookAt = new Vector3(0, 0, 0);
 
            // Setup the Generic SceneManager
            Entity ent;
            SceneNode sn;
 
            SceneManager gsm = mMSM.getSceneManager(gsmType);
            mMSM.setSceneManager(gsmType);
            mCamera = gsm.GetCamera("SceneCamera");
 
            ent = gsm.CreateEntity("Robot", "robot.mesh");
            sn = gsm.GetRootSceneNode().CreateChildSceneNode("RobotNode");
            sn.AttachObject(ent);
            sn.SetPosition(0, 0, -250);
            mCamera.LookAt = new Vector3(0, 0, -250);

Note that we have used mCamera here. We can do this for the current SceneManager, but due to the limitations of this design, we have to use the setSceneManager function if we want to manipulate the camera for a SceneManager. Compile and run the application. You should now be staring at a Robot, but since we have not added any key bindings for swapping SceneManagers we currently don't have any way to swap SceneManagers.

Binding a key click to swap SceneManagers

The last thing we need to do is add a way to swap SceneManagers. To do this, we will add some code to the KeyClicked method to swap between SceneManagers every time the C key is pressed:

base.KeyClicked(e);
 
            switch (e.KeyCode)
            {
                case KeyCode.C:
                    if (mTimeUntilNextToggle <= 1.0f)
                    {
                        mSceneType = (mSceneType == gsmType ) ?
                            tsmType :
                            gsmType ;
                        mMSM.setSceneManager(mSceneType);
                        mCamera = mMSM.getSceneManager(mSceneType).GetCamera("SceneCamera");
                        mTimeUntilNextToggle = 1.0f;
                    }
                    break;
            }

Note that we have to update mCamera every time we swap the SceneManager due to limitations of the Example framework. Compile and run the application. We are now done! C swaps SceneManagers and the Camera position is saved when we swap SceneManagers.

Complete Code for the tutorial

SceneManagerState.cs

using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial
 {
    // SceneManagerState
    class SceneManagerState
    {
        protected Vector3 mCamPosition; 
        protected Quaternion mCamOrientation;  // The camera orientation
        protected SceneManager mSceneManager; // The SceneManager this object wraps
        protected RenderWindow mRenderWindow; // The RenderWindow the application uses
 
        public SceneManagerState(SceneManager sceneManager, RenderWindow renderWindow)
        {
            mSceneManager = sceneManager;
            mRenderWindow = renderWindow;
        }
 
        ~SceneManagerState() { }
 
        // Called when this SceneManager is being displayed
        public void showScene()
        {
            // create the camera and viewport
            Camera cam = mSceneManager.CreateCamera("SceneCamera");
            Viewport vp = mRenderWindow.AddViewport(cam);
            vp.SetBackgroundColour(Color.Black);
 
            // Set the aspect ratio
            cam.SetAspectRatio((float)vp.GetWidth() / (float)vp.GetHeight());//p.GetActualWidth() / (float)vp.GetHeight());
            cam.SetNearClipDistance(5.0f);
 
            // Set the camera's position and orientation
            cam.SetPosition(mCamPosition);
            cam.SetOrientation(mCamOrientation);
        }
 
        // called when this SceneManager is no longer being displayed
        public void hideScene()
        {
            int numViewports;
 
            // save camera position and orientation
            Camera cam = mSceneManager.GetCamera("SceneCamera");
            mCamPosition = cam.GetPosition();
            mCamOrientation = cam.GetOrientation();
 
            // destroy the camera and viewport
            numViewports = mRenderWindow.GetNumViewports();
            for (int i = 0; i < numViewports; i++)
            {
                mRenderWindow.RemoveViewport(i);
            }
            mSceneManager.DestroyAllCameras();
        }
 
        // returns the SceneManager
        public SceneManager getSceneManager()
        {
            return mSceneManager;
        }
    }
 }

MultiSceneManager.cs


using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial
 {
    // MultiSceneManager
    class MultiSceneManager
    {
        protected Dictionary<ushort, SceneManagerState> mStateMap; // The map of registered states
        protected SceneManagerState mCurrentSMState;  // the current state
        protected Root mRoot;                       // the Root object
        protected RenderWindow mRenderWindow;       // the RenderWindow
 
        public MultiSceneManager()
        {
            mCurrentSMState = null;
            mRoot = null;
            mRenderWindow = null;
            mStateMap = new Dictionary<ushort, SceneManagerState>();
        }
        
        ~MultiSceneManager( ) { }
 
        // sets the Root object
        public void setRoot( Root root )
        {
            mRoot = root;
        }
        
        // sets the RenderWindow
        public void setRenderWindow( RenderWindow renderWindow )
        {
            mRenderWindow = renderWindow;
        }
 
        // registers a scene manager class for usage, you cannot call
        // setSceneManager on any type without first calling registerSceneManager
        public void registerSceneManager( ushort st )
        {
            mStateMap[st] = new SceneManagerState(mRoot.CreateSceneManager(st),
                mRenderWindow);
            
            Console.WriteLine("SceneType {0} registered", st);
        }
 
        // makes st the current SceneManager
        public void setSceneManager( ushort st ) 
        {
            // hide the current SceneManager
            if (mCurrentSMState != null)
                mCurrentSMState.hideScene();
 
            // find the next SceneManager
            mCurrentSMState = findState(st);
 
            // set the current SceneManager in the Root class after initializing
            if (mCurrentSMState != null)
            {
                mCurrentSMState.showScene();
                mRoot._setCurrentSceneManager(mCurrentSMState.getSceneManager());
            }
        }
 
        // returns the SceneManager that's currently rendering
        public SceneManager getCurrentSceneManager( )
        {
            if(mCurrentSMState != null)
                return mCurrentSMState.getSceneManager();
            else 
                return null; 
        }
 
        // returns the SceneManager associated with type st (must already be registered)
        public SceneManager getSceneManager( ushort st ) //SceneType st)
        {
            SceneManagerState sms = findState(st);
            if (sms != null)
                return sms.getSceneManager();
            else
                return null;
        }
 
        // finds and returns the SceneManagerState associated with st    
        protected SceneManagerState findState( ushort st )
        {
            SceneManagerState retval;
            // Search map
            //return the result or null
            if(mStateMap.TryGetValue(st,out retval))            
                return retval;
            else
                return null;
        }
    }
 }

SMTutorial.cs


using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using Math3D;
 using OgreDotNet;
 
 namespace OgreDotNetTutorial
 {
    class IntermediateTutorial4 : ExampleApplication
    {
        protected MultiSceneManager mMSM;     // The multiScene Manager
        ushort mSceneType;                    // The current SceneManager type
        float mTimeUntilNextToggle;
        ushort tsmType;                       // Terrain SceneManager type
        ushort gsmType;                       // Generic SceneManager type 
 
        public IntermediateTutorial4()
        {
            mMSM = new MultiSceneManager();
            gsmType = (ushort) SceneType.Generic;
            tsmType = (ushort) SceneType.ExteriorClose;
            mSceneType = gsmType;
            mTimeUntilNextToggle = 1.0f;
        }
        
        ~IntermediateTutorial4() { }
        
        protected override void  CreateSceneManager()
        {
            // Set the required information
            mMSM.setRoot( mRoot );
            mMSM.setRenderWindow( mRenderWindow );
 
            // Register SceneTypes we will be using: 
            mMSM.registerSceneManager( gsmType );
            mMSM.registerSceneManager( tsmType );
            
            // Set the startup SceneType:
            mMSM.setSceneManager( gsmType );
 
            // Add variables that ExampleApplication expects
            mSceneManager = mMSM.getSceneManager( gsmType );
            mCamera = mSceneManager.GetCamera("SceneCamera");
        }
            
        protected override bool FrameStarted(FrameEvent e)
        {
            if(! base.FrameStarted(e)) 
                return false;
            
            // decrement the timelimit before scene toggling is allowed
            mTimeUntilNextToggle -= e.TimeSinceLastFrame;
 
            return true;
        }
 
        protected override void CreateScene()
        {
            // Setup the TerrainSceneManager
            SceneManager tsm = mMSM.getSceneManager(tsmType);
            mMSM.setSceneManager(tsmType);
            mCamera = tsm.GetCamera("SceneCamera");
            
            tsm.SetWorldGeometry("terrain.cfg");
            tsm.SetSkyBox(true, "Examples/SpaceSkyBox", 50);
            mCamera.SetPosition(new Vector3(60, 60, 500));
            mCamera.LookAt = new Vector3(0, 0, 0);
 
            // Setup the Generic SceneManager
            Entity ent;
            SceneNode sn;
 
            SceneManager gsm = mMSM.getSceneManager(gsmType);
            mMSM.setSceneManager(gsmType);
            mCamera = gsm.GetCamera("SceneCamera");
 
            ent = gsm.CreateEntity("Robot", "robot.mesh");
            sn = gsm.GetRootSceneNode().CreateChildSceneNode("RobotNode");
            sn.AttachObject(ent);
            sn.SetPosition(0, 0, -250);
            mCamera.LookAt = new Vector3(0, 0, -250);
        }
 
        protected override void CreateCamera() {}
        protected override void CreateViewPort() {}
 
        protected override void KeyClicked(KeyEvent e)
        {
            base.KeyClicked(e);
 
            switch (e.KeyCode)
            {
                case KeyCode.C:
                    if (mTimeUntilNextToggle <= 1.0f)
                    {
                        mSceneType = (mSceneType == gsmType ) ?
                            tsmType :
                            gsmType ;
                        mMSM.setSceneManager(mSceneType);
                        mCamera = mMSM.getSceneManager(mSceneType).GetCamera("SceneCamera");
                        mTimeUntilNextToggle = 1.0f;
                    }
                    break;
            }
        }
 
        static void Main(string[] args)
        {
            using (IntermediateTutorial4 app = new IntermediateTutorial4())
            {
                app.Start();
            }
        }
    }
 }

Exercises


Easy Exercises

  1. Registering the same SceneType multiple times is unnecessary. Instead of allowing the user to register the same SceneType multiple times, throw an exception class when the user tries to do this.
  2. Currently if a SceneType is not registered, the MultiSceneManager will just ignore it and return null. Instead, throw an Exception every time the user tries to use a SceneType that's not registered.
  3. setSceneManager should check whether or not we are already using the requested SceneType and since there is nothing to do in that case, it should just return. update the code.
  4. There are still some C++ style getVariable and setVariable functions. update the code to use properties since this fits the C# code style

Intermediate Exercises

  1. Modify the MultiSceneManager class so that instead of throwing an exception for unregistered SceneTypes, it creates a new one whenever it encounters a SceneType that's unregistered. Now that you have implemented both methods, which do you think is better?
  2. There really should only ever be one MultiSceneManager class. Make the MultiSceneManager class inherit from Ogre.Singleton.

Advanced Exercises

  1. Modify the code so that you can set a default Camera position and Orientation.
  2. The way cameras are currently handled there is only one camera ever, and it is retrieved based on the string "SceneCamera". Make this system more robust by adding a method to add multiple Cameras to each SceneManager and to be able to query for them. Don't forget that every Camera that is created will need to be stored when they are destroyed during the hideScene method.
  3. When a SceneManager is swapped for another SceneManager, some classes will need to be made aware of this. For example, it would be inefficient to query for the current SceneManager and Camera EVERY frame if the SceneManager is changed very rarely. Implement a SceneChangeEvent which is fired every time the SceneManager is changed. Create a SceneChangeListener with an abstract interface for receiving these events. Note that the SceneChangeEvent should probably include the SceneManager which is being hidden and the SceneManager which is being shown. When should this event occur? Before the current SceneManager is hidden? After the new SceneManager is shown? In between the two events?

Exercises for Further Study

  1. Design and implement a similar set of classes which manipulate "SceneManager contexts" instead of SceneManagers. You may need to have a single SceneManager do multiple things. For example, you may need have the TerrainSceneManager display two seperate sets of Geometry and Entities which you swap back and forth between. This is currently not possible with the methods implemented here.

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.