2015-03-24 04:18:00 +00:00
|
|
|
// by commy2 and esteldunedain
|
2015-01-17 22:38:13 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
params ["_unit", "_range", "_isGreen", "_brightness"];
|
2015-06-13 08:41:19 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
private ["_p0", "_v1", "_v2", "_v3", "_p1", "_pL", "_distance", "_pL2", "_camPos", "_size"];
|
2015-04-14 11:14:37 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
_p0 = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "righthand"));
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Find a system of orthogonal reference vectors
|
|
|
|
// _v1 points in the direction of the weapon
|
|
|
|
// _v2 points to the right of the weapon
|
|
|
|
// _v3 points to the top side of the weapon
|
|
|
|
_v1 = _unit weaponDirection currentWeapon _unit;
|
|
|
|
_v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]);
|
|
|
|
_v3 = _v2 vectorCrossProduct _v1;
|
|
|
|
|
|
|
|
// Offset over the 3 reference axis
|
|
|
|
// This offset could eventually be configured by weapon in the config
|
2015-08-31 15:31:37 +00:00
|
|
|
#define OFFV1 0.31
|
|
|
|
#define OFFV2 0
|
|
|
|
#define OFFV3 0.08
|
2015-01-18 02:51:31 +00:00
|
|
|
|
|
|
|
// Offset _p0, the start of the laser
|
2015-08-31 15:31:37 +00:00
|
|
|
_p0 = _p0 vectorAdd (_v1 vectorMultiply OFFV1) vectorAdd (_v3 vectorMultiply OFFV3) vectorAdd (_v2 vectorMultiply OFFV2);
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
// Calculate _p1, the potential end of the laser
|
|
|
|
_p1 = _p0 vectorAdd (_v1 vectorMultiply _range);
|
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
_pL = lineIntersectsSurfaces [_p0, _p1, ACE_player, vehicle ACE_player, true, 1, "GEOM", "FIRE"] select 0 select 0;
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
// no intersection found, quit
|
|
|
|
if (isNil "_pL") exitWith {};
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
_distance = _p0 vectorDistance _pL;
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
//systemChat str _distance;
|
|
|
|
if (_distance < 0.5) exitWith {};
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
_pL = _p0 vectorAdd (_v1 vectorMultiply _distance);
|
|
|
|
_pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5));
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
_pL = ASLtoAGL _pL;
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-04-14 11:14:37 +00:00
|
|
|
/*
|
|
|
|
drawLine3D [
|
2015-08-31 15:31:37 +00:00
|
|
|
_p0,
|
2015-04-14 11:14:37 +00:00
|
|
|
_pL,
|
|
|
|
[[1,0,0,1], [0,1,0,1]] select _isGreen
|
|
|
|
];
|
|
|
|
*/
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
//systemChat str [_unit, "FIRE"] intersect [_camPos, _pL];
|
2015-01-17 22:38:13 +00:00
|
|
|
|
|
|
|
_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 {};
|
2015-01-18 02:51:31 +00:00
|
|
|
|
|
|
|
// Convert _camPos to ASL
|
2015-08-31 15:31:37 +00:00
|
|
|
_camPos = AGLToASL _camPos;
|
|
|
|
|
2015-01-18 02:51:31 +00:00
|
|
|
if ( terrainIntersectASL [_camPos, _pL2]) exitWith {};
|
|
|
|
if ( lineIntersects [_camPos, _pL2]) exitWith {};
|
2015-01-17 22:38:13 +00:00
|
|
|
|
2015-08-31 15:31:37 +00:00
|
|
|
_size = 2 * (_range - (positionCameraToWorld [0,0,0] vectorDistance _pL)) / _range;
|
2015-04-14 11:14:37 +00:00
|
|
|
|
2015-01-17 22:38:13 +00:00
|
|
|
drawIcon3D [
|
|
|
|
format ["\a3\weapons_f\acc\data\collimdot_%1_ca.paa", ["red", "green"] select _isGreen],
|
|
|
|
[[1,0.25,0.25,0.5*_brightness], [0.25,1,0.25,0.5*_brightness]] select _isGreen,
|
|
|
|
_pL,
|
|
|
|
_size,
|
|
|
|
_size,
|
|
|
|
45,
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
0.05
|
|
|
|
];
|