1 #include <GLviewer/Scenes/SceneBase.hh>
2 #include <Base/Common/FileHandling.hh>
3 #include "ScenePlainOpenSceneGraph.hh"
4 #include <osg/MatrixTransform>
5 #include <osgShadow/ShadowedScene>
12 ScenePlainOpenSceneGraph::ScenePlainOpenSceneGraph() :
SceneBase()
20 BIASERR(
"Init on SceneOpenSceneGraph should only be called once: skipping\n");
27 sceneView_->setThreadingModel(osgViewer::Viewer::SingleThreaded);
29 sceneView_->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
41 rootNode_->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
44 rootNode_->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
61 node = osgDB::readNodeFile(filename);
73 node = osgDB::readNodeFile(fileName);
74 string path, base, suffix;
76 std::transform(suffix.begin(), suffix.end(), suffix.begin(), (int
77 (*)(int)) std::tolower);
78 if (suffix ==
".wrl") {
81 osg::MatrixTransform *mt =
82 dynamic_cast<osg::MatrixTransform *
> (node.get());
83 if (mt && mt->getNumChildren() == 1) {
84 node = mt->getChild(0);
109 int children =
rootNode_->getNumChildren();
124 glGetIntegerv( GL_VIEWPORT, viewParams );
125 if (
w_ != (
unsigned int)(viewParams[2]) ||
h_ != (
unsigned int)(viewParams[3])) {
126 w_ = (
unsigned int)viewParams[2];
127 h_ = (
unsigned int)viewParams[3];
135 glGetFloatv( GL_PROJECTION_MATRIX, glMat );
137 sceneView_->getCamera()->setProjectionMatrix( osgMat );
139 glGetFloatv( GL_MODELVIEW_MATRIX, glMat );
141 sceneView_->getCamera()->getViewMatrix().set( osgMat );
143 glPushAttrib( GL_VIEWPORT_BIT );
144 glMatrixMode(GL_PROJECTION);
146 glMatrixMode(GL_TEXTURE);
148 glMatrixMode(GL_MODELVIEW);
152 glMatrixMode(GL_MODELVIEW);
154 glMatrixMode(GL_TEXTURE);
156 glMatrixMode(GL_PROJECTION);
164 const osg::BoundingSphere& bs =
rootNode_->getBound();
167 (double) bs.center()[2]);
169 double radius = (double) bs.radius();
172 themin = center - diag;
173 themax = center + diag;
179 const osg::BoundingSphere& bs =
rootNode_->getBound();
182 (double) bs.center()[1], (double) bs.center()[2]);
bool Load(std::string filename)
virtual void Draw()
To do anything usefull, overload this method, assume context is ready and draw.
osg::ref_ptr< osg::Group > rootNode_
virtual Vector3< double > GetBoundingBoxCenter()
virtual void GetBoundingBox(BIAS::Vector3< double > &themin, BIAS::Vector3< double > &themax)
Determine and return the bouning box of all elements of the scene.
osg::ref_ptr< osgViewer::Viewer > sceneView_
static void SplitName(const std::string &fullname, std::string &dir, std::string &base, std::string &suffix)
Split full path into:
void AppendNode(osg::ref_ptr< osg::Node > node)
int AppendSubTreeFromFile(const std::string &fileName, osg::ref_ptr< osg::Node > &childNode)
Base class for all scenes.
void SetLighting(bool on)
osg::observer_ptr< osgViewer::GraphicsWindow > embedWindow_
int Init(unsigned int width=1200, unsigned int height=900)
virtual ~ScenePlainOpenSceneGraph()
void RemoveNode(osg::ref_ptr< osg::Node > node)
void SetRootNode(osg::ref_ptr< osg::Group > newRoot)