OpenWalnut 1.2.5

WGEPropertyTransformationCallback.h

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 #ifndef WGEPROPERTYTRANSFORMATIONCALLBACK_H
00026 #define WGEPROPERTYTRANSFORMATIONCALLBACK_H
00027 
00028 #include <osg/Node>
00029 #include <osg/TexMat>
00030 #include <osg/StateAttribute>
00031 #include <osg/MatrixTransform>
00032 
00033 #include "WGECallbackTraits.h"
00034 #include "../../common/WProperties.h"
00035 #include "../WExportWGE.h"
00036 
00037 /**
00038  * TODO(ebaum): write.
00039  */
00040 template < typename ParentType = osg::Node, typename TargetType = osg::MatrixTransform >
00041 class WGEPropertyTransformationCallback: public WGECallbackTraits< ParentType >::CallbackType
00042 {
00043 public:
00044 
00045     /**
00046      * Default constructor.
00047      *
00048      * \param prop the property holding the matrix to use.
00049      */
00050     explicit WGEPropertyTransformationCallback( WPropMatrix4X4 prop );
00051 
00052     /**
00053      * Destructor.
00054      */
00055     virtual ~WGEPropertyTransformationCallback();
00056 
00057     /**
00058      * This operator gets called by OSG every update cycle. It calls the specified functor.
00059      *
00060      * \param handled the osg node, stateset or whatever
00061      * \param nv the node visitor
00062      */
00063     virtual void operator()( typename WGECallbackTraits< ParentType >::HandledType* handled, osg::NodeVisitor* nv );
00064 
00065 protected:
00066 
00067 private:
00068 
00069     /**
00070      * The property controlling the callback
00071      */
00072     WPropMatrix4X4 m_prop;
00073 };
00074 
00075 template < typename ParentType, typename TargetType >
00076 WGEPropertyTransformationCallback< ParentType, TargetType >::WGEPropertyTransformationCallback( WPropMatrix4X4 prop ):
00077     WGECallbackTraits< ParentType >::CallbackType(),
00078     m_prop( prop )
00079 {
00080     // initialize members
00081 }
00082 
00083 template < typename ParentType, typename TargetType >
00084 WGEPropertyTransformationCallback< ParentType, TargetType >::~WGEPropertyTransformationCallback()
00085 {
00086     // cleanup
00087 }
00088 
00089 template < typename ParentType, typename TargetType >
00090 void WGEPropertyTransformationCallback< ParentType, TargetType >::operator()( typename WGECallbackTraits< ParentType >::HandledType* handled,
00091                                                                               osg::NodeVisitor* nv )
00092 {
00093     TargetType* m = dynamic_cast< TargetType* >( handled );
00094     if( m )
00095     {
00096         m->setMatrix( m_prop->get() );
00097     }
00098 
00099     WGECallbackTraits< ParentType >::traverse( this, handled, nv );
00100 }
00101 
00102 #endif  // WGEPROPERTYTRANSFORMATIONCALLBACK_H
00103 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends