Example Code: Get Center: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (replaced params with param)
m (various changes)
Line 10: 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:
Line 16: Line 16:
*/
*/


private _positions = param [0,[]];
#define POSITIONS allUnits //Array of positions,objects, markers, groups or locations.
 
private _sumPositions = [0,0,0];
private _sumPositions = [0,0,0];


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


//Return center position
//Return center position
_sumPositions vectorMultiply 1 / count _positions</syntaxhighlight>
_sumPositions vectorMultiply 1 / count POSITIONS</syntaxhighlight>


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

Revision as of 11:05, 18 August 2019

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]
*/

#define POSITIONS allUnits //Array of positions,objects, markers, groups or locations.

private _sumPositions = [0,0,0];

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

//Return center position
_sumPositions vectorMultiply 1 / count POSITIONS