mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
LP-29 OSGTransformNode now derives from OSGGroup
This commit is contained in:
parent
5800f17d03
commit
444c126dab
@ -36,6 +36,8 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace osgQtQuick {
|
namespace osgQtQuick {
|
||||||
|
// NOTE : these flags should not overlap with OSGGroup flags!!!
|
||||||
|
// TODO : find a better way...
|
||||||
enum DirtyFlag {};
|
enum DirtyFlag {};
|
||||||
|
|
||||||
struct OSGBillboardNode::Hidden : public QObject {
|
struct OSGBillboardNode::Hidden : public QObject {
|
||||||
|
@ -38,7 +38,9 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace osgQtQuick {
|
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 {
|
struct OSGGeoTransformNode::Hidden : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -49,7 +51,6 @@ private:
|
|||||||
osg::ref_ptr<osgEarth::GeoTransform> transform;
|
osg::ref_ptr<osgEarth::GeoTransform> transform;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OSGNode *childNode;
|
|
||||||
OSGNode *sceneNode;
|
OSGNode *sceneNode;
|
||||||
|
|
||||||
float offset;
|
float offset;
|
||||||
@ -59,7 +60,7 @@ public:
|
|||||||
|
|
||||||
QVector3D position;
|
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()
|
osg::Node *createNode()
|
||||||
@ -69,26 +70,6 @@ public:
|
|||||||
return transform;
|
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)
|
bool acceptSceneNode(OSGNode *node)
|
||||||
{
|
{
|
||||||
qDebug() << "OSGGeoTransformNode::acceptSceneNode" << node;
|
qDebug() << "OSGGeoTransformNode::acceptSceneNode" << node;
|
||||||
@ -109,29 +90,6 @@ public:
|
|||||||
return true;
|
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()
|
void updateSceneNode()
|
||||||
{
|
{
|
||||||
qDebug() << "OSGGeoTransformNode::updateSceneNode" << sceneNode;
|
qDebug() << "OSGGeoTransformNode::updateSceneNode" << sceneNode;
|
||||||
@ -171,7 +129,7 @@ public:
|
|||||||
// get "size" of model
|
// get "size" of model
|
||||||
// TODO this should be done once only...
|
// TODO this should be done once only...
|
||||||
osg::ComputeBoundsVisitor cbv;
|
osg::ComputeBoundsVisitor cbv;
|
||||||
childNode->node()->accept(cbv);
|
transform->accept(cbv);
|
||||||
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
||||||
offset = bbox.radius();
|
offset = bbox.radius();
|
||||||
|
|
||||||
@ -187,12 +145,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onChildNodeChanged(osg::Node *node)
|
|
||||||
{
|
|
||||||
qDebug() << "OSGGeoTransformNode::onChildNodeChanged" << node;
|
|
||||||
updateChildNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onSceneNodeChanged(osg::Node *node)
|
void onSceneNodeChanged(osg::Node *node)
|
||||||
{
|
{
|
||||||
qDebug() << "OSGGeoTransformNode::onSceneNodeChanged" << node;
|
qDebug() << "OSGGeoTransformNode::onSceneNodeChanged" << node;
|
||||||
@ -212,19 +164,6 @@ OSGGeoTransformNode::~OSGGeoTransformNode()
|
|||||||
delete h;
|
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
|
OSGNode *OSGGeoTransformNode::sceneNode() const
|
||||||
{
|
{
|
||||||
return h->sceneNode;
|
return h->sceneNode;
|
||||||
@ -280,9 +219,6 @@ void OSGGeoTransformNode::updateNode()
|
|||||||
{
|
{
|
||||||
Inherited::updateNode();
|
Inherited::updateNode();
|
||||||
|
|
||||||
if (isDirty(Child)) {
|
|
||||||
h->updateChildNode();
|
|
||||||
}
|
|
||||||
if (isDirty(Scene)) {
|
if (isDirty(Scene)) {
|
||||||
h->updateSceneNode();
|
h->updateSceneNode();
|
||||||
}
|
}
|
||||||
|
@ -29,28 +29,23 @@
|
|||||||
#define _H_OSGQTQUICK_GEOTRANSFORMNODE_H_
|
#define _H_OSGQTQUICK_GEOTRANSFORMNODE_H_
|
||||||
|
|
||||||
#include "Export.hpp"
|
#include "Export.hpp"
|
||||||
#include "OSGNode.hpp"
|
#include "OSGGroup.hpp"
|
||||||
|
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
|
||||||
// TODO derive from OSGGroup...
|
|
||||||
namespace osgQtQuick {
|
namespace osgQtQuick {
|
||||||
class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGNode {
|
class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGGroup {
|
||||||
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged)
|
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged)
|
||||||
Q_PROPERTY(osgQtQuick::OSGNode * sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged)
|
|
||||||
Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged)
|
Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged)
|
||||||
Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged)
|
Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged)
|
||||||
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
|
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
|
||||||
|
|
||||||
typedef OSGNode Inherited;
|
typedef OSGGroup Inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OSGGeoTransformNode(QObject *parent = 0);
|
OSGGeoTransformNode(QObject *parent = 0);
|
||||||
virtual ~OSGGeoTransformNode();
|
virtual ~OSGGeoTransformNode();
|
||||||
|
|
||||||
OSGNode *childNode() const;
|
|
||||||
void setChildNode(OSGNode *node);
|
|
||||||
|
|
||||||
OSGNode *sceneNode() const;
|
OSGNode *sceneNode() const;
|
||||||
void setSceneNode(OSGNode *node);
|
void setSceneNode(OSGNode *node);
|
||||||
|
|
||||||
@ -63,13 +58,9 @@ public:
|
|||||||
void setPosition(QVector3D arg);
|
void setPosition(QVector3D arg);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void childNodeChanged(OSGNode *node);
|
|
||||||
|
|
||||||
void sceneNodeChanged(OSGNode *node);
|
void sceneNodeChanged(OSGNode *node);
|
||||||
|
|
||||||
void clampToTerrainChanged(bool arg);
|
void clampToTerrainChanged(bool arg);
|
||||||
void intoTerrainChanged(bool arg);
|
void intoTerrainChanged(bool arg);
|
||||||
|
|
||||||
void positionChanged(QVector3D arg);
|
void positionChanged(QVector3D arg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -34,7 +34,9 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace osgQtQuick {
|
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 {
|
struct OSGTransformNode::Hidden : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -45,13 +47,11 @@ private:
|
|||||||
osg::ref_ptr<osg::PositionAttitudeTransform> transform;
|
osg::ref_ptr<osg::PositionAttitudeTransform> transform;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OSGNode *childNode;
|
|
||||||
|
|
||||||
QVector3D scale;
|
QVector3D scale;
|
||||||
QVector3D attitude;
|
QVector3D attitude;
|
||||||
QVector3D position;
|
QVector3D position;
|
||||||
|
|
||||||
Hidden(OSGTransformNode *self) : QObject(self), self(self), childNode(NULL)
|
Hidden(OSGTransformNode *self) : QObject(self), self(self)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
osg::Node *createNode()
|
osg::Node *createNode()
|
||||||
@ -60,49 +60,6 @@ public:
|
|||||||
return transform;
|
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()
|
void updateScale()
|
||||||
{
|
{
|
||||||
// qDebug() << "OSGTransformNode::updateScale" << scale;
|
// qDebug() << "OSGTransformNode::updateScale" << scale;
|
||||||
@ -130,13 +87,6 @@ public:
|
|||||||
{
|
{
|
||||||
transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z()));
|
transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onChildNodeChanged(osg::Node *node)
|
|
||||||
{
|
|
||||||
qDebug() << "OSGTransformNode::onChildNodeChanged" << node;
|
|
||||||
updateChildNode();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* class OSGTransformNode */
|
/* class OSGTransformNode */
|
||||||
@ -150,19 +100,6 @@ OSGTransformNode::~OSGTransformNode()
|
|||||||
delete h;
|
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
|
QVector3D OSGTransformNode::scale() const
|
||||||
{
|
{
|
||||||
return h->scale;
|
return h->scale;
|
||||||
@ -214,9 +151,6 @@ void OSGTransformNode::updateNode()
|
|||||||
{
|
{
|
||||||
Inherited::updateNode();
|
Inherited::updateNode();
|
||||||
|
|
||||||
if (isDirty(Child)) {
|
|
||||||
h->updateChildNode();
|
|
||||||
}
|
|
||||||
if (isDirty(Scale)) {
|
if (isDirty(Scale)) {
|
||||||
h->updateScale();
|
h->updateScale();
|
||||||
}
|
}
|
||||||
|
@ -29,27 +29,22 @@
|
|||||||
#define _H_OSGQTQUICK_TRANSFORMNODE_H_
|
#define _H_OSGQTQUICK_TRANSFORMNODE_H_
|
||||||
|
|
||||||
#include "Export.hpp"
|
#include "Export.hpp"
|
||||||
#include "OSGNode.hpp"
|
#include "OSGGroup.hpp"
|
||||||
|
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
|
||||||
// TODO derive from OSGGroup...
|
|
||||||
namespace osgQtQuick {
|
namespace osgQtQuick {
|
||||||
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode {
|
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGGroup {
|
||||||
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged)
|
Q_OBJECT Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
|
||||||
Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
|
|
||||||
Q_PROPERTY(QVector3D attitude READ attitude WRITE setAttitude NOTIFY attitudeChanged)
|
Q_PROPERTY(QVector3D attitude READ attitude WRITE setAttitude NOTIFY attitudeChanged)
|
||||||
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
|
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
|
||||||
|
|
||||||
typedef OSGNode Inherited;
|
typedef OSGGroup Inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OSGTransformNode(QObject *parent = 0);
|
OSGTransformNode(QObject *parent = 0);
|
||||||
virtual ~OSGTransformNode();
|
virtual ~OSGTransformNode();
|
||||||
|
|
||||||
OSGNode *childNode() const;
|
|
||||||
void setChildNode(OSGNode *node);
|
|
||||||
|
|
||||||
QVector3D scale() const;
|
QVector3D scale() const;
|
||||||
void setScale(QVector3D arg);
|
void setScale(QVector3D arg);
|
||||||
|
|
||||||
@ -60,8 +55,6 @@ public:
|
|||||||
void setPosition(QVector3D arg);
|
void setPosition(QVector3D arg);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void childNodeChanged(OSGNode *node);
|
|
||||||
|
|
||||||
void scaleChanged(QVector3D arg);
|
void scaleChanged(QVector3D arg);
|
||||||
void attitudeChanged(QVector3D arg);
|
void attitudeChanged(QVector3D arg);
|
||||||
void positionChanged(QVector3D arg);
|
void positionChanged(QVector3D arg);
|
||||||
|
@ -67,8 +67,8 @@ Item {
|
|||||||
OSGGeoTransformNode {
|
OSGGeoTransformNode {
|
||||||
id: modelNode
|
id: modelNode
|
||||||
|
|
||||||
childNode: modelTransformNode
|
|
||||||
sceneNode: terrainFileNode
|
sceneNode: terrainFileNode
|
||||||
|
children: [ modelTransformNode ]
|
||||||
|
|
||||||
clampToTerrain: true
|
clampToTerrain: true
|
||||||
|
|
||||||
@ -77,7 +77,9 @@ Item {
|
|||||||
|
|
||||||
OSGTransformNode {
|
OSGTransformNode {
|
||||||
id: modelTransformNode
|
id: modelTransformNode
|
||||||
childNode: modelFileNode
|
|
||||||
|
children: [ modelFileNode ]
|
||||||
|
|
||||||
// model dimensions are in mm, scale to meters
|
// model dimensions are in mm, scale to meters
|
||||||
scale: Qt.vector3d(0.001, 0.001, 0.001)
|
scale: Qt.vector3d(0.001, 0.001, 0.001)
|
||||||
attitude: UAV.attitude()
|
attitude: UAV.attitude()
|
||||||
|
@ -60,7 +60,9 @@ Item {
|
|||||||
|
|
||||||
OSGTransformNode {
|
OSGTransformNode {
|
||||||
id: transformNode
|
id: transformNode
|
||||||
childNode: fileNode
|
|
||||||
|
children: [ fileNode ]
|
||||||
|
|
||||||
attitude: UAV.attitude()
|
attitude: UAV.attitude()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user