Example Code: Get Center: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (formatting)
m (Some wiki formatting)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
<syntaxhighlight lang="cpp">/*
{{GVI|arma3|1.92}}
 
<sqf>/*
   Author: R3vo
   Author: R3vo


Line 8: Line 10:


   Parameter(s):
   Parameter(s):
   0: ARRAY -  Array of position sor objects.
   0: ARRAY -  Array of positions, objects, markers, groups or locations.


   Returns:
   Returns:
   ARRAY: Array of center in form [x,y,z]
   ARRAY - Array of center in form [x,y,z]
*/
*/


params [["_positions"],[[]]];
params [
["_entities", [], [[]]] // array of positions, objects, markers, groups or locations
];


private _sumPositions = [0,0,0];
private _sumPositions = [0,0,0];
if (_entities isEqualTo []) exitWith { _sumPositions };


{
{
_sumPositions = _sumPositions vectorAdd (_x call BIS_fnc_position);
_sumPositions = _sumPositions vectorAdd (_x call BIS_fnc_position);
} forEach _positions;
} forEach _entities;


//Return center position
// return center position
_sumPositions params ["_x","_y","_z"];
_sumPositions vectorMultiply (1 / count _entities);
private _count = count _positions;
</sqf>


[
_x / _count,
_y / _count,
_z / _count
]</syntaxhighlight>


[[Category: Example Code]]
[[Category: Example Code]]

Latest revision as of 18:43, 2 April 2022

Arma 3 logo black.png1.92

/* Author: R3vo Date: 2019-08-18 Description: Returns the center position of given coordinates or objects. Parameter(s): 0: ARRAY - Array of positions, objects, markers, groups or locations. Returns: ARRAY - Array of center in form [x,y,z] */ params [ ["_entities", [], [[]]] // array of positions, objects, markers, groups or locations ]; private _sumPositions = [0,0,0]; if (_entities isEqualTo []) exitWith { _sumPositions }; { _sumPositions = _sumPositions vectorAdd (_x call BIS_fnc_position); } forEach _entities; // return center position _sumPositions vectorMultiply (1 / count _entities);