Skip to content

Instantly share code, notes, and snippets.

@Seb105
Last active October 26, 2022 20:18
Show Gist options
  • Save Seb105/519bc40fa10c60a05de14d833e7a08a0 to your computer and use it in GitHub Desktop.
Save Seb105/519bc40fa10c60a05de14d833e7a08a0 to your computer and use it in GitHub Desktop.
Arma 3 window script
params ["_window1", "_window2"];
private _windowCam = "camera" camCreate [0,0,0];
private _texRef = hashValue _windowCam + "rtt";
private _texString = "#(argb,512,512,1)r2t(" + _texRef + ",1)";
_windowCam cameraEffect ["internal", "back", _texRef];
_windowCam camCommit 0;
_window1 setObjectTexture [0, _texString];
private _bbr = boundingBoxReal _window1;
private _p1 = _bbr select 0;
private _p2 = _bbr select 1;
private _windowHeight = abs ((_p2 select 2) - (_p1 select 2));
private _handle = [{
params ["_args", "_handle"];
_args params ["_window1", "_window2", "_windowCam", "_windowHeight"];
// Position of cmain camera
private _mainCamPosAgl = positionCameraToWorld [0,0,0];
private _mainCamPosWorld = AGLToASL _mainCamPosAgl;
private _windowPosWorld = getPosWorld _window1;
// Vector from main camera position to window, in coordspace of window
private _dirToWindow = _window1 vectorWorldToModelVisual (_mainCamPosWorld vectorFromTo _windowPosWorld);
// Reflect vector X/Y for portal mirror, not window effect.
private _vectorReflected = _dirToWindow vectorMultiply -1;
// Don't flip Z.
_vectorReflected set [2,_dirToWindow#2];
// Get needed cam FOV
(call CBA_fnc_getFOV) params ["_hFov", "_zoom"];
_hFov = deg _hFov;
// Height of player FOV at the distance of the window.
private _distance = _mainCamPosWorld distance _windowPosWorld;
private _heightAtDistance = ((tan(_hFov)) * _distance);
// How much of the vertical FOV the window takes up (proportion)
private _heightRatio = _windowHeight / _heightAtDistance;
private _newZoom = _heightRatio/_zoom;
// Set calculated values
private _vectorUp = _window2 vectorModelToWorldVisual [0,0,1];
_windowCam camSetFov _newZoom;
_windowCam setPosWorld (getPosWorld _window2);
private _camNewDir = _window2 vectorModelToWorldVisual _vectorReflected;
_windowCam setVectorDirAndUp [_camNewDir, _vectorUp];
}, 0, [_window1, _window2, _windowCam, _windowHeight]] call CBA_fnc_addPerFrameHandler;
@Seb105
Copy link
Author

Seb105 commented Oct 26, 2022

gpl v2 license

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment