--- /dev/null
+// Copyright (C) 2010 Tim Moore (timoore33@gmail.com)
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include "ConditionNode.hxx"
+
+namespace simgear
+{
+using namespace osg;
+
+ConditionNode::ConditionNode()
+{
+}
+
+ConditionNode::ConditionNode(const ConditionNode& rhs, const CopyOp& op)
+ : Group(rhs, op), _condition(rhs._condition)
+{
+}
+
+ConditionNode::~ConditionNode()
+{
+}
+
+void ConditionNode::traverse(NodeVisitor& nv)
+{
+ if (nv.getTraversalMode() == NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {
+ unsigned numChildren = getNumChildren();
+ if (numChildren == 0)
+ return;
+ if (!_condition || _condition->test())
+ getChild(0)->accept(nv);
+ else if (numChildren > 1)
+ getChild(1)->accept(nv);
+ else
+ return;
+ } else {
+ Group::traverse(nv);
+ }
+}
+
+}
--- /dev/null
+// Copyright (C) 2010 Tim Moore (timoore33@gmail.com)
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#ifndef SIMGEAR_CONDITIONNODE_HXX
+#define SIMGEAR_CONDITIONNODE_HXX 1
+
+#include <simgear/props/condition.hxx>
+#include <osg/Group>
+
+namespace simgear
+{
+/**
+ * If the condition is true, traverse the first child; otherwise,
+ * traverse the second if it exists.
+ */
+class ConditionNode : public osg::Group
+{
+public:
+ ConditionNode();
+ ConditionNode(const ConditionNode& rhs,
+ const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY);
+ META_Node(simgear,ConditionNode);
+ ~ConditionNode();
+ const SGCondition* getCondition() { return _condition.ptr(); }
+ void setCondition(const SGCondition* condition) { _condition = condition; }
+
+ virtual void traverse(osg::NodeVisitor& nv);
+protected:
+ SGSharedPtr<SGCondition const> _condition;
+};
+
+}
+#endif
persparam.hxx \
placement.hxx \
CheckSceneryVisitor.hxx \
+ ConditionNode.hxx \
SGClipGroup.hxx \
SGInteractionAnimation.hxx \
SGMaterialAnimation.hxx \
placement.cxx \
shadanim.cxx \
CheckSceneryVisitor.cxx \
+ ConditionNode.cxx \
SGClipGroup.cxx \
SGInteractionAnimation.cxx \
SGMaterialAnimation.cxx \
#include "SGScaleTransform.hxx"
#include "SGInteractionAnimation.hxx"
+#include "ConditionNode.hxx"
+
using OpenThreads::Mutex;
using OpenThreads::ReentrantMutex;
using OpenThreads::ScopedLock;
// Implementation of a select animation
////////////////////////////////////////////////////////////////////////
-class SGSelectAnimation::UpdateCallback : public osg::NodeCallback {
-public:
- UpdateCallback(const SGCondition* condition) :
- _condition(condition)
- {}
- virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
- {
- osg::Switch* sw = static_cast<osg::Switch*>(node);
- if (_condition->test())
- sw->setAllChildrenOn();
- else
- sw->setAllChildrenOff();
- traverse(node, nv);
- }
-
-private:
- SGSharedPtr<SGCondition const> _condition;
-};
-
SGSelectAnimation::SGSelectAnimation(const SGPropertyNode* configNode,
SGPropertyNode* modelRoot) :
SGAnimation(configNode, modelRoot)
// when the animation installer returns
if (!condition)
return new osg::Group;
-
- osg::Switch* sw = new osg::Switch;
- sw->setName("select animation node");
- sw->setUpdateCallback(new UpdateCallback(condition));
- parent.addChild(sw);
- return sw;
+ simgear::ConditionNode* cn = new simgear::ConditionNode;
+ cn->setName("select animation node");
+ cn->setCondition(condition.ptr());
+ osg::Group* grp = new osg::Group;
+ cn->addChild(grp);
+ parent.addChild(cn);
+ return grp;
}
SGSelectAnimation(const SGPropertyNode* configNode,
SGPropertyNode* modelRoot);
virtual osg::Group* createAnimationGroup(osg::Group& parent);
-private:
- class UpdateCallback;
};
\f