OpenWalnut
1.4.0
|
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 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 * Default constructor. 00046 * 00047 * \param prop the property holding the matrix to use. 00048 */ 00049 explicit WGEPropertyTransformationCallback( WPropMatrix4X4 prop ); 00050 00051 /** 00052 * Destructor. 00053 */ 00054 virtual ~WGEPropertyTransformationCallback(); 00055 00056 /** 00057 * This operator gets called by OSG every update cycle. It calls the specified functor. 00058 * 00059 * \param handled the osg node, stateset or whatever 00060 * \param nv the node visitor 00061 */ 00062 virtual void operator()( typename WGECallbackTraits< ParentType >::HandledType* handled, osg::NodeVisitor* nv ); 00063 00064 protected: 00065 private: 00066 /** 00067 * The property controlling the callback 00068 */ 00069 WPropMatrix4X4 m_prop; 00070 }; 00071 00072 template < typename ParentType, typename TargetType > 00073 WGEPropertyTransformationCallback< ParentType, TargetType >::WGEPropertyTransformationCallback( WPropMatrix4X4 prop ): 00074 WGECallbackTraits< ParentType >::CallbackType(), 00075 m_prop( prop ) 00076 { 00077 // initialize members 00078 } 00079 00080 template < typename ParentType, typename TargetType > 00081 WGEPropertyTransformationCallback< ParentType, TargetType >::~WGEPropertyTransformationCallback() 00082 { 00083 // cleanup 00084 } 00085 00086 template < typename ParentType, typename TargetType > 00087 void WGEPropertyTransformationCallback< ParentType, TargetType >::operator()( typename WGECallbackTraits< ParentType >::HandledType* handled, 00088 osg::NodeVisitor* nv ) 00089 { 00090 TargetType* m = dynamic_cast< TargetType* >( handled ); 00091 if( m ) 00092 { 00093 m->setMatrix( m_prop->get() ); 00094 } 00095 00096 WGECallbackTraits< ParentType >::traverse( this, handled, nv ); 00097 } 00098 00099 #endif // WGEPROPERTYTRANSFORMATIONCALLBACK_H 00100