mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-13 19:52:38 +03:00
Update fn_inAngleSector.sqf
Made by @Victor-the-Cleaner
This commit is contained in:
@@ -1,37 +1,30 @@
|
||||
//------------------
|
||||
// Authors: Peter Morrison (snYpir) & Philipp Pilhofer (raedor)
|
||||
// Purpose: Checks if a position lies within an angle sector
|
||||
// Arguments: [<center position>,<center angle of sector>,<sector width>,<position>]
|
||||
// Return: boolean
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/*
|
||||
Returns true if <position> lies within the sector defined by <center position>,
|
||||
<center angle of sector> and <sector width>. Use this function to determine if
|
||||
a position lies within a certain angle from another position (ie the <center position>).
|
||||
Example:
|
||||
[position player,getdir player,30,position enemy_tank] call BIS_fnc_inAngleSector
|
||||
will return true if the vehicle named enemy_tank is within 30 degrees of where the player is pointing.
|
||||
*/
|
||||
// Revision History:
|
||||
// 09/01/08 0.1 - First cut VBS2
|
||||
//------------------
|
||||
private["_small","_large","_xpos","_ypos","_dir2","_dir3"];
|
||||
// Purpose: Checks if a position lies within an angle sector
|
||||
// Arguments: [<center position>, <center angle of sector>, <sector width>, <position>]
|
||||
// Return: boolean
|
||||
//
|
||||
// Returns true if <position> lies within the sector defined by <center position>,
|
||||
// <center angle of sector> and <sector width>.
|
||||
//
|
||||
// Example:
|
||||
// [position player, getDir player, 30, position enemy_tank] call BIS_fnc_inAngleSector
|
||||
// will return true if the vehicle named enemy_tank is within 30 degrees of where the player is pointing.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Optimized for 1.0.7.1
|
||||
//
|
||||
// Transpose the rightmost radial arm to 0 degrees and calculate target direction
|
||||
// using CCW trig convention. Keep sector width to < 180 degrees when calling this function.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
local _source = _this select 0; // center position
|
||||
local _width = _this select 2; // sector width
|
||||
local _target = _this select 3; // target position
|
||||
local _px = (_target select 0) - (_source select 0); // x relative
|
||||
local _py = (_target select 1) - (_source select 1); // y relative
|
||||
local _dir = -(_px atan2 _py) + 360; // get CCW relative angle from x,y coords
|
||||
local _relDir = (_dir + (_this select 1) + (_width * 0.5)) % 360; // transpose target direction by source direction plus half angle sector
|
||||
|
||||
_r = false;
|
||||
|
||||
_small = (_this select 1) - ((_this select 2) / 2);
|
||||
_large = (_this select 1) + ((_this select 2) / 2);
|
||||
|
||||
_xpos = ((_this select 3) select 0) - ((_this select 0) select 0);
|
||||
_ypos = ((_this select 3) select 1) - ((_this select 0) select 1);
|
||||
|
||||
_dir1 = _xpos atan2 _ypos;
|
||||
|
||||
if (_dir1 < 0) then {_dir1 = _dir1 + 360};
|
||||
|
||||
_dir2 = _dir1 - 360;
|
||||
_dir3 = _dir1 + 360;
|
||||
|
||||
if ((_dir1 >= _small && _dir1 <= _large) || (_dir2 >= _small && _dir2 <= _large) || (_dir3 >= _small && _dir3 <= _large)) then {_r = true};
|
||||
|
||||
_r
|
||||
_relDir <= _width // is target in angle sector?
|
||||
|
||||
Reference in New Issue
Block a user