Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPOverlay: fix loiter circle rendering #3232

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions ExtLibs/Maps/WPOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void CreateOverlay(PointLatLngAlt home, List<Locationwp> missionitems, do
}
else if (command == (ushort) MAVLink.MAV_CMD.LOITER_TIME ||
command == (ushort) MAVLink.MAV_CMD.LOITER_TURNS ||
command == (ushort) MAVLink.MAV_CMD.LOITER_TO_ALT ||
command == (ushort) MAVLink.MAV_CMD.LOITER_UNLIM)
{
if (item.lat == 0 && item.lng == 0)
Expand All @@ -160,6 +161,20 @@ public void CreateOverlay(PointLatLngAlt home, List<Locationwp> missionitems, do
color = Color.LightBlue
});

// Calculate the loiter radius and direction for this command, if one is specified
var this_loiterradius = loiterradius;
if (command == (ushort)MAVLink.MAV_CMD.LOITER_TURNS ||
command == (ushort)MAVLink.MAV_CMD.LOITER_UNLIM)
{
this_loiterradius = item.p3 != 0 ? item.p3 : this_loiterradius;
}
else if (command == (ushort)MAVLink.MAV_CMD.LOITER_TO_ALT)
{
this_loiterradius = item.p2 != 0 ? item.p2 : this_loiterradius;
}
int loiterdirection = Math.Sign(this_loiterradius);
this_loiterradius = Math.Abs(this_loiterradius);

// exit at tangent
if (item.p4 == 1)
{
Expand All @@ -175,10 +190,11 @@ public void CreateOverlay(PointLatLngAlt home, List<Locationwp> missionitems, do
var bearing = from.GetBearing(to);
var dist = from.GetDistance(to);

if (dist > loiterradius)
if (dist > this_loiterradius)
{
route.Add(pointlist[pointlist.Count - 1]);
var offset = from.newpos(bearing + 90, loiterradius);
var theta = Math.Acos(this_loiterradius / dist) * MathHelper.rad2deg;
var offset = from.newpos(bearing - loiterdirection*theta, this_loiterradius);
route.Add(offset);
}
else
Expand All @@ -190,7 +206,7 @@ public void CreateOverlay(PointLatLngAlt home, List<Locationwp> missionitems, do
route.Add(pointlist[pointlist.Count - 1]);

addpolygonmarker((a + 1).ToString(), item.lng, item.lat,
item.alt * altunitmultiplier, Color.LightBlue, loiterradius);
item.alt * altunitmultiplier, Color.LightBlue, this_loiterradius);
}
}
else if (command == (ushort) MAVLink.MAV_CMD.SPLINE_WAYPOINT)
Expand Down
Loading