More improvements have been added with the introduction of a new “CameraManager” class. Overall, the changes were quite large, so I’ll sum up the amends here but the full version can be found here.
The idea behind the “CameraManager” class was to allow multiple cameras to be instantiated and used. Before, everything was hard-coded to a “FirstPersonCamera” and now the camera classes inherit from a new “ICamera” interface. This allows for a camera class to be passed through the engine without actually knowing what type of camera it is. The new “CameraManager” class sits inside of the “Core” folder. It has 4 simple methods which allow you to add, remove, set and get a camera. The “SceneManager” class has been altered to automatically create a “FirstPersonCamera” and assigns a name of “Default”. I’ll quickly run through the new methods:
public static void AddCamera(string name, ICamera camera);
“AddCamera” allows you to add a new camera. As it’s a
static method (and so are the other methods), you use it like:
CameraManager.AddCamera("Camera1", new PerspectiveCamera(MathHelper.PiOver2, GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f));
public static ICamera GetActiveCamera();
“GetActiveCamera” does exactly what it says, it will return the camera that is currently set as active. If no camera is found, then it will throw an exception.
public static void RemoveCamera(string name);
“RemoveCamera” will remove the camera with the specified name.
public static void SetActiveCamera(string name);
“SetActiveCamera” will assign the active camera to the specified name. If the specified camera name does not exist in the camera collection, it will throw an exception.
That is pretty much it. Just a quick summary post of the new class. I would download the latest changeset to see the implications that the new class has had on the structure of the engine. Thanks to the new interface “ICamera”, passing cameras between renderers is now a lot easier.