Let’s talk some more about  shortcomings of Arma scripting. this time it is the lack of getFOV or getZoom commands. You might think this is not a big deal, who needs it anyway? Well knowing Field Of View could be useful for many things. For example, you can measure the physical distance in game in a few different ways. But let’s imagine you want to know virtual, perceived distance to an object rather than physical.

When you look through a scope or binoculars you see things much closer so the virtual distance could be a few hundred metres away while physical distance could be thousands metres away. Where can you use this? For once it is useful if you want to make icons dynamic, i.e. change detail the closer you look, as shown in this video.

You cannot do this without knowing FOV. So I’ve constructed a function to measure optics zoom. Zoom, FOV, perceived distance, they are all connected, but you need a way of finding one or the other. I’ve created a feature request on feedback tracker for a new command to get either FOV or zoom, so please upvote if you’re with me.

Now to the workaround. The principle is simple, create a virtual dot in physical space, transfer it to the screen coordinates and then measure the screen distance between centre of the screen and this dot. As you zoom in the distance will increase, as you zoom out the distance will decrease. Here is the code:

KK_fnc_trueZoom = { ( [0.5,0.5] distance2D worldToScreen positionCameraToWorld [0,3,4] ) * ( getResolution select 5 ) / 2 };

I have calibrated this for my screen. This code should work with any screen now and measure the actual zoom. As you can see from the video below, it is pretty precise.

The code I used for the hint output is:

onEachFrame { hintSilent format [ "CURRENT ZOOM: %1x", round (call KK_fnc_trueZoom * 10) / 10 ] };


EDIT: I have updated the code. It should now work with any screen and any UI resolution.

EDIT2: I have updated the code once again, this time I think this will be final. A few things changed since I first published the code. Bohemia tweaked zoom on all weapons and player view and unified it, so that when you zoom without a weapon, it becomes 1x zoom. Everything else is derivative from this base level. Also, new command distance2D was introduced that is essential for this function to work properly. I also finally calibrated the function using science, not magic. Because it now returns proper zoom, I also renamed the function to KK_fnc_trueZoom.