Camera Controls

The WTCaptureDeviceManager allows you to change capture device specific settings during an active capture session. It lets you change e.g.

* the capture device position
* the capture device focus mode
* the capture device zoom level

A valid pointer to a WTCaptureDeviceManager object can be retrieved from the WTWikitudeNativeSDK method -captureDeviceManager. Please note that this pointer is only valid if the native SDK is running. If the SDK is currently stopped, changes for the capture device are done using the WTStartupConfiguration object that is passed as argument to the startupHandler when calling -start:completion:.

The sample uses a UIPickerView to let the user select between different camera specific values. This UIPickerView is added to the view hierarchy in the main storyboards camera scene. By default, the picker view is placed behind the OpenGL ES 2 view, so that it is not visible. To show the picker view, the bottom OpenGL ES 2 view constraint is modified and animated, if a button is touched, to unveil the picker view. A standard iOS SDK UIView animation is used to do so. Please refer to the WTCameraControlsViewController -handleCameraControlsPresentation method.

The connection between the UIPickerView and WTCaptureDeviceManager is done by a custom class called WTCameraControlsModel and its delegate object (Which is in this case WTCameraControlsViewController). This custom class WTCameraControlsModel implements the UIPickerView data source and delegate protocol and uses its custom delegate object to retrieve current camera specific values or exposes newly selected values from the picker view. Implementation details of WTCameraControlsModel are not discussed in this guide as it only handles UIKit related functionality. The following snippets shows the previously mentioned object connection. All following snippets can be found in the WTCameraControlsViewController class.

self.cameraControlsPickerModel = [[WTCameraControlsModel alloc] init];
self.cameraControlsPickerModel.delegate = self;
self.cameraControlPicker.dataSource = _cameraControlsPickerModel;
self.cameraControlPicker.delegate = _cameraControlsPickerModel;

The camera controls model knows internally about all possible camera settings and uses these information to load the picker view. Once the picker is loaded and the user selects a different value, the camera controls model delegate is used to propagate the value change. Since the camera controls view controller implements this delegate protocol and also holds a reference to the Wikitude Native SDK, which by itself provides access to the capture device manager), the view controller sets the appropriate capture device value when this camera controls model delegate is called. The following snippet demonstrates this for the capture device position:

- (void)cameraControlsModel:(WTCameraControlsModel *)cameraControlsModel didSelectCameraPosition:(AVCaptureDevicePosition)activeCameraPosition
{
    if ( [self.wikitudeSDK captureDeviceManager] ) {
        [[self.wikitudeSDK captureDeviceManager] setActiveCaptureDevicePosition:activeCameraPosition];
    }
}

Please note that there is a nil check when [self.wikitudeSDK captureDeviceManager] is called. This is because the Wikitude Native SDK could be paused when the picker changes one of its values.

Every time the picker becomes visible again, the camera controls model asks through its delegate object which capture device settings are currently active. The following snippet again demonstrates this for the currently active capture device position.

- (AVCaptureDevicePosition)currentlyActiveCameraPositionForCameraControlsModel:(WTCameraControlsModel *)cameraControlsModel
{
    return [[self.wikitudeSDK captureDeviceManager] activeCaptureDevicePosition];
}