1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01: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>
namespace osgQtQuick {
enum DirtyFlag { Scene = 1 << 0 };
struct OSGCameraManipulator::Hidden : public QObject, public DirtySupport {
Q_OBJECT
@ -91,7 +93,7 @@ public:
qWarning() << "OSGCameraManipulator::updateSceneNode - no scene node";
return;
}
qDebug() << "OSGCameraManipulator::updateSceneNode" << sceneNode->node();
qDebug() << "OSGCameraManipulator::updateSceneNode" << sceneNode;
manipulator->setNode(sceneNode->node());
}
@ -99,7 +101,7 @@ private slots:
void onSceneNodeChanged(osg::Node *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)
{
if (h->acceptSceneNode(node)) {
setDirty(Scene);
emit sceneNodeChanged(node);
}
}
@ -169,7 +172,9 @@ osgGA::CameraManipulator *OSGCameraManipulator::asCameraManipulator() const
void OSGCameraManipulator::update()
{
h->updateSceneNode();
if (isDirty(Scene)) {
h->updateSceneNode();
}
}
} // namespace osgQtQuick

View File

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

View File

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