X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCockpit%2Fod_gauge.cxx;h=4f569acb1af97733c67d753b7d51335301c99108;hb=68c71d5787f2a0309e35c3e05939950113618cb7;hp=9e7c3e1e426986a4e08c96d8925798a0ed25f858;hpb=2ad82a1b6083662c065e9f4e39f97c224384b4dc;p=flightgear.git diff --git a/src/Cockpit/od_gauge.cxx b/src/Cockpit/od_gauge.cxx index 9e7c3e1e4..4f569acb1 100644 --- a/src/Cockpit/od_gauge.cxx +++ b/src/Cockpit/od_gauge.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -47,30 +48,21 @@ #include #include +#include #include
-#include #include #include "od_gauge.hxx" #include -//------------------------------------------------------------------------------ -static void cbAddCamera(osg::Camera* cam) -{ - globals->get_renderer()->addCamera(cam, false); -} - -//------------------------------------------------------------------------------ -static void cbRemoveCamera(osg::Camera* cam) -{ - globals->get_renderer()->removeCamera(cam); -} +static simgear::canvas::SystemAdapterPtr system_adapter( + new canvas::FGCanvasSystemAdapter +); //------------------------------------------------------------------------------ -FGODGauge::FGODGauge(): - simgear::ODGauge(cbAddCamera, cbRemoveCamera) +FGODGauge::FGODGauge() { - + setSystemAdapter(system_adapter); } //------------------------------------------------------------------------------ @@ -87,6 +79,9 @@ class ReplaceStaticTextureVisitor: { public: + typedef osg::ref_ptr GroupPtr; + typedef osg::ref_ptr MaterialPtr; + ReplaceStaticTextureVisitor( const char* name, osg::Texture2D* new_texture ): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), @@ -94,7 +89,7 @@ class ReplaceStaticTextureVisitor: _new_texture(new_texture) {} - ReplaceStaticTextureVisitor( const SGPropertyNode* placement, + ReplaceStaticTextureVisitor( SGPropertyNode* placement, osg::Texture2D* new_texture, osg::NodeCallback* cull_callback = 0 ): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), @@ -103,6 +98,7 @@ class ReplaceStaticTextureVisitor: ), _node_name( placement->getStringValue("node") ), _parent_name( placement->getStringValue("parent") ), + _node(placement), _new_texture(new_texture), _cull_callback(cull_callback) { @@ -122,7 +118,7 @@ class ReplaceStaticTextureVisitor: * Get a list of groups which have been inserted into the scene graph to * replace the given texture */ - canvas::Placements& getPlacements() + simgear::canvas::Placements& getPlacements() { return _placements; } @@ -188,7 +184,7 @@ class ReplaceStaticTextureVisitor: // insert a new group between the geode an it's parent which overrides // the texture - osg::ref_ptr group = new osg::Group; + GroupPtr group = new osg::Group; group->setName("canvas texture group"); group->addChild(eg); parent->removeChild(eg); @@ -197,16 +193,16 @@ class ReplaceStaticTextureVisitor: if( _cull_callback ) group->setCullCallback(_cull_callback); - _placements.push_back( - canvas::PlacementPtr(new ObjectPlacement(group)) - ); - osg::StateSet* stateSet = group->getOrCreateStateSet(); stateSet->setTextureAttribute( unit, _new_texture, osg::StateAttribute::OVERRIDE ); stateSet->setTextureMode( unit, GL_TEXTURE_2D, osg::StateAttribute::ON ); + _placements.push_back( simgear::canvas::PlacementPtr( + new ObjectPlacement(_node, group) + )); + SG_LOG ( SG_GL, @@ -223,12 +219,52 @@ class ReplaceStaticTextureVisitor: protected: class ObjectPlacement: - public canvas::Placement + public simgear::canvas::Placement { public: - ObjectPlacement(osg::ref_ptr group): + + ObjectPlacement( SGPropertyNode* node, + GroupPtr group ): + Placement(node), _group(group) - {} + { + // TODO make more generic and extendable for more properties + if( node->hasValue("emission") ) + setEmission( node->getFloatValue("emission") ); + } + + virtual bool childChanged(SGPropertyNode* node) + { + if( node->getParent() != _node ) + return false; + + if( node->getNameString() == "emission" ) + setEmission( node->getFloatValue() ); + else + return false; + + return true; + } + + void setEmission(float emit) + { + emit = SGMiscf::clip(emit, 0, 1); + + if( !_material ) + { + _material = new osg::Material; + _material->setColorMode(osg::Material::OFF); + _material->setDataVariance(osg::Object::DYNAMIC); + _group->getOrCreateStateSet() + ->setAttribute(_material, ( osg::StateAttribute::ON + | osg::StateAttribute::OVERRIDE ) ); + } + + _material->setEmission( + osg::Material::FRONT_AND_BACK, + osg::Vec4(emit, emit, emit, emit) + ); + } /** * Remove placement from the scene @@ -249,22 +285,26 @@ class ReplaceStaticTextureVisitor: } private: - osg::ref_ptr _group; + GroupPtr _group; + MaterialPtr _material; }; std::string _tex_name, ///get_scenery()->get_aircraft_branch(); ReplaceStaticTextureVisitor visitor(name, new_texture); @@ -273,9 +313,10 @@ canvas::Placements FGODGauge::set_texture( const char* name, } //------------------------------------------------------------------------------ -canvas::Placements FGODGauge::set_texture( const SGPropertyNode* placement, - osg::Texture2D* new_texture, - osg::NodeCallback* cull_callback ) +simgear::canvas::Placements +FGODGauge::set_texture( SGPropertyNode* placement, + osg::Texture2D* new_texture, + osg::NodeCallback* cull_callback ) { osg::Group* root = globals->get_scenery()->get_aircraft_branch(); ReplaceStaticTextureVisitor visitor(placement, new_texture, cull_callback);