1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-29 OSGTransformNode now derives from OSGGroup

This commit is contained in:
Philippe Renon 2016-03-26 21:18:23 +01:00
parent 5800f17d03
commit 444c126dab
7 changed files with 26 additions and 166 deletions

View File

@ -36,6 +36,8 @@
#include <QDebug>
namespace osgQtQuick {
// NOTE : these flags should not overlap with OSGGroup flags!!!
// TODO : find a better way...
enum DirtyFlag {};
struct OSGBillboardNode::Hidden : public QObject {

View File

@ -38,7 +38,9 @@
#include <QDebug>
namespace osgQtQuick {
enum DirtyFlag { Child = 1 << 0, Scene = 1 << 1, Position = 1 << 2, Clamp = 1 << 3 };
// NOTE : these flags should not overlap with OSGGroup flags!!!
// TODO : find a better way...
enum DirtyFlag { Scene = 1 << 10, Position = 1 << 11, Clamp = 1 << 12 };
struct OSGGeoTransformNode::Hidden : public QObject {
Q_OBJECT
@ -49,7 +51,6 @@ private:
osg::ref_ptr<osgEarth::GeoTransform> transform;
public:
OSGNode *childNode;
OSGNode *sceneNode;
float offset;
@ -59,7 +60,7 @@ public:
QVector3D position;
Hidden(OSGGeoTransformNode *self) : QObject(self), self(self), childNode(NULL), sceneNode(NULL), offset(-1.0), clampToTerrain(false), intoTerrain(false)
Hidden(OSGGeoTransformNode *self) : QObject(self), self(self), sceneNode(NULL), offset(-1.0), clampToTerrain(false), intoTerrain(false)
{}
osg::Node *createNode()
@ -69,26 +70,6 @@ public:
return transform;
}
bool acceptChildNode(OSGNode *node)
{
qDebug() << "OSGGeoTransformNode::acceptChildNode" << node;
if (childNode == node) {
return false;
}
if (childNode) {
disconnect(childNode);
}
childNode = node;
if (childNode) {
connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)));
}
return true;
}
bool acceptSceneNode(OSGNode *node)
{
qDebug() << "OSGGeoTransformNode::acceptSceneNode" << node;
@ -109,29 +90,6 @@ public:
return true;
}
void updateChildNode()
{
qDebug() << "OSGGeoTransformNode::updateChildNode" << childNode;
bool updated = false;
if (transform->getNumChildren() == 0) {
if (childNode && childNode->node()) {
updated |= transform->addChild(childNode->node());
}
} else {
if (childNode && childNode->node()) {
if (transform->getChild(0) != childNode->node()) {
updated |= transform->removeChild(0, 1);
updated |= transform->addChild(childNode->node());
}
} else {
updated |= transform->removeChild(0, 1);
}
}
// if (updated) {
self->emitNodeChanged();
// }
}
void updateSceneNode()
{
qDebug() << "OSGGeoTransformNode::updateSceneNode" << sceneNode;
@ -171,7 +129,7 @@ public:
// get "size" of model
// TODO this should be done once only...
osg::ComputeBoundsVisitor cbv;
childNode->node()->accept(cbv);
transform->accept(cbv);
const osg::BoundingBox & bbox = cbv.getBoundingBox();
offset = bbox.radius();
@ -187,12 +145,6 @@ public:
}
private slots:
void onChildNodeChanged(osg::Node *node)
{
qDebug() << "OSGGeoTransformNode::onChildNodeChanged" << node;
updateChildNode();
}
void onSceneNodeChanged(osg::Node *node)
{
qDebug() << "OSGGeoTransformNode::onSceneNodeChanged" << node;
@ -212,19 +164,6 @@ OSGGeoTransformNode::~OSGGeoTransformNode()
delete h;
}
OSGNode *OSGGeoTransformNode::childNode() const
{
return h->childNode;
}
void OSGGeoTransformNode::setChildNode(OSGNode *node)
{
if (h->acceptChildNode(node)) {
setDirty(Child);
emit childNodeChanged(node);
}
}
OSGNode *OSGGeoTransformNode::sceneNode() const
{
return h->sceneNode;
@ -280,9 +219,6 @@ void OSGGeoTransformNode::updateNode()
{
Inherited::updateNode();
if (isDirty(Child)) {
h->updateChildNode();
}
if (isDirty(Scene)) {
h->updateSceneNode();
}

View File

@ -29,28 +29,23 @@
#define _H_OSGQTQUICK_GEOTRANSFORMNODE_H_
#include "Export.hpp"
#include "OSGNode.hpp"
#include "OSGGroup.hpp"
#include <QVector3D>
// TODO derive from OSGGroup...
namespace osgQtQuick {
class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGNode {
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged)
Q_PROPERTY(osgQtQuick::OSGNode * sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged)
class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGGroup {
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged)
Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged)
Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged)
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
typedef OSGNode Inherited;
typedef OSGGroup Inherited;
public:
OSGGeoTransformNode(QObject *parent = 0);
virtual ~OSGGeoTransformNode();
OSGNode *childNode() const;
void setChildNode(OSGNode *node);
OSGNode *sceneNode() const;
void setSceneNode(OSGNode *node);
@ -63,13 +58,9 @@ public:
void setPosition(QVector3D arg);
signals:
void childNodeChanged(OSGNode *node);
void sceneNodeChanged(OSGNode *node);
void clampToTerrainChanged(bool arg);
void intoTerrainChanged(bool arg);
void positionChanged(QVector3D arg);
protected:

View File

@ -34,7 +34,9 @@
#include <QDebug>
namespace osgQtQuick {
enum DirtyFlag { Child = 1 << 0, Scale = 1 << 1, Position = 1 << 2, Attitude = 1 << 3 };
// NOTE : these flags should not overlap with OSGGroup flags!!!
// TODO : find a better way...
enum DirtyFlag { Scale = 1 << 10, Position = 1 << 11, Attitude = 1 << 12 };
struct OSGTransformNode::Hidden : public QObject {
Q_OBJECT
@ -45,13 +47,11 @@ private:
osg::ref_ptr<osg::PositionAttitudeTransform> transform;
public:
OSGNode *childNode;
QVector3D scale;
QVector3D attitude;
QVector3D position;
Hidden(OSGTransformNode *self) : QObject(self), self(self), childNode(NULL)
Hidden(OSGTransformNode *self) : QObject(self), self(self)
{}
osg::Node *createNode()
@ -60,49 +60,6 @@ public:
return transform;
}
bool acceptChildNode(OSGNode *node)
{
qDebug() << "OSGTransformNode::acceptChildNode" << node;
if (childNode == node) {
return false;
}
if (childNode) {
disconnect(childNode);
}
childNode = node;
if (childNode) {
connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)));
}
return true;
}
void updateChildNode()
{
qDebug() << "OSGTransformNode::updateChildNode" << childNode;
bool updated = false;
if (transform->getNumChildren() == 0) {
if (childNode && childNode->node()) {
updated |= transform->addChild(childNode->node());
}
} else {
if (childNode && childNode->node()) {
if (transform->getChild(0) != childNode->node()) {
updated |= transform->removeChild(0, 1);
updated |= transform->addChild(childNode->node());
}
} else {
updated |= transform->removeChild(0, 1);
}
}
// if (updated) {
self->emitNodeChanged();
// }
}
void updateScale()
{
// qDebug() << "OSGTransformNode::updateScale" << scale;
@ -130,13 +87,6 @@ public:
{
transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z()));
}
private slots:
void onChildNodeChanged(osg::Node *node)
{
qDebug() << "OSGTransformNode::onChildNodeChanged" << node;
updateChildNode();
}
};
/* class OSGTransformNode */
@ -150,19 +100,6 @@ OSGTransformNode::~OSGTransformNode()
delete h;
}
OSGNode *OSGTransformNode::childNode() const
{
return h->childNode;
}
void OSGTransformNode::setChildNode(OSGNode *node)
{
if (h->acceptChildNode(node)) {
setDirty(Child);
emit childNodeChanged(node);
}
}
QVector3D OSGTransformNode::scale() const
{
return h->scale;
@ -214,9 +151,6 @@ void OSGTransformNode::updateNode()
{
Inherited::updateNode();
if (isDirty(Child)) {
h->updateChildNode();
}
if (isDirty(Scale)) {
h->updateScale();
}

View File

@ -29,27 +29,22 @@
#define _H_OSGQTQUICK_TRANSFORMNODE_H_
#include "Export.hpp"
#include "OSGNode.hpp"
#include "OSGGroup.hpp"
#include <QVector3D>
// TODO derive from OSGGroup...
namespace osgQtQuick {
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode {
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged)
Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGGroup {
Q_OBJECT Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
Q_PROPERTY(QVector3D attitude READ attitude WRITE setAttitude NOTIFY attitudeChanged)
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
typedef OSGNode Inherited;
typedef OSGGroup Inherited;
public:
OSGTransformNode(QObject *parent = 0);
virtual ~OSGTransformNode();
OSGNode *childNode() const;
void setChildNode(OSGNode *node);
QVector3D scale() const;
void setScale(QVector3D arg);
@ -60,8 +55,6 @@ public:
void setPosition(QVector3D arg);
signals:
void childNodeChanged(OSGNode *node);
void scaleChanged(QVector3D arg);
void attitudeChanged(QVector3D arg);
void positionChanged(QVector3D arg);

View File

@ -67,8 +67,8 @@ Item {
OSGGeoTransformNode {
id: modelNode
childNode: modelTransformNode
sceneNode: terrainFileNode
children: [ modelTransformNode ]
clampToTerrain: true
@ -77,7 +77,9 @@ Item {
OSGTransformNode {
id: modelTransformNode
childNode: modelFileNode
children: [ modelFileNode ]
// model dimensions are in mm, scale to meters
scale: Qt.vector3d(0.001, 0.001, 0.001)
attitude: UAV.attitude()

View File

@ -60,7 +60,9 @@ Item {
OSGTransformNode {
id: transformNode
childNode: fileNode
children: [ fileNode ]
attitude: UAV.attitude()
}