diff --git a/addons/laserpointer/functions/fnc_drawLaserpoint.sqf b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf index e69fc5e2715..34ca98808b7 100644 --- a/addons/laserpointer/functions/fnc_drawLaserpoint.sqf +++ b/addons/laserpointer/functions/fnc_drawLaserpoint.sqf @@ -1,30 +1,11 @@ // by commy2 and esteldunedain #include "script_component.hpp" -private ["_p0", "_p1", "_p0Pos", "_offV1", "_offV2", "_offV3", "_camPos", "_intermediatePos", "_iteration", "_light", "_line", "_pL", "_pL2", "_pX", "_size", "_units", "_fnc_getDistanceToTerrain", "_fnc_doesIntersectWithMan"]; +params ["_unit", "_range", "_isGreen", "_brightness"]; -// init object -/*if (isNil QGVAR(laserdot)) then { - _light = "#lightpoint" createVehicleLocal [0,0,0]; - _light setLightBrightness 10; - _light setLightColor [1,0,0]; - _light setLightAmbient [1,0,0]; - _light setLightDayLight true; - //_light lightAttachObject [GVAR(laserdot), [0,0,0]]; - _light setLightAttenuation [0.04,4,4,0,0.04,0.08]; +private ["_p0", "_v1", "_v2", "_v3", "_p1", "_pL", "_distance", "_pL2", "_camPos", "_size"]; - GVAR(laserdot) = _light; -};*/ - -EXPLODE_4_PVT(_this,_unit,_range,_isGreen,_brightness); - -_p0Pos = _unit modelToWorldVisual (_unit selectionPosition "righthand"); - -// Convert _p0Pos to ASL -_p0 = + _p0Pos; -if (!surfaceIsWater _p0) then { - _p0 = ATLtoASL _p0; -}; +_p0 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "righthand")); // Find a system of orthogonal reference vectors // _v1 points in the direction of the weapon @@ -36,68 +17,22 @@ _v3 = _v2 vectorCrossProduct _v1; // Offset over the 3 reference axis // This offset could eventually be configured by weapon in the config -_offV1 = 0.31; -_offV2 = 0; -_offV3 = 0.08; +#define OFFV1 0.31 +#define OFFV2 0 +#define OFFV3 0.08 // Offset _p0, the start of the laser -_p0 = _p0 vectorAdd (_v1 vectorMultiply _offV1) vectorAdd (_v3 vectorMultiply _offV3) vectorAdd (_v2 vectorMultiply _offV2); -_p0Pos = _p0Pos vectorAdd (_v1 vectorMultiply _offV1) vectorAdd (_v3 vectorMultiply _offV3) vectorAdd (_v2 vectorMultiply _offV2); +_p0 = _p0 vectorAdd (_v1 vectorMultiply OFFV1) vectorAdd (_v3 vectorMultiply OFFV3) vectorAdd (_v2 vectorMultiply OFFV2); + // Calculate _p1, the potential end of the laser _p1 = _p0 vectorAdd (_v1 vectorMultiply _range); -//Debugaaa = lineIntersectsObjs [_p0, _p1, objNull, _unit, false, 2]; - -_fnc_getDistanceToTerrain = { - private ["_distance"]; - - _pX = + _p0; - _line = [_p0, _pX]; - - _distance = _this; - _iteration = _distance; - - while {_iteration > 0.05 / 2} do { - _iteration = _iteration / 2; - - _pX = _p0 vectorAdd (_v1 vectorMultiply _distance); - - _line set [1, _pX]; +_pL = lineIntersectsSurfaces [_p0, _p1, ACE_player, vehicle ACE_player, true, 1, "GEOM", "FIRE"] select 0 select 0; - _distance = _distance + (([1, -1] select (lineIntersects (_line + [_unit]) || {terrainIntersectASL _line})) * _iteration); +// no intersection found, quit +if (isNil "_pL") exitWith {}; - if (_distance > _this) exitWith {_distance = _this}; - }; - - _distance -}; - -// Get distance to nearest object or terrain (excluding men) -_distance = _range call _fnc_getDistanceToTerrain; - -// Find all men potentially intercepted by the ray -_intermediatePos = _p0 vectorAdd (_v1 vectorMultiply _distance/2); -if (!surfaceIsWater _intermediatePos) then { - _intermediatePos = ASLtoATL _intermediatePos; -}; -_units = nearestObjects [_intermediatePos, ["Man"], _distance/2]; - -_units deleteAt (_units find _unit); - -_fnc_doesIntersectWithMan = { - _pX = _p0 vectorAdd (_v1 vectorMultiply (_this select 1)); - if (!surfaceIsWater _pX) then { - _pX = ASLtoATL _pX; - }; - count ([_this select 0, "FIRE"] intersect [_p0Pos, _pX]) > 0 -}; - -// Test intersection with nearby men -{ - if ([_x, _distance] call _fnc_doesIntersectWithMan) then { - _distance = _distance min ((_unit distance _x) - _offV1); - }; -} forEach _units; +_distance = _p0 vectorDistance _pL; //systemChat str _distance; if (_distance < 0.5) exitWith {}; @@ -105,31 +40,29 @@ if (_distance < 0.5) exitWith {}; _pL = _p0 vectorAdd (_v1 vectorMultiply _distance); _pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5)); -// Convert _pL to pos -if (!surfaceIsWater _pL) then { - _pL = ASLtoATL _pL; -}; +_pL = ASLtoAGL _pL; /* drawLine3D [ - _p0Pos, + _p0, _pL, [[1,0,0,1], [0,1,0,1]] select _isGreen ]; */ -_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range; +//systemChat str [_unit, "FIRE"] intersect [_camPos, _pL]; _camPos = positionCameraToWorld [0,0,0.2]; if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {}; if (count ([ACE_player, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {}; // Convert _camPos to ASL -if (!surfaceIsWater _camPos) then { _camPos = ATLtoASL _camPos; }; +_camPos = AGLToASL _camPos; + if ( terrainIntersectASL [_camPos, _pL2]) exitWith {}; if ( lineIntersects [_camPos, _pL2]) exitWith {}; -//GVAR(laserdot) setPos _pL; +_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range; drawIcon3D [ format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen], diff --git a/addons/laserpointer/functions/fnc_onDraw.sqf b/addons/laserpointer/functions/fnc_onDraw.sqf index 09663f9ecf0..9e61e70156c 100644 --- a/addons/laserpointer/functions/fnc_onDraw.sqf +++ b/addons/laserpointer/functions/fnc_onDraw.sqf @@ -35,7 +35,7 @@ _brightness = 2 - call EFUNC(common,ambientBrightness); }; if (_laserID > 0 && {_x isFlashlightOn _weapon}) then { - [_x, 50, (_laserID == 2 || _isIR), _brightness] call FUNC(drawLaserpoint); + [_x, 100, (_laserID == 2 || _isIR), _brightness] call FUNC(drawLaserpoint); }; };