* Added function to obtain *average* Vec3 of the GROUP
* Added function to obtain *average* Coordinate of the GROUP

#TARGET
* Make use of new coordinate function in GROUP
This commit is contained in:
Applevangelist 2022-10-16 13:37:11 +02:00
commit cefb5d98f0
2 changed files with 49 additions and 3 deletions

View File

@ -1141,7 +1141,7 @@ function TARGET:GetTargetVec3(Target)
local object=Target.Object --Wrapper.Group#GROUP
if object and object:IsAlive() then
local vec3=object:GetVec3()
local vec3=object:GetAverageVec3()
if vec3 then
return vec3

View File

@ -1019,9 +1019,9 @@ function GROUP:GetVec2()
end
--- Returns the current Vec3 vector of the first DCS Unit in the GROUP.
--- Returns the current Vec3 vector of the first Unit in the GROUP.
-- @param #GROUP self
-- @return DCS#Vec3 Current Vec3 of the first DCS Unit of the GROUP.
-- @return DCS#Vec3 Current Vec3 of the first Unit of the GROUP or nil if cannot be found.
function GROUP:GetVec3()
-- Get first unit.
@ -1036,6 +1036,37 @@ function GROUP:GetVec3()
return nil
end
--- Returns the average Vec3 vector of the Units in the GROUP.
-- @param #GROUP self
-- @return DCS#Vec3 Current Vec3 of the GROUP or nil if cannot be found.
function GROUP:GetAverageVec3()
local units = self:GetUnits() or {}
-- Init.
local x=0 ; local y=0 ; local z=0 ; local n=0
-- Loop over all units.
for _,unit in pairs(units) do
local vec3=nil --DCS#Vec3
if unit and unit:IsAlive() then
vec3 = unit:GetVec3()
end
if vec3 then
-- Sum up posits.
x=x+vec3.x
y=y+vec3.y
z=z+vec3.z
-- Increase counter.
n=n+1
end
end
if n>0 then
-- Average.
local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
return Vec3
end
return nil
end
--- Returns a POINT_VEC2 object indicating the point in 2D of the first UNIT of the GROUP within the mission.
-- @param #GROUP self
-- @return Core.Point#POINT_VEC2 The 2D point vector of the first DCS Unit of the GROUP.
@ -1056,6 +1087,21 @@ function GROUP:GetPointVec2()
return nil
end
--- Returns a COORDINATE object indicating the average position of the GROUP within the mission.
-- @param Wrapper.Group#GROUP self
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.
function GROUP:GetAverageCoordinate()
local vec3 = self:GetAverageVec3()
if vec3 then
local coord = COORDINATE:NewFromVec3(vec3)
local Heading = self:GetHeading()
coord.Heading = Heading
else
BASE:E( { "Cannot GetAverageCoordinate", Group = self, Alive = self:IsAlive() } )
return nil
end
end
--- Returns a COORDINATE object indicating the point of the first UNIT of the GROUP within the mission.
-- @param Wrapper.Group#GROUP self
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.