mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Merged in filnet/librepilot/LP-566_osgearth29_upgrade (pull request #498)
LP-566 upgrade to osgEarth 2.9 Approved-by: Philippe Renon <philippe_renon@yahoo.fr> Approved-by: Lalanne Laurent <f5soh@free.fr>
This commit is contained in:
commit
ed36165706
@ -117,32 +117,30 @@ public:
|
||||
} else {
|
||||
qWarning() << "OSGGeoTransformNode::updatePosition - scene node is not valid";
|
||||
}
|
||||
|
||||
// TODO factorize this logic to utility (same logic is found elsewhere)
|
||||
osgEarth::GeoPoint geoPoint;
|
||||
if (mapNode) {
|
||||
geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position);
|
||||
} else {
|
||||
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - no map node";
|
||||
geoPoint = osgQtQuick::toGeoPoint(position);
|
||||
osgEarth::GeoPoint geoPoint = createGeoPoint(position, mapNode);
|
||||
if (clampToTerrain) {
|
||||
// get "size" of model
|
||||
// TODO this should be done once only...
|
||||
#if 0
|
||||
osg::ComputeBoundsVisitor cbv;
|
||||
transform->accept(cbv);
|
||||
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
||||
offset = bbox.radius();
|
||||
#else
|
||||
const osg::BoundingSphere & boundingSphere = transform->getBound();
|
||||
offset = boundingSphere.radius();
|
||||
#endif
|
||||
// clamp model to terrain if needed
|
||||
intoTerrain = clampGeoPoint(geoPoint, offset, mapNode);
|
||||
if (intoTerrain) {
|
||||
qDebug() << "OSGGeoTransformNode::updateNode - into terrain" << offset;
|
||||
}
|
||||
} else if (clampToTerrain) {
|
||||
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node";
|
||||
}
|
||||
transform->setPosition(geoPoint);
|
||||
}
|
||||
if (clampToTerrain && mapNode) {
|
||||
// get "size" of model
|
||||
// TODO this should be done once only...
|
||||
osg::ComputeBoundsVisitor cbv;
|
||||
transform->accept(cbv);
|
||||
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
||||
offset = bbox.radius();
|
||||
|
||||
// qDebug() << "OSGGeoTransformNode::updateNode - offset" << offset;
|
||||
|
||||
// clamp model to terrain if needed
|
||||
intoTerrain = clampGeoPoint(geoPoint, offset, mapNode);
|
||||
} else if (clampToTerrain) {
|
||||
qWarning() << "OSGGeoTransformNode::onChildNodeChanged - cannot clamp without map node";
|
||||
}
|
||||
|
||||
transform->setPosition(geoPoint);
|
||||
}
|
||||
|
||||
private slots:
|
||||
|
@ -155,27 +155,21 @@ public:
|
||||
|
||||
if (sceneNode && sceneNode->node()) {
|
||||
mapNode = osgEarth::MapNode::findMapNode(sceneNode->node());
|
||||
if (!mapNode) {
|
||||
qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node does not contain a map node";
|
||||
}
|
||||
} else {
|
||||
qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node is null";
|
||||
}
|
||||
|
||||
osgEarth::GeoPoint geoPoint;
|
||||
if (mapNode) {
|
||||
geoPoint = osgQtQuick::toGeoPoint(mapNode->getTerrain()->getSRS(), position);
|
||||
osgEarth::GeoPoint geoPoint = osgQtQuick::createGeoPoint(position, mapNode);
|
||||
if (clampToTerrain) {
|
||||
// clamp model to terrain if needed
|
||||
intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode);
|
||||
} else if (clampToTerrain) {
|
||||
qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node";
|
||||
}
|
||||
geoPoint.createLocalToWorld(cameraPosition);
|
||||
} else {
|
||||
geoPoint = osgQtQuick::toGeoPoint(position);
|
||||
qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node does not contain a map node";
|
||||
}
|
||||
if (clampToTerrain && mapNode) {
|
||||
// clamp model to terrain if needed
|
||||
intoTerrain = osgQtQuick::clampGeoPoint(geoPoint, 0, mapNode);
|
||||
} else if (clampToTerrain) {
|
||||
qWarning() << "OSGGeoTransformManipulator::updatePosition - cannot clamp without map node";
|
||||
}
|
||||
|
||||
geoPoint.createLocalToWorld(cameraPosition);
|
||||
}
|
||||
|
||||
void updateAttitude()
|
||||
|
@ -69,9 +69,11 @@
|
||||
#include "osgQtQuick/ga/OSGEarthManipulator.hpp"
|
||||
#include "osgQtQuick/ga/OSGGeoTransformManipulator.hpp"
|
||||
|
||||
#include <osgEarth/Version>
|
||||
#include <osgEarth/Capabilities>
|
||||
#include <osgEarth/MapNode>
|
||||
#include <osgEarth/SpatialReference>
|
||||
#include <osgEarth/Terrain>
|
||||
#include <osgEarth/ElevationQuery>
|
||||
#endif // USE_OSGEARTH
|
||||
|
||||
@ -454,18 +456,20 @@ QString getUsageString(osgViewer::CompositeViewer *viewer)
|
||||
}
|
||||
|
||||
#ifdef USE_OSGEARTH
|
||||
osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position)
|
||||
osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode)
|
||||
{
|
||||
const osgEarth::SpatialReference *srs = NULL;
|
||||
|
||||
if (mapNode) {
|
||||
srs = mapNode->getTerrain()->getSRS();
|
||||
} else {
|
||||
qWarning() << "Utility::createGeoPoint - null map node";
|
||||
srs = osgEarth::SpatialReference::get("wgs84");
|
||||
}
|
||||
osgEarth::GeoPoint geoPoint(srs, position.x(), position.y(), position.z(), osgEarth::ALTMODE_ABSOLUTE);
|
||||
|
||||
return geoPoint;
|
||||
}
|
||||
|
||||
osgEarth::GeoPoint toGeoPoint(const QVector3D &position)
|
||||
{
|
||||
return toGeoPoint(osgEarth::SpatialReference::get("wgs84"), position);
|
||||
}
|
||||
|
||||
bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode)
|
||||
{
|
||||
if (!mapNode) {
|
||||
@ -477,9 +481,18 @@ bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode
|
||||
osgEarth::ElevationQuery eq(mapNode->getMap());
|
||||
// qDebug() << "Utility::clampGeoPoint - SRS :" << QString::fromStdString(mapNode->getMap()->getSRS()->getName());
|
||||
|
||||
bool clamped = false;
|
||||
double elevation;
|
||||
if (eq.getElevation(geoPoint, elevation, 0.0)) {
|
||||
bool gotElevation;
|
||||
#if OSGEARTH_VERSION_LESS_THAN(2, 9, 0)
|
||||
gotElevation = eq.getElevation(geoPoint, elevation, 0.0);
|
||||
#else
|
||||
const double resolution = 0.0;
|
||||
double actualResolution;
|
||||
elevation = eq.getElevation(geoPoint, resolution, &actualResolution);
|
||||
gotElevation = (elevation != NO_DATA_VALUE);
|
||||
#endif
|
||||
bool clamped = false;
|
||||
if (gotElevation) {
|
||||
clamped = ((geoPoint.z() - offset) < elevation);
|
||||
if (clamped) {
|
||||
// qDebug() << "Utility::clampGeoPoint - clamping" << geoPoint.z() - offset << "/" << elevation;
|
||||
|
@ -145,8 +145,7 @@ QString getUsageString(osgViewer::Viewer *viewer);
|
||||
QString getUsageString(osgViewer::CompositeViewer *viewer);
|
||||
|
||||
#ifdef USE_OSGEARTH
|
||||
osgEarth::GeoPoint toGeoPoint(const QVector3D &position);
|
||||
osgEarth::GeoPoint toGeoPoint(const osgEarth::SpatialReference *srs, const QVector3D &position);
|
||||
osgEarth::GeoPoint createGeoPoint(const QVector3D &position, osgEarth::MapNode *mapNode);
|
||||
bool clampGeoPoint(osgEarth::GeoPoint &geoPoint, float offset, osgEarth::MapNode *mapNode);
|
||||
void capabilitiesInfo(const osgEarth::Capabilities & caps);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user