mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #2328 from acemod/322laserpointer
laserpointer with new command lineintersectssurface
This commit is contained in:
commit
2a82b97b5a
@ -1,30 +1,11 @@
|
|||||||
// by commy2 and esteldunedain
|
// by commy2 and esteldunedain
|
||||||
#include "script_component.hpp"
|
#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
|
private ["_p0", "_v1", "_v2", "_v3", "_p1", "_pL", "_distance", "_pL2", "_camPos", "_size"];
|
||||||
/*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];
|
|
||||||
|
|
||||||
GVAR(laserdot) = _light;
|
_p0 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "righthand"));
|
||||||
};*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Find a system of orthogonal reference vectors
|
// Find a system of orthogonal reference vectors
|
||||||
// _v1 points in the direction of the weapon
|
// _v1 points in the direction of the weapon
|
||||||
@ -36,68 +17,22 @@ _v3 = _v2 vectorCrossProduct _v1;
|
|||||||
|
|
||||||
// Offset over the 3 reference axis
|
// Offset over the 3 reference axis
|
||||||
// This offset could eventually be configured by weapon in the config
|
// This offset could eventually be configured by weapon in the config
|
||||||
_offV1 = 0.31;
|
#define OFFV1 0.31
|
||||||
_offV2 = 0;
|
#define OFFV2 0
|
||||||
_offV3 = 0.08;
|
#define OFFV3 0.08
|
||||||
|
|
||||||
// Offset _p0, the start of the laser
|
// Offset _p0, the start of the laser
|
||||||
_p0 = _p0 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);
|
||||||
_p0Pos = _p0Pos vectorAdd (_v1 vectorMultiply _offV1) vectorAdd (_v3 vectorMultiply _offV3) vectorAdd (_v2 vectorMultiply _offV2);
|
|
||||||
// Calculate _p1, the potential end of the laser
|
// Calculate _p1, the potential end of the laser
|
||||||
_p1 = _p0 vectorAdd (_v1 vectorMultiply _range);
|
_p1 = _p0 vectorAdd (_v1 vectorMultiply _range);
|
||||||
|
|
||||||
//Debugaaa = lineIntersectsObjs [_p0, _p1, objNull, _unit, false, 2];
|
_pL = lineIntersectsSurfaces [_p0, _p1, ACE_player, vehicle ACE_player, true, 1, "GEOM", "FIRE"] select 0 select 0;
|
||||||
|
|
||||||
_fnc_getDistanceToTerrain = {
|
// no intersection found, quit
|
||||||
private ["_distance"];
|
if (isNil "_pL") exitWith {};
|
||||||
|
|
||||||
_pX = + _p0;
|
_distance = _p0 vectorDistance _pL;
|
||||||
_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];
|
|
||||||
|
|
||||||
_distance = _distance + (([1, -1] select (lineIntersects (_line + [_unit]) || {terrainIntersectASL _line})) * _iteration);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
//systemChat str _distance;
|
//systemChat str _distance;
|
||||||
if (_distance < 0.5) exitWith {};
|
if (_distance < 0.5) exitWith {};
|
||||||
@ -105,31 +40,29 @@ if (_distance < 0.5) exitWith {};
|
|||||||
_pL = _p0 vectorAdd (_v1 vectorMultiply _distance);
|
_pL = _p0 vectorAdd (_v1 vectorMultiply _distance);
|
||||||
_pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5));
|
_pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5));
|
||||||
|
|
||||||
// Convert _pL to pos
|
_pL = ASLtoAGL _pL;
|
||||||
if (!surfaceIsWater _pL) then {
|
|
||||||
_pL = ASLtoATL _pL;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
drawLine3D [
|
drawLine3D [
|
||||||
_p0Pos,
|
_p0,
|
||||||
_pL,
|
_pL,
|
||||||
[[1,0,0,1], [0,1,0,1]] select _isGreen
|
[[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];
|
_camPos = positionCameraToWorld [0,0,0.2];
|
||||||
if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
||||||
if (count ([ACE_player, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
if (count ([ACE_player, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith {};
|
||||||
|
|
||||||
// Convert _camPos to ASL
|
// Convert _camPos to ASL
|
||||||
if (!surfaceIsWater _camPos) then { _camPos = ATLtoASL _camPos; };
|
_camPos = AGLToASL _camPos;
|
||||||
|
|
||||||
if ( terrainIntersectASL [_camPos, _pL2]) exitWith {};
|
if ( terrainIntersectASL [_camPos, _pL2]) exitWith {};
|
||||||
if ( lineIntersects [_camPos, _pL2]) exitWith {};
|
if ( lineIntersects [_camPos, _pL2]) exitWith {};
|
||||||
|
|
||||||
//GVAR(laserdot) setPos _pL;
|
_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range;
|
||||||
|
|
||||||
drawIcon3D [
|
drawIcon3D [
|
||||||
format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen],
|
format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen],
|
||||||
|
@ -35,7 +35,7 @@ _brightness = 2 - call EFUNC(common,ambientBrightness);
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (_laserID > 0 && {_x isFlashlightOn _weapon}) then {
|
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);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user