Cameras

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article

Contents

Views

View Overview

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.

Image:Camera.png

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.

Creating Views

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.


Game.CreateView()
create a new view
Game.DeleteView(viewID)
delete a view
Game.SetActiveView(viewId)
sets the current active view to viewId
Game.GetActiveView()
returns the ID of the current view
Game.LinkViewTo(viewId, entityId)
link a view to an entity
Game.GetLinkedId(viewId)
return the entityID view is linked to

A camera is an entity with a view attached. This is typically done in the OnInit or OnSpawn callback of the Entity Scripts.

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.

This gives you a minimal camera. Then you can implement its own behavior by defining an OnUpdate function or a number of entity states with OnUpdate functions.

View Properties

These functions in Game allow operation on views by view ID's. They supersede the System view functions.


Game.SetViewShake(viewId, angle, shift, duration, frequency, randomness)
Start camera shaking
Game.ResetViewShaking()
Stop camera shaking
Game.SetViewFov(viewId, fov)
Sets the field of view for viewId
Game.GetViewFov(viewId)
Returns the field of view for viewId
Game.SetViewNear(viewId, near)
Sets the near plane for viewId
Game.GetViewNear(viewId)
Returns the near plane for viewId
Game.GetViewPos(viewId)
Returns the position of the view camera
Game.IsPlayingCutScene()
returns true if the view system is playing a cutscene, false otherwise

Example Cameras

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.

Image:Minicameras.JPG

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:

Start()
Make the camera's view active
Stop()
Returns the active view to the previous one

For cameras that have a target:

SetTarget(entity)

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.

References

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.

See the Golf minigame for an example of usage. The ARGolfCamera is a combination of the MultiCamera & the MiniFollowOrbitCamera.

Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools