OpenWalnut  1.4.0
WGEViewerEffect.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 
27 #include <osg/Depth>
28 
29 #include "WGEGeodeUtils.h"
30 #include "shaders/WGEShader.h"
31 #include "callbacks/WGENodeMaskCallback.h"
32 
33 #include "WGEViewerEffect.h"
34 
35 WGEViewerEffect::WGEViewerEffect( std::string name, std::string description, const char** icon ):
36  WObjectNDIP( name, description, icon )
37 {
38  // setup camera
39  setClearMask( GL_DEPTH_BUFFER_BIT );
40  setRenderOrder( WGECamera::POST_RENDER );
41  setReferenceFrame( osg::Transform::ABSOLUTE_RF );
42  setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
43  setViewMatrix( osg::Matrixd::identity() );
44 
45  // some state options
46  m_state = getOrCreateStateSet();
47  m_state->setMode( GL_DEPTH_TEST, osg::StateAttribute::PROTECTED |
48  osg::StateAttribute::OVERRIDE |
49  osg::StateAttribute::OFF );
50  m_state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED |
51  osg::StateAttribute::OVERRIDE |
52  osg::StateAttribute::OFF );
53  m_state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED |
54  osg::StateAttribute::OVERRIDE |
55  osg::StateAttribute::ON );
56 
57  osg::Depth* depth = new osg::Depth;
58  depth->setWriteMask( false );
59  m_state->setAttributeAndModes( depth, osg::StateAttribute::PROTECTED |
60  osg::StateAttribute::OVERRIDE |
61  osg::StateAttribute::ON );
62 
63  m_geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
64  osg::Vec3( 1.0, 0.0, 0.0 ),
65  osg::Vec3( 0.0, 1.0, 0.0 ) );
66 
67  // add the slice to the geode
68  addChild( m_geode );
69 
70  // Configure properties
71  m_active = m_properties->addProperty( "Active", "Activate this effect?", false );
72  // let this control the nodemask
73  addUpdateCallback( new WGENodeMaskCallback( m_active ) );
74 }
75 
77 {
78  // cleanup
79 }
80 
82 {
83  return m_active->get();
84 }
85 
86 void WGEViewerEffect::setEnabled( bool enable )
87 {
88  m_active->set( enable );
89 }
90 
91 void WGEViewerEffect::setEnabledByDefault( bool enableByDefault )
92 {
93  m_active->setRecommendedValue( enableByDefault );
94 }
WPropBool m_active
Enable or disable effect.
virtual void setEnabled(bool enable=true)
Set the effect enabled.
osg::ref_ptr< osg::Geode > genFinitePlane(double xSize, double ySize, const WPlane &p, const WColor &color=WColor(0.0, 0.7, 0.7, 1.0), bool border=false)
Generates a geode out of a Plane with a fixed size in direction of the vectors which span that plane...
virtual ~WGEViewerEffect()
Destructor.
virtual void setEnabledByDefault(bool enableByDefault=true)
Use this to activate an effect by default.
WGEViewerEffect(std::string name, std::string description, const char **icon=NULL)
Create the effect.
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP)...
Definition: WObjectNDIP.h:43
virtual bool isEnabled() const
Check whether the effect is active or not.
This callback is useful to en-/disable nodes using the node mask based on properties.
osg::ref_ptr< osg::Geode > m_geode
The fullscreen quad.
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:101
osg::ref_ptr< osg::StateSet > m_state
The stateset of the cam.