OpenWalnut  1.5.0dev
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  m_geode->setName( "__Viewer Effect Plane" ); // Two underscores to be ignore during picking
67 
68  // add the slice to the geode
69  addChild( m_geode );
70 
71  // Configure properties
72  m_active = m_properties->addProperty( "Active", "Activate this effect?", false );
73  // let this control the nodemask
74  addUpdateCallback( new WGENodeMaskCallback( m_active ) );
75 }
76 
78 {
79  // cleanup
80 }
81 
83 {
84  return m_active->get();
85 }
86 
87 void WGEViewerEffect::setEnabled( bool enable )
88 {
89  m_active->set( enable );
90 }
91 
92 void WGEViewerEffect::setEnabledByDefault( bool enableByDefault )
93 {
94  m_active->setRecommendedValue( enableByDefault );
95 }
This callback is useful to en-/disable nodes using the node mask based on properties.
WGEViewerEffect(std::string name, std::string description, const char **icon=NULL)
Create the effect.
WPropBool m_active
Enable or disable effect.
virtual void setEnabled(bool enable=true)
Set the effect enabled.
virtual bool isEnabled() const
Check whether the effect is active or not.
virtual void setEnabledByDefault(bool enableByDefault=true)
Use this to activate an effect by default.
osg::ref_ptr< osg::StateSet > m_state
The stateset of the cam.
osg::ref_ptr< osg::Geode > m_geode
The fullscreen quad.
virtual ~WGEViewerEffect()
Destructor.
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP).
Definition: WObjectNDIP.h:42
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:99
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.