This project is read-only.
  • Camera Component (Components\CameraComponent.cs)
    • Creating a camera
    • In the sample the current camera you’ll see is being created directly in the SceneManager. This camera is attach to the Root Entity which belongs to the SceneManager. This is to ensure there is always a camera that the engine can use, by default. You should not create another camera in the SceneManager, unless you want to be making changes directly to the engine. Instead, I recommend creating any new cameras inside you own scene, like in SampleScene.cs. However, for an example about how a camera is created, you will want to look in SceneManager.cs in the SetupBaseCamera() function. 
    • To create a camera, you simply need to attach a CameraComponent to an Entity. In the example in SceneManager.cs, we already have an entity, because the Scene Manager is attaching the camera to the Root Entity. If you create your own camera, you’ll want to create a new Entity for it most likely.
      • After your Entity is created, we need to attach a CameraComponent to that Entity. If you want to create the component dynamically this is done in SetupBaseCamera() with this line of code:
      • CameraComponent sceneMgrCamera = EntityLoader.LoadComponent( this.sceneMgrRootEntity, ComponentType.CameraComponent, this.content, 
        "Entities/ComponentDefinitions/Camera/StandardCamera"as CameraComponent;
      • This will create a CameraComponent, attach it to the Entity ‘sceneMgrRootEntity’ (in this case), set the field-of-view to 60 degrees, set the aspect ratio based on the game’s aspect ratio in this case, set our near clipping distance of 0.5 units, and a far clipping distance to 2000 units. This Entity can now render in whatever direction it is facing. However, read on, there is more you need to do.
      • To do this through a definition XML just specify each of your camera's settings inside the XML. However you'll notice that the root scene node doesn't use a template from the EntityTemplates.xml file, so here you can see how to load up single components from definition XML files.
      • To load single components you can call the static method 'LoadComponent' from within the EntityLoader class. Pass it the entity you want the component loaded on to, the type of component you want loaded, a reference to the content manager, and the full path of the definition XML file. Here's an example:
      • CameraComponent sceneMgrCamera = EntityLoader.LoadComponent(this.sceneMgrRootEntity, ComponentType.CameraComponent,this.content, "Entities/ComponentDefinitions/Camera/StandardCamera"as CameraComponent;
      • Just because you’ve created a camera doesn’t mean you’re going to be rendering from its point of view just yet. You need to inform the Renderer which Entity is acting as the current camera. You do this by sending a message to the CameraInterface, letting it know we want to use a specific Entity as the camera, like so (also in CreateAndStartFreeMovingCamera() in SceneManager):

        MsgSetRenderEntity camSetRenderMsg = ObjectPool.Aquire<MsgSetRenderEntity>();
        camSetRenderMsg.Entity = this.sceneMgrRootEntity;, InterfaceType.Camera);
      • This is your first introduction to the message system, which we’ll talk about more later. What you’re seeing in the code above is that we create a MsgSetRenderEntity object (which is a custom message created for setting which entity will render each frame), and the “Entity” variable is the entity which is going to become the render camera, in this case it was sceneMgrRootEntity. Then the last line is where we send the message to the Message system (and in this case, we’re sending to an interface rather than an Entity). The CameraInterface will receive this message, and see that we want to set sceneMgrRootEntity as the camera, and will do so. You will now see everything from this camera’s point of view.

Last edited Jan 5, 2012 at 5:56 AM by LordIkon, version 1


No comments yet.