Commit e96b743e authored by Lionel Heng's avatar Lionel Heng

Fixed coordinate system issue in waypoint management for 3D view.

parent 7d8ebfd3
...@@ -199,10 +199,9 @@ void WaypointList::add() ...@@ -199,10 +199,9 @@ void WaypointList::add()
} }
else else
{ {
//isLocalWP = true; //isLocalWP = true;
Waypoint *wp = new Waypoint(0, 1.1, 1.1, -0.8, 0.0, true, true, 0.15, 2000); Waypoint *wp = new Waypoint(0, uas->getLongitude(), uas->getLatitude(), uas->getAltitude(),
0.0, true, true, 0.15, 2000);
uas->getWaypointManager().addWaypoint(wp); uas->getWaypointManager().addWaypoint(wp);
......
...@@ -235,15 +235,23 @@ Pixhawk3DWidget::insertWaypoint(void) ...@@ -235,15 +235,23 @@ Pixhawk3DWidget::insertWaypoint(void)
{ {
if (uas) if (uas)
{ {
double latitude = uas->getLatitude();
double longitude = uas->getLongitude();
double altitude = uas->getAltitude(); double altitude = uas->getAltitude();
double x, y;
QString utmZone;
Imagery::LLtoUTM(uas->getLatitude(), uas->getLongitude(), x, y, utmZone);
std::pair<double,double> cursorWorldCoords = std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), altitude); getGlobalCursorPosition(getMouseX(), getMouseY(), altitude);
Imagery::UTMtoLL(cursorWorldCoords.first, cursorWorldCoords.second, utmZone,
latitude, longitude);
Waypoint* wp = new Waypoint(0, Waypoint* wp = new Waypoint(0,
cursorWorldCoords.first, longitude,
cursorWorldCoords.second, latitude,
-altitude); altitude);
uas->getWaypointManager().addWaypoint(wp); uas->getWaypointManager().addWaypoint(wp);
} }
} }
...@@ -259,17 +267,25 @@ Pixhawk3DWidget::setWaypoint(void) ...@@ -259,17 +267,25 @@ Pixhawk3DWidget::setWaypoint(void)
{ {
if (uas) if (uas)
{ {
double latitude = uas->getLatitude();
double longitude = uas->getLongitude();
double altitude = uas->getAltitude(); double altitude = uas->getAltitude();
double x, y;
QString utmZone;
Imagery::LLtoUTM(uas->getLatitude(), uas->getLongitude(), x, y, utmZone);
std::pair<double,double> cursorWorldCoords = std::pair<double,double> cursorWorldCoords =
getGlobalCursorPosition(getMouseX(), getMouseY(), altitude); getGlobalCursorPosition(getMouseX(), getMouseY(), altitude);
Imagery::UTMtoLL(cursorWorldCoords.first, cursorWorldCoords.second, utmZone,
latitude, longitude);
const QVector<Waypoint *> waypoints = const QVector<Waypoint *> waypoints =
uas->getWaypointManager().getWaypointList(); uas->getWaypointManager().getWaypointList();
Waypoint* waypoint = waypoints.at(selectedWpIndex); Waypoint* waypoint = waypoints.at(selectedWpIndex);
waypoint->setX(cursorWorldCoords.first); waypoint->setX(longitude);
waypoint->setY(cursorWorldCoords.second); waypoint->setY(latitude);
waypoint->setZ(-altitude); waypoint->setZ(altitude);
} }
} }
...@@ -294,10 +310,10 @@ Pixhawk3DWidget::setWaypointAltitude(void) ...@@ -294,10 +310,10 @@ Pixhawk3DWidget::setWaypointAltitude(void)
double newAltitude = double newAltitude =
QInputDialog::getDouble(this, tr("Set altitude of waypoint %1").arg(selectedWpIndex), QInputDialog::getDouble(this, tr("Set altitude of waypoint %1").arg(selectedWpIndex),
tr("Altitude (m):"), -waypoint->getZ(), -1000.0, 1000.0, 1, &ok); tr("Altitude (m):"), waypoint->getZ(), -1000.0, 1000.0, 1, &ok);
if (ok) if (ok)
{ {
waypoint->setZ(-newAltitude); waypoint->setZ(newAltitude);
} }
} }
} }
...@@ -1049,7 +1065,7 @@ Pixhawk3DWidget::updateWaypoints(void) ...@@ -1049,7 +1065,7 @@ Pixhawk3DWidget::updateWaypoints(void)
osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable; osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable;
osg::ref_ptr<osg::Cylinder> cylinder = osg::ref_ptr<osg::Cylinder> cylinder =
new osg::Cylinder(osg::Vec3d(0.0, 0.0, - wp->getZ() / 2.0), new osg::Cylinder(osg::Vec3d(0.0, 0.0, wp->getZ() / 2.0),
wp->getOrbit(), wp->getOrbit(),
fabs(wp->getZ())); fabs(wp->getZ()));
...@@ -1072,14 +1088,21 @@ Pixhawk3DWidget::updateWaypoints(void) ...@@ -1072,14 +1088,21 @@ Pixhawk3DWidget::updateWaypoints(void)
sprintf(wpLabel, "wp%d", i); sprintf(wpLabel, "wp%d", i);
geode->setName(wpLabel); geode->setName(wpLabel);
double wpX, wpY;
Imagery::LLtoUTM(wp->getY(), wp->getX(), wpX, wpY, utmZone);
if (i < list.size() - 1) if (i < list.size() - 1)
{ {
double nextWpX, nextWpY;
Imagery::LLtoUTM(list.at(i+1)->getY(), list.at(i+1)->getX(),
nextWpX, nextWpY, utmZone);
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3dArray> vertices = new osg::Vec3dArray; osg::ref_ptr<osg::Vec3dArray> vertices = new osg::Vec3dArray;
vertices->push_back(osg::Vec3d(0.0, 0.0, -wp->getZ())); vertices->push_back(osg::Vec3d(0.0, 0.0, wp->getZ()));
vertices->push_back(osg::Vec3d(list.at(i+1)->getY() - wp->getY(), vertices->push_back(osg::Vec3d(nextWpY - wpY,
list.at(i+1)->getX() - wp->getX(), nextWpX - wpX,
-list.at(i+1)->getZ())); list.at(i+1)->getZ()));
geometry->setVertexArray(vertices); geometry->setVertexArray(vertices);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
...@@ -1092,6 +1115,7 @@ Pixhawk3DWidget::updateWaypoints(void) ...@@ -1092,6 +1115,7 @@ Pixhawk3DWidget::updateWaypoints(void)
osg::ref_ptr<osg::LineWidth> linewidth(new osg::LineWidth()); osg::ref_ptr<osg::LineWidth> linewidth(new osg::LineWidth());
linewidth->setWidth(2.0f); linewidth->setWidth(2.0f);
geometry->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON); geometry->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON);
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->addDrawable(geometry); geode->addDrawable(geometry);
} }
...@@ -1099,8 +1123,8 @@ Pixhawk3DWidget::updateWaypoints(void) ...@@ -1099,8 +1123,8 @@ Pixhawk3DWidget::updateWaypoints(void)
osg::ref_ptr<osg::PositionAttitudeTransform> pat = osg::ref_ptr<osg::PositionAttitudeTransform> pat =
new osg::PositionAttitudeTransform; new osg::PositionAttitudeTransform;
pat->setPosition(osg::Vec3d(wp->getY() - robotY, pat->setPosition(osg::Vec3d(wpY - robotY,
wp->getX() - robotX, wpX - robotX,
robotZ)); robotZ));
waypointsNode->addChild(pat); waypointsNode->addChild(pat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment