Reorganised the Group::removeChild and Geode::removeDrawable methods so
that removeChild(Node*), removeChild(uint) and equivilant Geode methods are now inline methods, not designed to be overriden, and seperated out the multiple remove method to be called removeChildren(uint, uint) which is now the only virtual method. There removeChildren is now the method to override in subclasses. This reorganisation requires some call code to be rename removeChild usage to removeChildren.
This commit is contained in:
@@ -156,20 +156,16 @@ bool CURRENT_CLASS::insertChild(unsigned int index, osg::Node *child)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CURRENT_CLASS::removeChild(osg::Node *child)
|
||||
{
|
||||
return Group::removeChild(child);
|
||||
}
|
||||
|
||||
bool CURRENT_CLASS::removeChild(unsigned int pos, unsigned int numRemove)
|
||||
bool CURRENT_CLASS::removeChildren(unsigned int pos, unsigned int numRemove)
|
||||
{
|
||||
if(!Group::removeChild(pos, numRemove)) return false; // Remove child
|
||||
if(!Group::removeChildren(pos, numRemove)) return false; // Remove child
|
||||
|
||||
// Remove child from each CameraNode
|
||||
unsigned int totalCameras = _cameraList.size();
|
||||
for(unsigned int i = 0; i < totalCameras; i++)
|
||||
{
|
||||
_cameraList[i]->removeChild(pos, numRemove);
|
||||
_cameraList[i]->removeChildren(pos, numRemove);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ class CURRENT_CLASS : public osg::Group
|
||||
of added or removed children. */
|
||||
virtual bool addChild(osg::Node *child);
|
||||
virtual bool insertChild(unsigned int index, osg::Node *child);
|
||||
virtual bool removeChild(osg::Node *child);
|
||||
virtual bool removeChild(unsigned int pos, unsigned int numRemove = 1);
|
||||
virtual bool removeChildren(unsigned int pos, unsigned int numRemove = 1);
|
||||
virtual bool setChild(unsigned int i, osg::Node *node);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -24,7 +24,7 @@ void Frame::rebuild()
|
||||
{
|
||||
float zPos = -0.1f;
|
||||
|
||||
removeDrawable(0, getNumDrawables());
|
||||
removeDrawables(0, getNumDrawables());
|
||||
addDrawable(build_quad(rect_, bgcolor_));
|
||||
addDrawable(build_quad(Rect(rect_.x0 + 4, rect_.y1 - 24, rect_.x1 - 4, rect_.y1 - 4), osg::Vec4(0, 0, 0, bgcolor_.w()), false, zPos));
|
||||
|
||||
|
||||
@@ -180,10 +180,10 @@ protected:
|
||||
effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription());
|
||||
|
||||
if (_scene.valid() && _root.valid()) {
|
||||
_root->removeChild(0, _root->getNumChildren());
|
||||
_root->removeChildren(0, _root->getNumChildren());
|
||||
osg::ref_ptr<osgFX::Effect> effect = _effects[_selected_fx].get();
|
||||
effect->setEnabled(_fxen);
|
||||
effect->removeChild(0, effect->getNumChildren());
|
||||
effect->removeChildren(0, effect->getNumChildren());
|
||||
effect->addChild(_scene.get());
|
||||
effect->setUpDemo();
|
||||
_root->addChild(effect.get());
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
#include <osg/Shape>
|
||||
#include <osg/PolygonMode>
|
||||
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
@@ -312,15 +310,11 @@ int main(int argc, char **argv)
|
||||
viewer.setSceneData(root.get());
|
||||
|
||||
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get());
|
||||
osg::Group * overlaySubGraph = new osg::Group;
|
||||
if (csn)
|
||||
{
|
||||
|
||||
bool insertOverlayNode = true;
|
||||
osg::ref_ptr<osgSim::OverlayNode> overlayNode;
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osg");
|
||||
double s = 200000.0 / cessna->getBound().radius();
|
||||
|
||||
if (insertOverlayNode)
|
||||
{
|
||||
|
||||
@@ -331,34 +325,21 @@ int main(int argc, char **argv)
|
||||
{
|
||||
overlayNode->addChild( csn->getChild(i) );
|
||||
}
|
||||
csn->removeChild(0, csn->getNumChildren());
|
||||
|
||||
csn->removeChildren(0, csn->getNumChildren());
|
||||
csn->addChild(overlayNode.get());
|
||||
|
||||
osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode;
|
||||
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
|
||||
osg::NodeCallback* sphereCb = new ModelPositionCallback;
|
||||
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
|
||||
mt->setUpdateCallback(sphereCb);
|
||||
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
osg::ref_ptr<osg::ShapeDrawable> sd;
|
||||
sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),s));
|
||||
sd->setColor(osg::Vec4(1.0,0.0,0.0,1.0));
|
||||
geode->addDrawable(sd.get());
|
||||
|
||||
mt->addChild(geode.get());
|
||||
overlaySubGraph->addChild(mt.get());
|
||||
|
||||
geode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON);
|
||||
// tell the overlay node to continously update its overlay texture
|
||||
// as we know we'll be tracking a moving target.
|
||||
overlayNode->setContinuousUpdate(true);
|
||||
}
|
||||
|
||||
|
||||
//osg::Node* cessna = osgDB::readNodeFile("f15.ive");
|
||||
osg::Node* cessna = osgDB::readNodeFile("cessna.osg");
|
||||
if (cessna)
|
||||
{
|
||||
double s = 200000.0 / cessna->getBound().radius();
|
||||
|
||||
osg::MatrixTransform* scaler = new osg::MatrixTransform;
|
||||
scaler->addChild(cessna);
|
||||
scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation));
|
||||
@@ -367,15 +348,18 @@ int main(int argc, char **argv)
|
||||
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
||||
mt->addChild(scaler);
|
||||
|
||||
|
||||
if (!nc) nc = new ModelPositionCallback;
|
||||
|
||||
mt->setUpdateCallback(nc);
|
||||
|
||||
csn->addChild(mt);
|
||||
|
||||
// if (overlaySubGraph) overlaySubGraph->addChild(mt);
|
||||
|
||||
// if we are using an overaly node, use the cessna subgraph as the overlay subgraph
|
||||
if (overlayNode.valid())
|
||||
{
|
||||
overlayNode->setOverlaySubgraph(mt);
|
||||
}
|
||||
|
||||
osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
|
||||
tm->setTrackerMode(trackerMode);
|
||||
@@ -390,10 +374,6 @@ int main(int argc, char **argv)
|
||||
std::cout<<"Failed to read cessna.osg"<<std::endl;
|
||||
}
|
||||
|
||||
if (overlayNode.valid())
|
||||
{
|
||||
// overlayNode->setOverlaySubgraph(overlaySubGraph);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user