mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3cee8dafe | ||
|
|
3686e0de63 | ||
|
|
2931b32ce6 |
@@ -133,7 +133,10 @@ VECTOR = {
|
|||||||
|
|
||||||
--- VECTOR class version.
|
--- VECTOR class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
VECTOR.version="0.0.2"
|
VECTOR.version="0.0.3"
|
||||||
|
|
||||||
|
--- VECTOR unique ID
|
||||||
|
_VECTORID=0
|
||||||
|
|
||||||
--- VECTOR private index.
|
--- VECTOR private index.
|
||||||
-- @field #VECTOR __index
|
-- @field #VECTOR __index
|
||||||
@@ -169,6 +172,10 @@ function VECTOR:New(x, y, z)
|
|||||||
self=setmetatable({x=x or 0, y=y or 0, z=z or 0}, VECTOR)
|
self=setmetatable({x=x or 0, y=y or 0, z=z or 0}, VECTOR)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_VECTORID=_VECTORID+1
|
||||||
|
|
||||||
|
self.uid=_VECTORID
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -275,7 +282,7 @@ end
|
|||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #number Latitude Latitude in decimal degrees.
|
-- @param #number Latitude Latitude in decimal degrees.
|
||||||
-- @param #number Longitude Longitude in decimal degrees.
|
-- @param #number Longitude Longitude in decimal degrees.
|
||||||
-- @param #number altitude (Optional) Altitude in meters. Default is the land height at the 2D position.
|
-- @param #number Altitude (Optional) Altitude in meters. Default is the land height at the 2D position.
|
||||||
-- @return #VECTOR self
|
-- @return #VECTOR self
|
||||||
function VECTOR:NewFromLLDD(Latitude, Longitude, Altitude)
|
function VECTOR:NewFromLLDD(Latitude, Longitude, Altitude)
|
||||||
|
|
||||||
@@ -285,12 +292,10 @@ function VECTOR:NewFromLLDD(Latitude, Longitude, Altitude)
|
|||||||
-- Convert vec3 to coordinate object.
|
-- Convert vec3 to coordinate object.
|
||||||
self=VECTOR:NewFromVec(vec3)
|
self=VECTOR:NewFromVec(vec3)
|
||||||
|
|
||||||
-- -- Adjust height
|
-- Adjust height
|
||||||
-- if Altitude==nil then
|
if Altitude then
|
||||||
-- self.y=self:GetSurfaceHeight()
|
self.y=Altitude
|
||||||
-- else
|
end
|
||||||
-- self.y=Altitude
|
|
||||||
-- end
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -526,18 +531,29 @@ function VECTOR:GetLatitudeLongitude()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get MGRS coordinates of this vector.
|
--- Get MGRS information of this vector.
|
||||||
|
--
|
||||||
|
-- `MGRS = {UTMZone = string, MGRSDigraph = string, Easting = number, Northing = number}`
|
||||||
|
--
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #VECTOR Vector Vector from which the heading is requested.
|
-- @return #table MGRS table with `UTMZone`, `MGRSDiGraph`, `Easting` and `Northing` keys.
|
||||||
-- @return #number Latitude
|
|
||||||
-- @return #number Longitude
|
|
||||||
function VECTOR:GetMGRS()
|
function VECTOR:GetMGRS()
|
||||||
|
|
||||||
local lat, long=self:GetLatitudeLongitude()
|
local lat, long=self:GetLatitudeLongitude()
|
||||||
|
|
||||||
local mrgs=coord.LLtoMGRS(lat, long)
|
local mgrs=coord.LLtoMGRS(lat, long)
|
||||||
|
|
||||||
return mrgs.Easing, mrgs.Northing
|
-- Example table returned by coord.LLtoMGRS
|
||||||
|
--[[
|
||||||
|
MGRS = {
|
||||||
|
UTMZone = string,
|
||||||
|
MGRSDigraph = string,
|
||||||
|
Easting = number,
|
||||||
|
Northing = number
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
|
return mgrs
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the difference of the heading of this vector w.
|
--- Get the difference of the heading of this vector w.
|
||||||
@@ -569,7 +585,7 @@ end
|
|||||||
-- @param #VECTOR Vector The destination vector.
|
-- @param #VECTOR Vector The destination vector.
|
||||||
-- @param #number Fraction The fraction (0,1) where the new vector is created. Default 0.5, *i.e.* in the middle.
|
-- @param #number Fraction The fraction (0,1) where the new vector is created. Default 0.5, *i.e.* in the middle.
|
||||||
-- @return #VECTOR Vector between this and the other vector.
|
-- @return #VECTOR Vector between this and the other vector.
|
||||||
function VECTOR:GetIntermediateCoordinate(Vector, Fraction)
|
function VECTOR:GetIntermediateVector(Vector, Fraction)
|
||||||
|
|
||||||
local f=Fraction or 0.5
|
local f=Fraction or 0.5
|
||||||
|
|
||||||
@@ -582,12 +598,6 @@ function VECTOR:GetIntermediateCoordinate(Vector, Fraction)
|
|||||||
-- Set/scale the length.
|
-- Set/scale the length.
|
||||||
vec:SetLength(f*length)
|
vec:SetLength(f*length)
|
||||||
|
|
||||||
--TODO: Not sure what this was supposed to do?!
|
|
||||||
-- if f>1 then
|
|
||||||
-- local norm=UTILS.VecNorm(vec)
|
|
||||||
-- f=Fraction/norm
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- Get to the desired position.
|
-- Get to the desired position.
|
||||||
vec=self+vec
|
vec=self+vec
|
||||||
|
|
||||||
@@ -638,14 +648,13 @@ end
|
|||||||
--- Set z-component of vector. The z-axis points to the East.
|
--- Set z-component of vector. The z-axis points to the East.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #number z Value of z. Default 0.
|
-- @param #number z Value of z. Default 0.
|
||||||
-- @param #VECTOR self
|
-- @return #VECTOR self
|
||||||
function VECTOR:SetZ(z)
|
function VECTOR:SetZ(z)
|
||||||
self.z=z or 0
|
self.z=z or 0
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Add a vector to this. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
|
--- Add a vector to this. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
|
||||||
-- Note that if you want to add a VECTOR, you can also simply use the `+` operator.
|
-- Note that if you want to add a VECTOR, you can also simply use the `+` operator.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
@@ -666,8 +675,9 @@ function VECTOR:AddVec(Vec)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Substract a vector from this one. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
|
--- Subtract a vector from this one. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
|
||||||
-- Note that if you want to add a VECTOR, you can also simply use the `-` operator.
|
--
|
||||||
|
-- **Note** that if you want to add a VECTOR, you can also simply use the `-` operator.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param DCS#Vec3 Vec Vector to substract. Can also be a DCS#Vec2, DCS#Vec3, COORDINATE or VECTOR object.
|
-- @param DCS#Vec3 Vec Vector to substract. Can also be a DCS#Vec2, DCS#Vec3, COORDINATE or VECTOR object.
|
||||||
-- @return #VECTOR self
|
-- @return #VECTOR self
|
||||||
@@ -818,10 +828,14 @@ function VECTOR:Rotate2D(Angle, Copy)
|
|||||||
local x = X*sinPhi + Y*cosPhi
|
local x = X*sinPhi + Y*cosPhi
|
||||||
|
|
||||||
-- Create new vector.
|
-- Create new vector.
|
||||||
-- TODO: Copy argument
|
if Copy then
|
||||||
local vector=VECTOR:New(x, self.y, z)
|
local vector=VECTOR:New(x, self.y, z)
|
||||||
|
return vector
|
||||||
return vector
|
else
|
||||||
|
self:SetX(x)
|
||||||
|
self:SetZ(z)
|
||||||
|
return self
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -857,7 +871,7 @@ end
|
|||||||
-- * RUNWAY = 5
|
-- * RUNWAY = 5
|
||||||
--
|
--
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @return #number Surface Type
|
-- @return #number Surface type
|
||||||
function VECTOR:GetSurfaceType()
|
function VECTOR:GetSurfaceType()
|
||||||
|
|
||||||
local vec2=self:GetVec2()
|
local vec2=self:GetVec2()
|
||||||
@@ -867,6 +881,32 @@ function VECTOR:GetSurfaceType()
|
|||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get the name of surface type at the vector.
|
||||||
|
--
|
||||||
|
-- * LAND = 1
|
||||||
|
-- * SHALLOW_WATER = 2
|
||||||
|
-- * WATER = 3
|
||||||
|
-- * ROAD = 4
|
||||||
|
-- * RUNWAY = 5
|
||||||
|
--
|
||||||
|
-- @param #VECTOR self
|
||||||
|
-- @return #string Surface type name
|
||||||
|
function VECTOR:GetSurfaceTypeName()
|
||||||
|
|
||||||
|
local vec2=self:GetVec2()
|
||||||
|
|
||||||
|
local s=land.getSurfaceType(vec2)
|
||||||
|
|
||||||
|
for name,id in land.SurfaceType() do
|
||||||
|
if id==s then
|
||||||
|
return name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
end
|
||||||
|
|
||||||
--- Check if a given vector has line of sight with this vector.
|
--- Check if a given vector has line of sight with this vector.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #VECTOR Vec The other vector.
|
-- @param #VECTOR Vec The other vector.
|
||||||
@@ -1022,36 +1062,104 @@ function VECTOR:GetTemperaturAndPressure()
|
|||||||
return t,p
|
return t,p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Creates a smoke at this vector.
|
||||||
|
-- @param #VECTOR self
|
||||||
|
-- @param #number Color Color of the smoke: 0=Green, 1=Red, 2=White, 3=Orange, 4=Blue. Default 0.
|
||||||
|
-- @param #number Duration (Optional) Duration of the smoke in seconds. Default nil.
|
||||||
|
-- @return #string Name of the smoke object. Can be used to stop it.
|
||||||
|
function VECTOR:Smoke(Color, Duration)
|
||||||
|
|
||||||
|
local vec3=self:GetVec3()
|
||||||
|
|
||||||
|
Color=Color or 0
|
||||||
|
|
||||||
|
-- Create a name for the smoke object
|
||||||
|
local name=string.format("Vector-Smoke-%d", self.uid)
|
||||||
|
|
||||||
|
-- Create smoke at this position
|
||||||
|
trigger.action.smoke(vec3, Color, name)
|
||||||
|
|
||||||
|
if Duration and Duration>0 then
|
||||||
|
self:StopSmoke(name, Duration)
|
||||||
|
end
|
||||||
|
|
||||||
|
return name
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Creates a large smoke and fire effect of a specified type and density at this vector.
|
--- Creates a large smoke and fire effect of a specified type and density at this vector.
|
||||||
|
--
|
||||||
|
-- * 1 = small smoke and fire
|
||||||
|
-- * 2 = medium smoke and fire
|
||||||
|
-- * 3 = large smoke and fire
|
||||||
|
-- * 4 = huge smoke and fire
|
||||||
|
-- * 5 = small smoke
|
||||||
|
-- * 6 = medium smoke
|
||||||
|
-- * 7 = large smoke
|
||||||
|
-- * 8 = huge smoke
|
||||||
|
--
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #number Preset Preset of smoke. Default `BIGSMOKEPRESET.LargeSmokeAndFire`.
|
-- @param #number Preset Preset of smoke. Default `BIGSMOKEPRESET.LargeSmokeAndFire`.
|
||||||
-- @param #number Density Density between [0,1]. Default 0.5.
|
-- @param #number Density Density between [0,1]. Default 0.5.
|
||||||
|
-- @param #number Duration (Optional) Duration of the smoke and fire in seconds.
|
||||||
-- @return #string Name of the smoke. Can be used to stop it.
|
-- @return #string Name of the smoke. Can be used to stop it.
|
||||||
function VECTOR:SmokeAndFire(Preset, Density)
|
function VECTOR:SmokeAndFire(Preset, Density, Duration)
|
||||||
|
|
||||||
Preset=Preset or BIGSMOKEPRESET.LargeSmokeAndFire
|
Preset=Preset or BIGSMOKEPRESET.LargeSmokeAndFire
|
||||||
Density=Density or 0.5
|
Density=Density or 0.5
|
||||||
|
|
||||||
local vec3=self:GetVec3()
|
local vec3=self:GetVec3()
|
||||||
|
|
||||||
--TODO: Get a unique name or pass name as parameter?
|
-- Get a name of this smoke & fire object
|
||||||
|
local name=string.format("Vector-Fire-%d", self.uid)
|
||||||
|
|
||||||
trigger.action.effectSmokeBig(vec3, Preset, Density, Name)
|
trigger.action.effectSmokeBig(vec3, Preset, Density, name)
|
||||||
|
|
||||||
return Name
|
if Duration and Duration>0 then
|
||||||
|
self:StopSmoke(name, Duration)
|
||||||
|
end
|
||||||
|
|
||||||
|
return name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Stop smoke or fire effect.
|
||||||
|
-- @param #VECTOR self
|
||||||
|
-- @param #string Name Name of the smoke object.
|
||||||
|
-- @param #number Delay Delay in seconds before the smoke is stopped.
|
||||||
|
-- @return #VECTOR self
|
||||||
|
function VECTOR:StopSmoke(Name, Delay)
|
||||||
|
|
||||||
|
if Delay and Delay>0 then
|
||||||
|
TIMER:New(VECTOR.StopSmoke, self, Name):Start(Delay)
|
||||||
|
else
|
||||||
|
if Name then
|
||||||
|
trigger.action.effectSmokeStop(Name)
|
||||||
|
else
|
||||||
|
env.error(string.format("No name provided in VECTOR.StopSmoke function!"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Creates an illumination bomb at the specified point.
|
--- Creates an illumination bomb at the specified point.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #number Power The power in Candela (cd). Should be between 1 and 1000000. Default 1000 cd.
|
-- @param #number Power The power in Candela (cd). Should be between 1 and 1000000. Default 1000 cd.
|
||||||
|
-- @param #number Altitude (Optional) Altitude [m] at which the illumination bomb is created.
|
||||||
-- @return #VECTOR self
|
-- @return #VECTOR self
|
||||||
function VECTOR:IlluminationBomb(Power)
|
function VECTOR:IlluminationBomb(Power, Altitude)
|
||||||
|
|
||||||
local vec3=self:GetVec3()
|
local vec3=self:GetVec3()
|
||||||
|
|
||||||
|
if Altitude then
|
||||||
|
vec3.y=Altitude
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create an illumination bomb.
|
||||||
trigger.action.illuminationBomb(vec3, Power or 1000)
|
trigger.action.illuminationBomb(vec3, Power or 1000)
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Creates an explosion at a given point at the specified power.
|
--- Creates an explosion at a given point at the specified power.
|
||||||
@@ -1085,16 +1193,73 @@ end
|
|||||||
--- Creates a arrow from this VECTOR to another vector on the F10 map.
|
--- Creates a arrow from this VECTOR to another vector on the F10 map.
|
||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @param #VECTOR Vector The vector defining the endpoint.
|
-- @param #VECTOR Vector The vector defining the endpoint.
|
||||||
-- @return #VECTOR self
|
-- @param #number Coalition Coalition Id: -1=All, 0=Neutral, 1=Red, 2=Blue. Default -1.
|
||||||
function VECTOR:ArrowToAll(Vector)
|
-- @param #table Color RGB color with alpha {r, g, b, alpha}. Default {1, 0, 0, 0.7}.
|
||||||
|
-- @param #table FillColor RGB color with alpha {r, g, b, alpha}. Default {1, 0, 0, 0.5}.
|
||||||
|
-- @param #number LineType Line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot Dash, 5=Long Dash, 6=Two Dash. Default 1.
|
||||||
|
-- @return #number Marker ID. Can be used to remove the drawing.
|
||||||
|
function VECTOR:ArrowTo(Vector, Coalition, Color, FillColor, LineType)
|
||||||
|
|
||||||
local vec3Start=self:GetVec3()
|
local vec3End=self:GetVec3()
|
||||||
|
local vec3Start=Vector:GetVec3()
|
||||||
|
|
||||||
trigger.action.arrowToAll(coalition , id, vec3Start, vec3End, color, fillColor , lineType, readOnly, "")
|
local id=UTILS.GetMarkID()
|
||||||
|
|
||||||
return self
|
Coalition=Coalition or -1
|
||||||
|
Color=Color or {1,0,0,0.7}
|
||||||
|
FillColor=FillColor or {1,0,0,0.5}
|
||||||
|
LineType=LineType or 1
|
||||||
|
|
||||||
|
local readOnly=false
|
||||||
|
|
||||||
|
trigger.action.arrowToAll(Coalition , id, vec3Start, vec3End, Color, FillColor , LineType, readOnly, "")
|
||||||
|
|
||||||
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create mark on F10 map.
|
||||||
|
-- @param #VECTOR self
|
||||||
|
-- @param #string MarkText Free format text that shows the marking clarification.
|
||||||
|
-- @param #number Recipient Recipient of the mark: -1=All (default), 0=Neutral, 1=Red, 2=Blue. Can also be a `GROUP` object.
|
||||||
|
-- @param #boolean ReadOnly (Optional) Mark is readonly and cannot be removed by users. Default false.
|
||||||
|
-- @return #number Mark ID.
|
||||||
|
function VECTOR:Mark(MarkText, Recipient, ReadOnly)
|
||||||
|
|
||||||
|
Recipient=Recipient or -1
|
||||||
|
|
||||||
|
if type(Recipient)=="number" then
|
||||||
|
|
||||||
|
local MarkID = UTILS.GetMarkID()
|
||||||
|
|
||||||
|
if Recipient==-1 then
|
||||||
|
trigger.action.markToAll(MarkID, MarkText, self:GetVec3(), ReadOnly, "")
|
||||||
|
elseif Recipient==0 then
|
||||||
|
trigger.action.markToCoalition(MarkID, MarkText, self:GetVec3(), coalition.side.NEUTRAL, ReadOnly, "")
|
||||||
|
elseif Recipient==1 then
|
||||||
|
trigger.action.markToCoalition(MarkID, MarkText, self:GetVec3(), coalition.side.RED, ReadOnly, "")
|
||||||
|
elseif Recipient==2 then
|
||||||
|
trigger.action.markToCoalition(MarkID, MarkText, self:GetVec3(), coalition.side.BLUE, ReadOnly, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
return MarkID
|
||||||
|
|
||||||
|
elseif type(Recipient)=="table" then
|
||||||
|
|
||||||
|
local MarkID = UTILS.GetMarkID()
|
||||||
|
|
||||||
|
local group=Recipient --Wrapper.Group#GROUP
|
||||||
|
|
||||||
|
trigger.action.markToGroup( MarkID, MarkText, self:GetVec3(), group:GetID(), ReadOnly, "")
|
||||||
|
|
||||||
|
return MarkID
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- Private Functions
|
-- Private Functions
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -1119,7 +1284,7 @@ function VECTOR.__add(a,b)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Meta function to substract vectors.
|
--- Meta function to subtract vectors.
|
||||||
-- @param #VECTOR a Vector a.
|
-- @param #VECTOR a Vector a.
|
||||||
-- @param #VECTOR b Vector b.
|
-- @param #VECTOR b Vector b.
|
||||||
-- @return #VECTOR Returns a new VECTOR c with c[i]=a[i]-b[i] for i=x,y,z.
|
-- @return #VECTOR Returns a new VECTOR c with c[i]=a[i]-b[i] for i=x,y,z.
|
||||||
@@ -1152,17 +1317,21 @@ function VECTOR.__mul(a, b)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Meta function for dividing vectors by scalars.
|
--- Meta function for dividing a vector by a scalar or by another vector.
|
||||||
-- @param #VECTOR a Vector a.
|
-- @param #VECTOR a Vector a.
|
||||||
-- @param #number b Number by which the components of the vector are divided.
|
-- @param #VECTOR b Vector b. Can also be a #number.
|
||||||
-- @return #VECTOR Returns a new VECTOR c with c[i]=a[i]/b for i=x,y,z.
|
-- @return #VECTOR Returns a new VECTOR c with c[i]=a[i]/b or c[i]=a[i]/b[i] for i=x,y,z.
|
||||||
function VECTOR.__div(a, b)
|
function VECTOR.__div(a, b)
|
||||||
|
|
||||||
assert(VECTOR._IsVector(a) and type(b) == "number", "div: wrong argument types (expected <vector> and <number>)")
|
assert(VECTOR._IsVector(a) and (type(b) == "number" or VECTOR._IsVector(b)), "div: wrong argument types (expected <vector> and (<number> or <vector>))")
|
||||||
|
|
||||||
env.info("FF __div")
|
local c=nil --#VECTOR
|
||||||
|
|
||||||
local c=VECTOR:New(a.x/b, a.y/b, a.z/b)
|
if type(b) == "number" then
|
||||||
|
c=VECTOR:New(a.x/b, a.y/b, a.z/b)
|
||||||
|
else
|
||||||
|
c=VECTOR:New(a.x/b.x, a.y/b.y, a.z/b.z)
|
||||||
|
end
|
||||||
|
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
@@ -1191,7 +1360,7 @@ end
|
|||||||
-- @param #VECTOR self
|
-- @param #VECTOR self
|
||||||
-- @return #string String representation of vector.
|
-- @return #string String representation of vector.
|
||||||
function VECTOR:__tostring()
|
function VECTOR:__tostring()
|
||||||
local text=string.format("(x=%.1f, y=%.1f, z=%.1f) |v|=%.1f Phi=%4.1f°", self.x, self.y, self.z, self:GetLength(), self:GetHeading(false))
|
local text=string.format("VECTOR: x=%.1f, y=%.1f, z=%.1f |v|=%.1f Phi=%4.1f°", self.x, self.y, self.z, self:GetLength(), self:GetHeading(false))
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ _DATABASE:_RegisterCargos()
|
|||||||
_DATABASE:_RegisterZones()
|
_DATABASE:_RegisterZones()
|
||||||
_DATABASE:_RegisterAirbases()
|
_DATABASE:_RegisterAirbases()
|
||||||
|
|
||||||
|
--- Function that writes to DCS log file
|
||||||
|
-- @param #string text Formatted text.
|
||||||
|
-- @param ... Format passed to string.format().
|
||||||
|
function printf(text, ...)
|
||||||
|
env.info(string.format(text, ...))
|
||||||
|
end
|
||||||
|
|
||||||
--- Check if os etc is available.
|
--- Check if os etc is available.
|
||||||
BASE:I("Checking de-sanitization of os, io and lfs:")
|
BASE:I("Checking de-sanitization of os, io and lfs:")
|
||||||
local __na = false
|
local __na = false
|
||||||
|
|||||||
@@ -3227,6 +3227,22 @@ function UTILS.BearingToCardinal(Heading)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Adjust given heading so that is is in [0, 360).
|
||||||
|
-- @param #number Heading The heading in degrees.
|
||||||
|
-- @return #number Adjust heading in [0,360).
|
||||||
|
function UTILS.AdjustHeading360(Heading)
|
||||||
|
|
||||||
|
while Heading>=360 or Heading<0 do
|
||||||
|
if Heading>=360 then
|
||||||
|
Heading=Heading-360
|
||||||
|
elseif Heading<0 then
|
||||||
|
Heading=Heading+360
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Heading
|
||||||
|
end
|
||||||
|
|
||||||
--- Create a BRAA NATO call string BRAA between two GROUP objects
|
--- Create a BRAA NATO call string BRAA between two GROUP objects
|
||||||
-- @param Wrapper.Group#GROUP FromGrp GROUP object
|
-- @param Wrapper.Group#GROUP FromGrp GROUP object
|
||||||
-- @param Wrapper.Group#GROUP ToGrp GROUP object
|
-- @param Wrapper.Group#GROUP ToGrp GROUP object
|
||||||
|
|||||||
@@ -1152,6 +1152,23 @@ function GROUP:GetVec3()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the current {@Core.Vector#VECTOR} of the first Unit in the GROUP.
|
||||||
|
-- @param #GROUP self
|
||||||
|
-- @return Core.Vector#VECTOR Vector of the first Unit of the GROUP or nil if cannot be found.
|
||||||
|
function GROUP:GetVector()
|
||||||
|
|
||||||
|
-- Get first unit.
|
||||||
|
local unit=self:GetUnit(1)
|
||||||
|
|
||||||
|
if unit then
|
||||||
|
local vector=unit:GetVector()
|
||||||
|
return vector
|
||||||
|
end
|
||||||
|
|
||||||
|
self:E("ERROR: Cannot get Vector of group "..tostring(self.GroupName))
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Returns the average Vec3 vector of the Units in the GROUP.
|
--- Returns the average Vec3 vector of the Units in the GROUP.
|
||||||
-- @param #GROUP self
|
-- @param #GROUP self
|
||||||
-- @return DCS#Vec3 Current Vec3 of the GROUP or nil if cannot be found.
|
-- @return DCS#Vec3 Current Vec3 of the GROUP or nil if cannot be found.
|
||||||
|
|||||||
@@ -219,6 +219,25 @@ function POSITIONABLE:GetOrientationZ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the vectors of the orientation of the object:
|
||||||
|
-- X is the orientation parallel to the movement of the object, Z perpendicular and Y vertical orientation.
|
||||||
|
-- @param #POSITIONABLE self
|
||||||
|
-- @return Core.Vector#VECTOR X orientation, i.e. parallel to the direction of movement.
|
||||||
|
-- @return Core.Vector#VECTOR Y orientation, i.e. vertical.
|
||||||
|
-- @return Core.Vector#VECTOR Z orientation, i.e. perpendicular to the direction of movement.
|
||||||
|
function POSITIONABLE:GetOrientationVectors()
|
||||||
|
local position = self:GetPosition()
|
||||||
|
if position then
|
||||||
|
local vecx=VECTOR:NewFromVec(position.x)
|
||||||
|
local vecy=VECTOR:NewFromVec(position.y)
|
||||||
|
local vecz=VECTOR:NewFromVec(position.z)
|
||||||
|
return vecx, vecy, vecz
|
||||||
|
else
|
||||||
|
BASE:E( { "Cannot GetOrientation", Positionable = self, Alive = self:IsAlive() } )
|
||||||
|
return nil, nil, nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Returns the @{DCS#Position3} position vectors indicating the point and direction vectors in 3D of the POSITIONABLE within the mission.
|
--- Returns the @{DCS#Position3} position vectors indicating the point and direction vectors in 3D of the POSITIONABLE within the mission.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @return DCS#Position The 3D position vectors of the POSITIONABLE.
|
-- @return DCS#Position The 3D position vectors of the POSITIONABLE.
|
||||||
@@ -286,6 +305,27 @@ function POSITIONABLE:GetVec2()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the @{Core.Vector#VECTOR} indicating the 3D position of the object on the map.
|
||||||
|
-- @param #POSITIONABLE self
|
||||||
|
-- @return Core.Vector#VECTOR The 3D vector.
|
||||||
|
function POSITIONABLE:GetVector()
|
||||||
|
|
||||||
|
local DCSPositionable = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSPositionable then
|
||||||
|
|
||||||
|
local Vec3 = DCSPositionable:getPoint() -- DCS#Vec3
|
||||||
|
|
||||||
|
local vector=VECTOR:NewFromVec(Vec3)
|
||||||
|
|
||||||
|
return vector
|
||||||
|
end
|
||||||
|
|
||||||
|
self:E( { "Cannot GetVec2", Positionable = self, Alive = self:IsAlive() } )
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Returns a COORDINATE object indicating the point in 2D of the POSITIONABLE within the mission.
|
--- Returns a COORDINATE object indicating the point in 2D of the POSITIONABLE within the mission.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @return Core.Point#COORDINATE The 3D point vector of the POSITIONABLE.
|
-- @return Core.Point#COORDINATE The 3D point vector of the POSITIONABLE.
|
||||||
@@ -914,6 +954,24 @@ function POSITIONABLE:GetVelocityVec3()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the velocity vector.
|
||||||
|
-- @param #POSITIONABLE self
|
||||||
|
-- @return Core.Vector#VECTOR The velocity vector or `nil` if the object does not exist.
|
||||||
|
function POSITIONABLE:GetVelocityVector()
|
||||||
|
|
||||||
|
local DCSPositionable = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSPositionable and DCSPositionable:isExist() then
|
||||||
|
local vec3 = DCSPositionable:getVelocity()
|
||||||
|
local vector=VECTOR:NewFromVec(vec3)
|
||||||
|
return vector
|
||||||
|
end
|
||||||
|
|
||||||
|
BASE:E( { "Cannot GetVelocityVector", Positionable = self, Alive = self:IsAlive() } )
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Get relative velocity with respect to another POSITIONABLE.
|
--- Get relative velocity with respect to another POSITIONABLE.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @param #POSITIONABLE Positionable Other POSITIONABLE.
|
-- @param #POSITIONABLE Positionable Other POSITIONABLE.
|
||||||
|
|||||||
Reference in New Issue
Block a user