mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
CT v0.0.3
This commit is contained in:
@@ -696,6 +696,105 @@ function POSITIONABLE:GetAoA()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns the unit's climb or descent angle.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Climb or descent angle in degrees.
|
||||
function POSITIONABLE:GetAoA()
|
||||
|
||||
-- Get position of the unit.
|
||||
local unitpos = self:GetPosition()
|
||||
|
||||
if unitpos then
|
||||
|
||||
-- Get velocity vector of the unit.
|
||||
local unitvel = self:GetVelocityVec3()
|
||||
|
||||
if unitvel and UTILS.VecNorm(unitvel)~=0 then
|
||||
|
||||
return math.asin(unitvel.y/UTILS.VecNorm(unitvel))
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the pitch angle of a unit.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Pitch ange in degrees.
|
||||
function POSITIONABLE:GetPitch()
|
||||
|
||||
-- Get position of the unit.
|
||||
local unitpos = self:GetPosition()
|
||||
|
||||
if unitpos then
|
||||
return math.deg(math.asin(unitpos.x.y))
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns the roll angle of a unit.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Pitch ange in degrees.
|
||||
function POSITIONABLE:GetRoll()
|
||||
|
||||
-- Get position of the unit.
|
||||
local unitpos = self:GetPosition()
|
||||
|
||||
if unitpos then
|
||||
|
||||
--first, make a vector that is perpendicular to y and unitpos.x with cross product
|
||||
local cp = UTILS.VecCross(unitpos.x, {x = 0, y = 1, z = 0})
|
||||
|
||||
--now, get dot product of of this cross product with unitpos.z
|
||||
local dp = UTILS.VecDot(cp, unitpos.z)
|
||||
|
||||
--now get the magnitude of the roll (magnitude of the angle between two vectors is acos(vec1.vec2/|vec1||vec2|)
|
||||
local Roll = math.acos(dp/(UTILS.VecNorm(cp)*UTILS.VecNorm(unitpos.z)))
|
||||
|
||||
--now, have to get sign of roll.
|
||||
-- by convention, making right roll positive
|
||||
-- to get sign of roll, use the y component of unitpos.z. For right roll, y component is negative.
|
||||
|
||||
if unitpos.z.y > 0 then -- left roll, flip the sign of the roll
|
||||
Roll = -Roll
|
||||
end
|
||||
|
||||
return math.deg(Roll)
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the yaw angle of a unit.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return #number Yaw ange in degrees.
|
||||
function POSITIONABLE:GetYaw()
|
||||
|
||||
local unitpos = self:GetPosition()
|
||||
if unitpos then
|
||||
-- get unit velocity
|
||||
local unitvel = self:GetVelocityVec3()
|
||||
|
||||
if unitvel and UTILS.VecNorm(unitvel) ~= 0 then --must have non-zero velocity!
|
||||
local AxialVel = {} --unit velocity transformed into aircraft axes directions
|
||||
|
||||
--transform velocity components in direction of aircraft axes.
|
||||
AxialVel.x = UTILS.VecDot(unitpos.x, unitvel)
|
||||
AxialVel.y = UTILS.VecDot(unitpos.y, unitvel)
|
||||
AxialVel.z = UTILS.VecDot(unitpos.z, unitvel)
|
||||
|
||||
--Yaw is the angle between unitpos.x and the x and z velocities
|
||||
--define right yaw as positive
|
||||
local Yaw = math.acos(UTILS.VecDot({x = 1, y = 0, z = 0}, {x = AxialVel.x, y = 0, z = AxialVel.z})/UTILS.VecNorm({x = AxialVel.x, y = 0, z = AxialVel.z}))
|
||||
|
||||
--now set correct direction:
|
||||
if AxialVel.z > 0 then
|
||||
Yaw = -Yaw
|
||||
end
|
||||
return Yaw
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Returns the message text with the callsign embedded (if there is one).
|
||||
-- @param #POSITIONABLE self
|
||||
|
||||
Reference in New Issue
Block a user