Example Code: Get Center: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Created page with "/* Author: R3vo Date: 2019-08-18 Description: Returns the center position of given coordinates or objects. Parameter(s): 0: ARRAY - Array of position sor...")
 
m (formatting)
Line 1: Line 1:
/*
<syntaxhighlight lang="cpp">/*
   Author: R3vo
   Author: R3vo


Line 20: Line 20:
{
{
_sumPositions = _sumPositions vectorAdd (_x call BIS_fnc_position);
_sumPositions = _sumPositions vectorAdd (_x call BIS_fnc_position);
systemChat str _sumPositions;
} forEach _positions;
} forEach _positions;


Line 31: Line 30:
_y / _count,
_y / _count,
_z / _count
_z / _count
]
]</syntaxhighlight>
 
[[Category: Example Code]]

Revision as of 02:24, 18 August 2019

/*
   Author: R3vo

   Date: 2019-08-18

   Description:
   Returns the center position of given coordinates or objects.

   Parameter(s):
   0: ARRAY -  Array of position sor objects.

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

params [["_positions"],[[]]];

private _sumPositions = [0,0,0];

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

//Return center position
_sumPositions params ["_x","_y","_z"];
private _count = count _positions;

[
	_x / _count,
	_y / _count,
	_z / _count
]