2 ******************************************************************************
4 * @file OSGTransformNode.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "OSGTransformNode.hpp"
31 #include <osg/PositionAttitudeTransform>
36 namespace osgQtQuick
{
37 // NOTE : these flags should not overlap with OSGGroup flags!!!
38 // TODO : find a better way...
39 enum DirtyFlag
{ Scale
= 1 << 10, Position
= 1 << 11, Attitude
= 1 << 12 };
41 struct OSGTransformNode::Hidden
: public QObject
{
45 OSGTransformNode
* const self
;
47 osg::ref_ptr
<osg::PositionAttitudeTransform
> transform
;
54 Hidden(OSGTransformNode
*self
) : QObject(self
), self(self
)
57 osg::Node
*createNode()
59 transform
= new osg::PositionAttitudeTransform();
65 // qDebug() << "OSGTransformNode::updateScale" << scale;
66 if ((scale
.x() != 0.0) || (scale
.y() != 0.0) || (scale
.z() != 0.0)) {
67 transform
->setScale(osg::Vec3d(scale
.x(), scale
.y(), scale
.z()));
68 // transform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
69 transform
->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL
, osg::StateAttribute::ON
);
75 double roll
= osg::DegreesToRadians(attitude
.x());
76 double pitch
= osg::DegreesToRadians(attitude
.y());
77 double yaw
= osg::DegreesToRadians(attitude
.z());
78 osg::Quat q
= osg::Quat(
79 roll
, osg::Vec3d(0, 1, 0),
80 pitch
, osg::Vec3d(1, 0, 0),
81 yaw
, osg::Vec3d(0, 0, -1));
83 transform
->setAttitude(q
);
88 transform
->setPosition(osg::Vec3d(position
.x(), position
.y(), position
.z()));
92 /* class OSGTransformNode */
94 OSGTransformNode::OSGTransformNode(QObject
*parent
) : Inherited(parent
), h(new Hidden(this))
97 OSGTransformNode::~OSGTransformNode()
102 QVector3D
OSGTransformNode::scale() const
107 void OSGTransformNode::setScale(QVector3D arg
)
109 if (h
->scale
!= arg
) {
112 emit
scaleChanged(scale());
116 QVector3D
OSGTransformNode::attitude() const
121 void OSGTransformNode::setAttitude(QVector3D arg
)
123 if (h
->attitude
!= arg
) {
126 emit
attitudeChanged(attitude());
130 QVector3D
OSGTransformNode::position() const
135 void OSGTransformNode::setPosition(QVector3D arg
)
137 if (h
->position
!= arg
) {
140 emit
positionChanged(position());
144 osg::Node
*OSGTransformNode::createNode()
146 return h
->createNode();
149 void OSGTransformNode::updateNode()
151 Inherited::updateNode();
153 if (isDirty(Scale
)) {
156 if (isDirty(Attitude
)) {
159 if (isDirty(Position
)) {
163 } // namespace osgQtQuick
165 #include "OSGTransformNode.moc"