As you know, when you use UAV, you can open terminal and have video from gunner and pilot camera streamed directly to it. Unfortunately this is hardcoded engine functionality and there is no direct way of tapping into these video feeds. Fortunately there is a way to simulate this using available SQF commands and config params. I am going to show how to “hack” UAV gunner camera and stream it to a texture surface so that it will show what UAV gunner sees.
The idea is simple, create render surface, create instance of a camera and assign it to created render surface, attach camera to the UAV gunner camera position, make it point where gunner camera is pointing. Everything is pretty straight forward apart from getting gunner camera direction. For this we need to look in config of the particular UAV to find gunner camera memory points. For the quadrotor UAV they are:
- uavCameraGunnerPos = “PiP0_pos”;
- uavCameraGunnerDir = “PiP0_dir”;
uavCameraGunnerPos is position of the camera lens in model coordinates. It will be good for attaching custom camera to it. uavCameraGunnerDir is also position, contrary to the name. One might expect directional vector, but it is actually position, so in order to find directional vector, you need to calculate it from uavCameraGunnerPos and uavCameraGunnerDir. Luckily there is a command for it, vectorFromTo. To get the actual coordinates you need selectionPosition command. So the vectorDir of the gunner camera can be calculated like this:
This is how this vectorDir would look like when calculated:
But having just vectorDir is not enough and for complete camera orientation we need vectorUp as well, which can be found as vectorCrossProduct between vectorDir and a side vector, which is perpendicular to vectorDir:
The direction of the attached camera will need to be adjusted every frame as attached objects do not change direction automatically. The whole code should now look like this:
Enjoy,
KK
An experiment I did earlier with Greyhawk UAV:
EDIT: fixed small typo _uav -> uav