Using your own camera controls

Using your own camera controls

When using Wrld maps with the UnityWorld coordinate system it should be possible to use standard approaches to Unity camera control to explore. Alternatively, if built-in camera controls would be more helpful, see Using the Built-in Camera Controls.

Coordinate System

Choosing the coordinate space in the inspector, at edit time

When controlling your own camera, we recommend that you start the API with the UnityWorld coordinate system. This orients the map so that the local up direction for the point around which your map is based matches the unity Y axis. The choice of coordinate system is usually controlled from the Wrld Map behaviour via the Inspector window (see above), but you can also set this up in code yourself if you’re building your own behaviour, as shown below:

	Api.Create(m_apiKey, CoordinateSystem.UnityWorld, rootTransform, defaultConfig);

ECEF

It is possible to control the camera in the alternative coordinate system (ECEF) but this requires you to take account of the curvature of Earth. As such it can get quite complicated, so we’d recommend using the built-in Wrld camera controller where ECEF is required. See Using the Built-in Camera Controls for an example.

Disabling the Built-in Camera Controls

Selecting the built-in camera controls for the WrldMap behaviour

Make sure the Use Built-in Camera Controls box is unchecked when using a custom camera, to avoid any risk of the built-in camera controls interfering. If you’re writing a your own behaviour and want to apply custom control to a camera you’ve previously passed to CameraApi.SetControlledCamera you’ll also need to call CameraApi.ClearControlledCamera to stop the built-in controls from taking effect.

Starting Location for Streaming

Choosing the starting location

You can select the starting latitude and longitude for which your scene will be loaded by modifying the Start Latitude and Start Longitude fields on the WrldMap behaviour. The latitude and longitude are expressed in decimal degrees, using the WGS84 standard (this is the same as the standard used by Google, Bing and many other mapping providers). If you’re writing a custom behaviour, you can instead set these fields in the Wrld.ConfigParams object that gets passed into Wrld.Api.Create:

	var config = ConfigParams.MakeDefaultConfig();
	config.LatitudeDegrees = m_latitudeDegrees;
	config.LongitudeDegrees = m_longitudeDegrees;

Positioning the Camera in the Editor

You can choose your camera’s starting position by moving it around in the editor as normal.

The map is oriented such that any movement along the positive X axis corresponds to going east from the starting location on the globe and any movement along the positive z-axis corresponds to going north. Similarly, movement along the positive Y axis corresponds to an increase in altitude.

Positioning the Camera with Scripts

Your camera’s position can be changed using scripts. However, after moving the camera this way, you must call CameraApi.SetCustomRenderCamera and pass in the camera. You can see an example where this is used in the Control a Custom Camera with Scripts example.

Streaming the map resources

If you’re using the WrldMap behaviour, streaming will be looked after automatically (the set of resources to be streamed is updated when the camera location changes). If you’re writing a custom behaviour, however, you will need to tell the API when the camera changes position. The relevant call is Api.StreamResourcesForCamera:

	m_api.StreamResourcesForCamera(m_streamingCamera);
v0.8.17