From Blue Mars Developer Guidebook
The basic functionality of a camera is in a view. The CryEngine viewsystem allows switching of the current active view among multiple views. A view derives its position and orientation from an attached entity. Thus, to expand on the metaphor, a view acts as the lens of a camera.
A view can be attached to any entity. For example, you could attach a view to a character to provide a first-person view. But for modularity, flexibility, and reusability, chances are you'll want to create a distinct "camera" entity associated with the view.You can implement one for your needs or use one of the #Predefined Cameras.
Since cameras are entities, they can be installed by dragging from the Sandbox Object browser or spawning with the System function SpawnEntity.
If you choose to implement a custom camera outside of your minigame script, you can include the new camera entity in your minigame XML file, and then either manually include the entity when placing the minigame or have a call to System.SpawnEntity in your minigaime script.
If you choose to create a custom camera, you can use the #Predefined Cameras as a starting point. It is recommended that the same conventions are used for activating and deactivating the camera, and initializing and destroying it.
These functions in the Game table create and manipulate views. You can think of a view as a camera lens - you can set view parameters like FOV, but to move and point it, you need to attach it to an entity.
- create a new view
- delete a view
- sets the current active view to viewId
- returns the ID of the current view
- Game.LinkViewTo(viewId, entityId)
- link a view to an entity
- return the entityID view is linked to
self.view = Game.CreateView(); Game.LinkViewTo(self.view,self.id);
The camera "sees" when its view becomes active. By convention in the #Predefined Cameras we do this in a Start function:
self.origView = Game.GetActiveView(); Game.SetActiveView(view);
Also by convention, in the example cameras, we have a Stop function that restores the previous view. This allows us to switch among multiple cameras and return to the original view easily. If you implement your own cameras, it is recommended that you follow these conventions.
- Game.SetViewShake(viewId, angle, shift, duration, frequency, randomness)
- Start camera shaking
- Stop camera shaking
- Game.SetViewFov(viewId, fov)
- Sets the field of view for viewId
- Returns the field of view for viewId
- Game.SetViewNear(viewId, near)
- Sets the near plane for viewId
- Returns the near plane for viewId
- Returns the position of the view camera
- returns true if the view system is playing a cutscene, false otherwise
There's no way to implement a camera that will satisfy every game's needs, but Blue Mars includes a number of example cameras.
The entity descriptors are listed in Game/Entities/Minigames/Cameras.
The Entity Scripts for predefined cameras can be found in Game/Scripts/Entities/Minigames/Cameras. In the Sandbox Editor object browser, the camera entities can be found under Minigames/Cameras.
Each of these cameras has Start and Stop methods:
- Make the camera's view active
- Returns the active view to the previous one
For cameras that have a target:
These are just conventions. You can implement cameras anyway you want - you just need to use the View functions listed above. Feel free to use these cameras as they are, or use them as examples of how to implement your own cameras.
- MiniCamera - a minimal camera with no built-in behavior
- MiniAttachCamera - a camera that attaches to an entity
- MiniLookAtCamera- a camera that always looks at a target
- MiniMouseOrbitCamera - a camera that orbits a target in response to mouse movement
- MiniFollowCamera - a camera that follows a target
- MiniFollowOrbitCamera - camera the combines following and mouse orbiting
- MultiCamera - a camera that includes several of the above as separate modes and switches among them
Game Programming Gems has articles on camera implementation, particularly third-person cameras, in volumes 1,2, and 4.
Real Time Cameras is a comprehensive book on the subject.