OpenWalnut  1.4.0
WGEViewerEffect.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <string>
00026 
00027 #include <osg/Depth>
00028 
00029 #include "WGEGeodeUtils.h"
00030 #include "shaders/WGEShader.h"
00031 #include "callbacks/WGENodeMaskCallback.h"
00032 
00033 #include "WGEViewerEffect.h"
00034 
00035 WGEViewerEffect::WGEViewerEffect( std::string name, std::string description, const char** icon ):
00036     WObjectNDIP( name, description, icon )
00037 {
00038     // setup camera
00039     setClearMask( GL_DEPTH_BUFFER_BIT );
00040     setRenderOrder( WGECamera::POST_RENDER );
00041     setReferenceFrame( osg::Transform::ABSOLUTE_RF );
00042     setProjectionMatrixAsOrtho2D( 0.0, 1.0, 0.0, 1.0 );
00043     setViewMatrix( osg::Matrixd::identity() );
00044 
00045     // some state options
00046     m_state = getOrCreateStateSet();
00047     m_state->setMode( GL_DEPTH_TEST,  osg::StateAttribute::PROTECTED |
00048                                       osg::StateAttribute::OVERRIDE |
00049                                       osg::StateAttribute::OFF );
00050     m_state->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED |
00051                                    osg::StateAttribute::OVERRIDE |
00052                                    osg::StateAttribute::OFF );
00053     m_state->setMode( GL_BLEND, osg::StateAttribute::PROTECTED |
00054                                 osg::StateAttribute::OVERRIDE |
00055                                 osg::StateAttribute::ON );
00056 
00057     osg::Depth* depth = new osg::Depth;
00058     depth->setWriteMask( false );
00059     m_state->setAttributeAndModes( depth, osg::StateAttribute::PROTECTED |
00060                                           osg::StateAttribute::OVERRIDE |
00061                                           osg::StateAttribute::ON );
00062 
00063     m_geode = wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ),
00064                                    osg::Vec3( 1.0, 0.0, 0.0 ),
00065                                    osg::Vec3( 0.0, 1.0, 0.0 ) );
00066 
00067     // add the slice to the geode
00068     addChild( m_geode );
00069 
00070     // Configure properties
00071     m_active = m_properties->addProperty( "Active", "Activate this effect?", false );
00072     // let this control the nodemask
00073     addUpdateCallback( new WGENodeMaskCallback( m_active ) );
00074 }
00075 
00076 WGEViewerEffect::~WGEViewerEffect()
00077 {
00078     // cleanup
00079 }
00080 
00081 bool WGEViewerEffect::isEnabled() const
00082 {
00083     return m_active->get();
00084 }
00085 
00086 void WGEViewerEffect::setEnabled( bool enable )
00087 {
00088     m_active->set( enable );
00089 }
00090 
00091 void WGEViewerEffect::setEnabledByDefault( bool enableByDefault )
00092 {
00093     m_active->setRecommendedValue( enableByDefault );
00094 }