ACE3/addons/laserpointer/functions/fnc_drawLaserpoint.sqf

110 lines
3.2 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
2015-11-23 19:52:04 +00:00
/*
* Author: commy2 and esteldunedain
* Draw a Laser Point
*
* Arguments:
* 0: Target unit <OBJECT>
* 1: Range <NUMBER>
* 2: is Green <BOOL>
* 3: Brightness <NUMBER>
*
* Return Value:
* None
*
* Example:
* [player, 10, false, 2] call ace_laserpointer_fnc_drawLaserpoint
*
* Public: No
*/
2015-01-17 22:38:13 +00:00
2015-11-23 19:52:04 +00:00
params ["_target", "_range", "_isGreen", "_brightness"];
2015-06-13 08:41:19 +00:00
2015-11-23 19:52:04 +00:00
private _unit = ACE_player;
2015-04-14 11:14:37 +00:00
private _p0 = _target modelToWorldVisualWorld (_target selectionPosition "righthand");
2015-01-17 22:38:13 +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
2015-11-23 19:52:04 +00:00
private _v1 = _target weaponDirection currentWeapon _target;
private _v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]);
private _v3 = _v2 vectorCrossProduct _v1;
// Offset over the 3 reference axis
// This offset could eventually be configured by weapon in the config
#define OFFV1 0.31
#define OFFV2 0
#define OFFV3 0.08
// Offset _p0, the start of the laser
2015-11-23 19:52:04 +00:00
_p0 = _p0 vectorAdd (_v1 vectorMultiply OFFV1) vectorAdd (_v3 vectorMultiply OFFV3) vectorAdd (_v2 vectorMultiply OFFV2);
// Calculate _p1, the potential end of the laser
2015-11-23 19:52:04 +00:00
private _p1 = _p0 vectorAdd (_v1 vectorMultiply _range);
2015-11-23 19:52:04 +00:00
private _pL = lineIntersectsSurfaces [_p0, _p1, _unit, vehicle _unit] select 0 select 0;
2015-01-17 22:38:13 +00:00
// no intersection found, quit (pointed to the sky or too far)
if (isNil "_pL") exitWith {};
2015-01-17 22:38:13 +00:00
2015-11-23 19:52:04 +00:00
private _distance = _p0 vectorDistance _pL;
2015-01-17 22:38:13 +00:00
//systemChat str _distance;
if (_distance < 0.5) exitWith {};
_pL = _p0 vectorAdd (_v1 vectorMultiply _distance);
2015-11-23 19:52:04 +00:00
private _pL2 = _p0 vectorAdd (_v1 vectorMultiply (_distance - 0.5));
2015-01-17 22:38:13 +00:00
_pL = ASLtoAGL _pL;
2015-01-17 22:38:13 +00:00
2015-04-14 11:14:37 +00:00
/*
drawLine3D [
_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-11-23 19:52:04 +00:00
//systemChat str [_target, "FIRE"] intersect [_camPos, _pL];
private _camPos = positionCameraToWorld [0,0,0.2];
2015-01-17 22:38:13 +00:00
// Check for blocking laser by player or external laser source (other player)
private _blocked = false;
if (_unit isEqualTo _target && {cameraView in ["INTERNAL","GUNNER"]}) then {
// Laser belongs to player: check VIEW LOD
// (it's less detailed & fallbacks to GEO if not present, but allows to draw laser mark behind bulletproof glass)
if (count ([_unit, "VIEW"] intersect [_camPos, _pL]) > 0) exitWith { _blocked = true; };
} else {
// External laser: check FIRE GEO LOD (more detailed)
if (count ([_target, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith { _blocked = true; };
if (count ([_unit, "FIRE"] intersect [_camPos, _pL]) > 0) exitWith { _blocked = true; };
};
// Exit due to LOS blocked by source/player
if (_blocked) exitWith {};
// Convert _camPos to ASL
_camPos = AGLToASL _camPos;
// Check for blocking by terrain or object
2015-11-23 19:52:04 +00:00
if (terrainIntersectASL [_camPos, _pL2]) exitWith {};
if (lineIntersects [_camPos, _pL2]) exitWith {};
2015-01-17 22:38:13 +00:00
2015-12-09 21:56:14 +00:00
private _size = 2 * sqrt (1 / _distance) * (call EFUNC(common,getZoom));
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],
2016-10-11 03:06:37 +00:00
[[1,0.25,0.25,0.6*_brightness], [0.25,1,0.25,0.5*_brightness]] select _isGreen,
2015-01-17 22:38:13 +00:00
_pL,
_size,
_size,
45,
"",
0,
0.05
];