Last active
May 15, 2018 18:02
-
-
Save commy2/b0c3bac9218e010e687a4f629b29a03b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by commy2 | |
// Display crosshair in center of screen. Used for debugging. | |
commy_debugCrosshairColor = [1,0,0,0.5]; | |
commy_debugCrosshairZoomColor = [1,0,0,2/3]; | |
commy_debugCrosshairManbarColor = [0,1,0,2/3]; | |
commy_debugCrosshairMilToDegree = 360/2000/pi; | |
private _debugCrosshair = uiNamespace getVariable ["BWA3_debugCrosshair", displayNull]; | |
if (!isNull _debugCrosshair) exitWith { | |
"BWA3_debugCrosshair" cutText ["", "PLAIN"]; | |
false | |
}; | |
"BWA3_debugCrosshair" cutRsc ["RscTitleDisplayEmpty", "PLAIN", 0, false]; | |
private _display = uiNamespace getVariable "RscTitleDisplayEmpty"; | |
uiNamespace setVariable ["BWA3_debugCrosshair", _display]; | |
private _vignette = _display displayCtrl 1202; | |
_vignette ctrlShow false; | |
// crosshair | |
private _horizontalBar = _display ctrlCreate ["RscText", -1]; | |
_horizontalBar ctrlSetBackgroundColor commy_debugCrosshairColor; | |
private _width = safezoneW; | |
private _height = pixelH; | |
private _left = safezoneX; | |
private _top = 0.5 - pixelH/2; | |
_horizontalBar ctrlSetPosition [_left, _top, _width, _height]; | |
_horizontalBar ctrlCommit 0; | |
private _verticalBar = _display ctrlCreate ["RscText", -1]; | |
_verticalBar ctrlSetBackgroundColor commy_debugCrosshairColor; | |
_width = pixelW; | |
_height = safezoneH; | |
_left = 0.5 - pixelW/2; | |
_top = safezoneY; | |
_verticalBar ctrlSetPosition [_left, _top, _width, _height]; | |
_verticalBar ctrlCommit 0; | |
// mildots | |
private _mildots = []; | |
_display setVariable ["BWA3_debugCrosshair_mildots", _mildots]; | |
for "_i" from 1 to 56 do { | |
private _mildot = _display ctrlCreate ["RscText", -1]; | |
_mildot ctrlSetBackgroundColor commy_debugCrosshairColor; | |
_mildot ctrlSetPosition [0,0,0,0]; | |
_mildot ctrlCommit 0; | |
_mildots pushBack _mildot; | |
}; | |
// magnification | |
private _magnification = _display ctrlCreate ["RscText", -1]; | |
_magnification ctrlSetTextColor commy_debugCrosshairZoomColor; | |
_width = safezoneW/30; | |
_height = safezoneH/30*(getResolution select 4); | |
_left = 0.5 + safezoneW/12 - _width/2; | |
_top = 0.5 - safezoneH/12*(getResolution select 4) - _height/2; | |
_magnification ctrlSetPosition [_left, _top, _width, _height]; | |
_magnification ctrlCommit 0; | |
_display setVariable ["BWA3_debugCrosshair_magnification", _magnification]; | |
// man heights | |
private _manbars = []; | |
_display setVariable ["BWA3_debugCrosshair_manbars", _manbars]; | |
for "_i" from 1 to 6 do { | |
private _manbar = _display ctrlCreate ["RscText", -1]; | |
_manbar ctrlSetBackgroundColor commy_debugCrosshairManbarColor; | |
_manbar ctrlSetPosition [0,0,0,0]; | |
_manbar ctrlCommit 0; | |
_manbars pushBack _manbar; | |
}; | |
_width = safezoneW/4; | |
_height = pixelH; | |
_left = 0.5 - _width/2; | |
_top = safeZoneY + safezoneH*7/8 - pixelH/2; | |
private _manbar = _manbars deleteAt 0; | |
_manbar ctrlSetPosition [_left, _top, _width, _height]; | |
_manbar ctrlCommit 0; | |
// draw script | |
private _script = _display ctrlCreate ["RscMapControl", -1]; | |
_script ctrlSetPosition [0,0,0,0]; | |
_script ctrlCommit 0; | |
_script ctrlAddEventHandler ["Draw", { | |
params ["_control"]; | |
private _display = ctrlParent _control; | |
// function to get the zoom, copied and edited from CBA_fnc_FOV | |
private _fnc_zoom = { | |
private _widthReal = safeZoneW / 2; | |
private _safeZoneAspectRatio = safeZoneW / safeZoneH; | |
private _pos = positionCameraToWorld [5000, 0, 10000]; | |
private _xPos = worldToScreen _pos select 0; | |
private _deltaX = _xPos - 0.5; | |
private _trigRatio = ((_widthReal * 5000) / (10000 * _deltaX)); | |
private _configFov = _trigRatio / _safeZoneAspectRatio; | |
0.25 / _configFov | |
}; | |
// Rodrigues Rotation Formula | |
// https://wikimedia.org/api/rest_v1/media/math/render/svg/2d63efa533bdbd776434af1a7af3cdafaff1d578 | |
// copy pasted from CBA_fnc_vectRotate3D | |
private _fnc_vectorRotate = { | |
params ["_vector", "_rotationAxis", "_theta"]; | |
private _normalVector = vectorNormalized _rotationAxis; | |
private _sinTheta = sin _theta; | |
private _cosTheta = cos _theta; | |
(_vector vectorMultiply _cosTheta) vectorAdd | |
((_normalVector vectorCrossProduct _vector) vectorMultiply _sinTheta) vectorAdd | |
(_normalVector vectorMultiply ((_normalVector vectorDotProduct _vector) * (1 - _cosTheta))) | |
}; | |
// get some vectors to work with | |
private _zoom = call _fnc_zoom; | |
private _start = AGLToASL positionCameraToWorld [0,0,0]; | |
private _end = AGLToASL positionCameraToWorld [0,0,1000]; | |
private _dir = _end vectorDiff _start; | |
private _vDir = _start vectorFromTo _end; | |
private _vLat = vectorNormalized (_vDir vectorCrossProduct [0,0,1]); | |
private _vUp = _vDir vectorCrossProduct _vLat; | |
// mildots | |
private _mildots = _display getVariable "BWA3_debugCrosshair_mildots"; | |
private _width = safezoneW/150*_zoom; | |
private _height = safezoneH/150*_zoom*(getResolution select 4); | |
private _left = 0.5 - _width/2; | |
private _top = 0.5 - _height/2; | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vUp, 5*commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _left = (worldToScreen ASLToAGL _milpos select 0) - pixelW/2; | |
_x ctrlSetPosition [_left, _top, pixelW, _height]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [0,10]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vUp, -5*commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _left = (worldToScreen ASLToAGL _milpos select 0) - pixelW/2; | |
_x ctrlSetPosition [_left, _top, pixelW, _height]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [10,10]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vLat, 5*commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _top = (worldToScreen ASLToAGL _milpos select 1) - pixelH/2; | |
_x ctrlSetPosition [_left, _top, _width, pixelH]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [20,10]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vLat, -5*commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _top = (worldToScreen ASLToAGL _milpos select 1) - pixelH/2; | |
_x ctrlSetPosition [_left, _top, _width, pixelH]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [30,10]); | |
_width = safezoneW/500*_zoom; | |
_height = safezoneH/500*_zoom*(getResolution select 4); | |
_left = 0.5 - _width/2; | |
_top = 0.5 - _height/2; | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vUp, commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _left = (worldToScreen ASLToAGL _milpos select 0) - pixelW/2; | |
_x ctrlSetPosition [_left, _top, pixelW, _height]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [40,4]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vUp, -commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _left = (worldToScreen ASLToAGL _milpos select 0) - pixelW/2; | |
_x ctrlSetPosition [_left, _top, pixelW, _height]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [44,4]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vLat, commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _top = (worldToScreen ASLToAGL _milpos select 1) - pixelH/2; | |
_x ctrlSetPosition [_left, _top, _width, pixelH]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [48,4]); | |
{ | |
private _milpos = _start vectorAdd ([_dir, _vLat, -commy_debugCrosshairMilToDegree*(_forEachIndex + 1)] call _fnc_vectorRotate); | |
private _top = (worldToScreen ASLToAGL _milpos select 1) - pixelH/2; | |
_x ctrlSetPosition [_left, _top, _width, pixelH]; | |
_x ctrlCommit 0; | |
} forEach (_mildots select [52,4]); | |
// magnification | |
private _magnification = _display getVariable "BWA3_debugCrosshair_magnification"; | |
_magnification ctrlSetText format ["%1x", _zoom toFixed 2]; | |
// man heights | |
private _manbars = _display getVariable "BWA3_debugCrosshair_manbars"; | |
_width = safezoneW/4/5; | |
_left = 0.5 - 5*_width/2; | |
_top = safeZoneY + safezoneH*7/8 - pixelH/2; | |
{ | |
private _distance = 200*(1 + _forEachIndex); | |
private _position = _start vectorAdd (_vDir vectorMultiply _distance) vectorAdd (_vUp vectorMultiply 1.8); | |
private _top = _top + 0.5 - (worldToScreen ASLToAGL _position select 1); | |
_x ctrlSetPosition [_left, _top, _width, pixelH]; | |
_x ctrlCommit 0; | |
_left = _left + _width; | |
} forEach _manbars; | |
}]; | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment