1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-04-10 02:02:21 +02:00

LP-29 improve dirty handling of camera manipulators

This commit is contained in:
Philippe Renon 2016-04-14 21:49:16 +02:00
parent 2c75badb0b
commit dd52cc4344
3 changed files with 41 additions and 13 deletions

View File

@ -35,6 +35,8 @@
#include <QDebug> #include <QDebug>
namespace osgQtQuick { namespace osgQtQuick {
enum DirtyFlag { Scene = 1 << 0 };
struct OSGCameraManipulator::Hidden : public QObject, public DirtySupport { struct OSGCameraManipulator::Hidden : public QObject, public DirtySupport {
Q_OBJECT Q_OBJECT
@ -91,7 +93,7 @@ public:
qWarning() << "OSGCameraManipulator::updateSceneNode - no scene node"; qWarning() << "OSGCameraManipulator::updateSceneNode - no scene node";
return; return;
} }
qDebug() << "OSGCameraManipulator::updateSceneNode" << sceneNode->node(); qDebug() << "OSGCameraManipulator::updateSceneNode" << sceneNode;
manipulator->setNode(sceneNode->node()); manipulator->setNode(sceneNode->node());
} }
@ -99,7 +101,7 @@ private slots:
void onSceneNodeChanged(osg::Node *node) void onSceneNodeChanged(osg::Node *node)
{ {
qDebug() << "OSGCameraManipulator::onSceneNodeChanged" << node; qDebug() << "OSGCameraManipulator::onSceneNodeChanged" << node;
qWarning() << "OSGCameraManipulator::onSceneNodeChanged - needs to be implemented"; updateSceneNode();
} }
}; };
@ -121,6 +123,7 @@ OSGNode *OSGCameraManipulator::sceneNode() const
void OSGCameraManipulator::setSceneNode(OSGNode *node) void OSGCameraManipulator::setSceneNode(OSGNode *node)
{ {
if (h->acceptSceneNode(node)) { if (h->acceptSceneNode(node)) {
setDirty(Scene);
emit sceneNodeChanged(node); emit sceneNodeChanged(node);
} }
} }
@ -169,7 +172,9 @@ osgGA::CameraManipulator *OSGCameraManipulator::asCameraManipulator() const
void OSGCameraManipulator::update() void OSGCameraManipulator::update()
{ {
h->updateSceneNode(); if (isDirty(Scene)) {
h->updateSceneNode();
}
} }
} // namespace osgQtQuick } // namespace osgQtQuick

View File

@ -42,6 +42,8 @@
#include <QDebug> #include <QDebug>
namespace osgQtQuick { namespace osgQtQuick {
enum DirtyFlag { Position = 1 << 10, Attitude = 1 << 11, Clamp = 1 << 12 };
class MyManipulator : public osgGA::CameraManipulator { class MyManipulator : public osgGA::CameraManipulator {
public: public:
MyManipulator() MyManipulator()
@ -148,13 +150,15 @@ public:
osgEarth::MapNode *mapNode = NULL; osgEarth::MapNode *mapNode = NULL;
if (manipulator->getNode()) { OSGNode *sceneNode = self->sceneNode();
mapNode = osgEarth::MapNode::findMapNode(manipulator->getNode());
if (sceneNode && sceneNode->node()) {
mapNode = osgEarth::MapNode::findMapNode(sceneNode->node());
if (!mapNode) { if (!mapNode) {
qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node does not contain a map node"; qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node does not contain a map node";
} }
} else { } else {
qWarning() << "OSGGeoTransformManipulator::updatePosition - manipulator node is null"; qWarning() << "OSGGeoTransformManipulator::updatePosition - scene node is null";
} }
osgEarth::GeoPoint geoPoint; osgEarth::GeoPoint geoPoint;
@ -220,6 +224,7 @@ void OSGGeoTransformManipulator::setClampToTerrain(bool arg)
{ {
if (h->clampToTerrain != arg) { if (h->clampToTerrain != arg) {
h->clampToTerrain = arg; h->clampToTerrain = arg;
setDirty(Clamp);
emit clampToTerrainChanged(clampToTerrain()); emit clampToTerrainChanged(clampToTerrain());
} }
} }
@ -238,7 +243,7 @@ void OSGGeoTransformManipulator::setAttitude(QVector3D arg)
{ {
if (h->attitude != arg) { if (h->attitude != arg) {
h->attitude = arg; h->attitude = arg;
setDirty(); setDirty(Attitude);
emit attitudeChanged(attitude()); emit attitudeChanged(attitude());
} }
} }
@ -252,7 +257,7 @@ void OSGGeoTransformManipulator::setPosition(QVector3D arg)
{ {
if (h->position != arg) { if (h->position != arg) {
h->position = arg; h->position = arg;
setDirty(); setDirty(Position);
emit positionChanged(position()); emit positionChanged(position());
} }
} }
@ -261,9 +266,19 @@ void OSGGeoTransformManipulator::update()
{ {
Inherited::update(); Inherited::update();
h->updatePosition(); bool b = false;
h->updateAttitude();
h->updateManipulator(); if (isDirty(Clamp | Position)) {
h->updatePosition();
b = true;
}
if (isDirty(Attitude)) {
h->updateAttitude();
b = true;
}
if (b) {
h->updateManipulator();
}
} }
} // namespace osgQtQuick } // namespace osgQtQuick

View File

@ -34,6 +34,8 @@
#include <QDebug> #include <QDebug>
namespace osgQtQuick { namespace osgQtQuick {
enum DirtyFlag { TrackNode = 1 << 10, TrackerMode = 1 << 11 };
struct OSGNodeTrackerManipulator::Hidden : public QObject { struct OSGNodeTrackerManipulator::Hidden : public QObject {
Q_OBJECT Q_OBJECT
@ -138,6 +140,7 @@ OSGNode *OSGNodeTrackerManipulator::trackNode() const
void OSGNodeTrackerManipulator::setTrackNode(OSGNode *node) void OSGNodeTrackerManipulator::setTrackNode(OSGNode *node)
{ {
if (h->acceptTrackNode(node)) { if (h->acceptTrackNode(node)) {
setDirty(TrackNode);
emit trackNodeChanged(node); emit trackNodeChanged(node);
} }
} }
@ -151,6 +154,7 @@ void OSGNodeTrackerManipulator::setTrackerMode(TrackerMode::Enum mode)
{ {
if (h->trackerMode != mode) { if (h->trackerMode != mode) {
h->trackerMode = mode; h->trackerMode = mode;
setDirty(TrackerMode);
emit trackerModeChanged(trackerMode()); emit trackerModeChanged(trackerMode());
} }
} }
@ -159,8 +163,12 @@ void OSGNodeTrackerManipulator::update()
{ {
Inherited::update(); Inherited::update();
h->updateTrackerMode(); if (isDirty(TrackNode)) {
h->updateTrackNode(); h->updateTrackNode();
}
if (isDirty(TrackerMode)) {
h->updateTrackerMode();
}
} }
} // namespace osgQtQuick } // namespace osgQtQuick