Added s/getCullSettings to OsgCameraGroup

This commit is contained in:
Robert Osfield 2004-10-05 19:12:46 +00:00
parent 3b8abfa875
commit debf8dceef
3 changed files with 54 additions and 29 deletions

View File

@ -90,12 +90,12 @@ public:
ModelPositionCallback():
_latitude(0.0),
_longitude(0.0),
_height(1000.0)
_height(10000.0)
{}
void updateParameters()
{
_longitude += (2.0*osg::PI)/360.0;
_latitude -= ((2.0*osg::PI)/360.0)/100.0;
}
@ -174,12 +174,6 @@ public:
};
void addModel(osgProducer::Viewer* viewer,osg::Node* model)
{
}
int main(int argc, char **argv)
{
// use an ArgumentParser object to manage the program arguments.
@ -197,7 +191,8 @@ int main(int argc, char **argv)
// set up the value with sensible default event handlers.
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
viewer.getCullSettings().setNearFarRatio(0.0001f);
// get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage());
@ -219,29 +214,38 @@ int main(int argc, char **argv)
return 1;
}
osg::Node *root = createEarth();
if (!root) return 0;
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData(root);
FindNamedNodeVisitor fnnv("cessna");
root->accept(fnnv);
osg::ref_ptr<osg::Node> root = createEarth();
if (!fnnv._foundNodes.empty())
if (!root) return 0;
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData(root.get());
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get());
if (csn)
{
osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
tm->setTrackNode(fnnv._foundNodes[0].get());
std::cout<<"Found "<<std::endl;
unsigned int num = viewer.addCameraManipulator(tm);
viewer.selectCameraManipulator(num);
}
osg::Node* cessna = osgDB::readNodeFile("cessna.osg");
if (cessna)
{
osg::MatrixTransform* mt = new osg::MatrixTransform;
mt->addChild(cessna);
mt->setUpdateCallback(new ModelPositionCallback);
csn->addChild(mt);
osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
tm->setTrackNode(cessna);
unsigned int num = viewer.addCameraManipulator(tm);
viewer.selectCameraManipulator(num);
}
else
{
std::cout<<"Failed to read cessna.osg"<<std::endl;
}
}
// create the windows and run the threads.
viewer.realize();

View File

@ -24,6 +24,7 @@
#include <osg/StateSet>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
#include <osg/CullSettings>
#include <osg/Matrixd>
#include <osgProducer/OsgSceneHandler>
@ -90,6 +91,13 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
const osg::DisplaySettings *getDisplaySettings() const { return _ds.get(); }
void setCullSettings( const osg::CullSettings& cs) { _cullSettings = cs; }
osg::CullSettings& getCullSettings() { return _cullSettings; }
const osg::CullSettings& getCullSettings() const { return _cullSettings; }
void setFrameStamp( osg::FrameStamp* fs );
@ -202,6 +210,8 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
osg::ref_ptr<osg::DisplaySettings> _ds;
bool _initialized;
osg::CullSettings _cullSettings;
unsigned int _frameNumber;
osg::Timer _timer;

View File

@ -611,6 +611,17 @@ void OsgCameraGroup::frame()
osg::Node* node = getTopMostSceneData();
if (node) node->getBound();
CameraGroup::frame();
// pass on the cull settings to the scene views to keep
// the settings in sync.
for(SceneHandlerList::iterator itr = _shvec.begin();
itr != _shvec.end();
++itr)
{
(*itr)->getSceneView()->setCullSettings(_cullSettings);
}
CameraGroup::frame();
}