Skip to content

Instantly share code, notes, and snippets.

@dedmen
Last active October 4, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedmen/61643bd7b7205c13b68bff4b214f5840 to your computer and use it in GitHub Desktop.
Save dedmen/61643bd7b7205c13b68bff4b214f5840 to your computer and use it in GitHub Desktop.
GetMatrixFromDirAndUp = {
params ["_vectorDir", "_vectorUp"];
private _xAxis = vectorNormalized (_vectorDir vectorCrossProduct _vectorUp);
[
[_xAxis#0, _vectorDir#0, _vectorUp#0],
[_xAxis#1, _vectorDir#1, _vectorUp#1],
[_xAxis#2, _vectorDir#2, _vectorUp#2]
];
};
GetWeaponLaserOffsetAndDir = {
params ["_unit"];
"WeapHash = createHashMap; disable cache if testing";
if (isNil "WeapHash") then {WeapHash = createHashMap;};
private _sideAttachmentType = primaryWeaponItems _unit select 1;
private _weaponComboName = primaryWeapon _unit + _sideAttachmentType;
if (_weaponComboName in WeapHash) exitWith {WeapHash get _weaponComboName};
private _model = getText (configFile >> "CfgWeapons" >> primaryWeapon _unit >> "model");
private _tempObject = createSimpleObject [_model, [0,0,0], true];
private _sideAttachOffset = _tempObject selectionPosition ["proxy:\a3\data_f\proxies\weapon_slots\side.001", 1];
private _sideAttachDir = (_tempObject selectionVectorDirAndUp ["proxy:\a3\data_f\proxies\weapon_slots\side.001", 1]);
deleteVehicle _tempObject;
private _attachmentClass = configFile >> "CfgWeapons" >> _sideAttachmentType;
private _model = getText (_attachmentClass >> "model");
private _tempObject = createSimpleObject [_model, [0,0,0], true];
private _memPointName = getText (_attachmentClass >> "ItemInfo" >> "Pointer" >> "irLaserPos");
private _laserOffset = _tempObject selectionPosition [_memPointName, "Memory"];
private _laserDir = (_tempObject selectionVectorDirAndUp [_memPointName, "Memory"]);
deleteVehicle _tempObject;
"Combine both directions into a matrix for later";
private _rotationMatrix = (_sideAttachDir call GetMatrixFromDirAndUp) matrixMultiply (_laserDir call GetMatrixFromDirAndUp);
"laserOffset needs to take sideAttachRotation into account";
private _rotatedLaserOffset = (_sideAttachDir call GetMatrixFromDirAndUp) matrixMultiply matrixTranspose [_laserOffset];
_rotatedLaserOffset = (matrixTranspose _rotatedLaserOffset) select 0;
private _result = [_sideAttachOffset vectorAdd _rotatedLaserOffset, _rotationMatrix];
WeapHash set [_weaponComboName, _result];
_result
};
onEachFrame {
private _playerPos = getPosWorldVisual player;
private _gunOffset = player selectionPosition ["proxy:\a3\characters_f\proxies\weapon.001", 1];
private _gunDir = (player selectionVectorDirAndUp ["proxy:\a3\characters_f\proxies\weapon.001", 1]);
(player call GetWeaponLaserOffsetAndDir) params ["_gunToLaserOffs", "_gunToLaserRotationMatrix"];
private _gunRotMatrix = _gunDir call GetMatrixFromDirAndUp;
private _rotatedLaserOffset = _gunRotMatrix matrixMultiply [[(_gunToLaserOffs#0)],[(_gunToLaserOffs#1)],[(_gunToLaserOffs#2)]];
_rotatedLaserOffset = (matrixTranspose _rotatedLaserOffset) select 0;
private _rotatedLaserRotation = _gunToLaserRotationMatrix matrixMultiply _gunRotMatrix;
"hintSilent str _gunToLaserRotationMatrix; ";
_rotatedLaserRotation = [-(_rotatedLaserRotation#0#0),_rotatedLaserRotation#1#0,_rotatedLaserRotation#2#0];
private _laserSourceOffset = _gunOffset vectorAdd _rotatedLaserOffset;
private _laserSource = (player modelToWorldVisualWorld _laserSourceOffset);
private _laserDirectionAbsolute = player vectorModelToWorldVisual _rotatedLaserRotation;
_colors = [
[0.3, 0.3, 0.5],
[0, 0.2, 0],
[0.73, 0.24, 0.11],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[0, 1, 1],
[1, 1, 0]
];
private _aSide = vectorNormalized (_laserDirectionAbsolute vectorCrossProduct [0,0,1]);
private _up = vectorNormalized (_aSide vectorCrossProduct _laserDirectionAbsolute);
private _laserRotationMatrix = [_up, _laserDirectionAbsolute] call GetMatrixFromDirAndUp;
for "_i" from 1 to 8 do {
_dir = [1, _i*45 + diag_frameNo, ((abs sin diag_frameNo )* 90) mod 90] call CBA_fnc_polar2vect;
private _rotatedLaserOffset = _laserRotationMatrix matrixMultiply matrixTranspose [_dir];
_rotatedLaserOffset = (matrixTranspose _rotatedLaserOffset) select 0;
_color = (_colors select (_i-1)) vectorMultiply 1000;
drawLaser [_laserSource, vectorNormalized (_rotatedLaserOffset), _color, [], 2, 20 * sin diag_frameNo*2, -1, true];
};
};
// normal weapon lazer (non cray cray)
onEachFrame {
private _playerPos = getPosWorldVisual player;
private _gunOffset = player selectionPosition ["proxy:\a3\characters_f\proxies\weapon.001", 1];
private _gunDir = (player selectionVectorDirAndUp ["proxy:\a3\characters_f\proxies\weapon.001", 1]);
(player call GetWeaponLaserOffsetAndDir) params ["_gunToLaserOffs", "_gunToLaserRotationMatrix"];
private _gunRotMatrix = _gunDir call GetMatrixFromDirAndUp;
private _rotatedLaserOffset = _gunRotMatrix matrixMultiply [[(_gunToLaserOffs#0)],[(_gunToLaserOffs#1)],[(_gunToLaserOffs#2)]];
_rotatedLaserOffset = (matrixTranspose _rotatedLaserOffset) select 0;
private _rotatedLaserRotation = _gunToLaserRotationMatrix matrixMultiply _gunRotMatrix;
"hintSilent str _gunToLaserRotationMatrix; ";
_rotatedLaserRotation = [-(_rotatedLaserRotation#0#0),_rotatedLaserRotation#1#0,_rotatedLaserRotation#2#0];
private _laserSourceOffset = _gunOffset vectorAdd _rotatedLaserOffset;
private _laserSource = (player modelToWorldVisualWorld _laserSourceOffset);
private _laserDirectionAbsolute = player vectorModelToWorldVisual _rotatedLaserRotation;
drawLaser [_laserSource, vectorNormalized (_laserDirectionAbsolute), [1000,1,1,1], [], 1, 20, -1, true];
};
// UAV laser
RenderSelectionsOf = {
{
drawIcon3D ["a3\ui_f\data\gui\Rsc\RscDisplayArsenal\radio_ca.paa", [1,0,0,1], (_this modelToWorldVisual (_this selectionPosition [_x, 1])), 0.2, 00.2, 0, _x, 1, 0.05, "PuristaMedium"];
} forEach (_this selectionNames 1);
{
drawIcon3D ["a3\ui_f\data\gui\Rsc\RscDisplayArsenal\radio_ca.paa", [0,0,1,1], (_this modelToWorldVisual (_this selectionPosition [_x, "Memory"])), 0.2, 00.2, 0, _x, 1, 0.05, "PuristaMedium"];
} forEach (_this selectionNames "Memory");
};
RenderDroneLaser = {
{
private _uav = _x;
"flir_axis"; "turret_axis"; "pip0_pos"; "pip0_dir";
// potentially better configOf _x >> "Turrets" >> "MainTurret" >> "memoryPointGun"
// atleast for UAV_02_base_F and UAV_01_base_F that returns the same point as "uavCameraGunnerDir"
// but technically only the turret memoryPointGun is the source for the actual laser designator
private _memoryName = getText (configOf _x >> "uavCameraGunnerDir");
private _gunOffset = _uav selectionPosition [_memoryName, "Memory"];
private _gunDir = (_uav selectionVectorDirAndUp [_memoryName, "Memory"]) select 0;
private _laserSource = _uav modelToWorldVisualWorld _gunOffset;
private _laserDirectionAbsolute = _uav vectorModelToWorldVisual _gunDir;
drawLaser [_laserSource, _laserDirectionAbsolute, [1000,0,0], 30, 60, false];
} forEach (allUnitsUAV select {isLaserOn _x})
};
onEachFrame {
drone1 call RenderSelectionsOf;
call RenderDroneLaser;
};
@dedmen
Copy link
Author

dedmen commented Sep 2, 2021

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