OpenWalnut  1.5.0dev
WGEPropertyTransformationCallback.h
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 #ifndef WGEPROPERTYTRANSFORMATIONCALLBACK_H
26 #define WGEPROPERTYTRANSFORMATIONCALLBACK_H
27 
28 #include <osg/Node>
29 #include <osg/TexMat>
30 #include <osg/StateAttribute>
31 #include <osg/MatrixTransform>
32 
33 #include "WGECallbackTraits.h"
34 #include "../../common/WProperties.h"
35 
36 
37 /**
38  * TODO(ebaum): write.
39  */
40 template < typename ParentType = osg::Node, typename TargetType = osg::MatrixTransform >
41 class WGEPropertyTransformationCallback: public WGECallbackTraits< ParentType >::CallbackType
42 {
43 public:
44  /**
45  * Default constructor.
46  *
47  * \param prop the property holding the matrix to use.
48  */
49  explicit WGEPropertyTransformationCallback( WPropMatrix4X4 prop );
50 
51  /**
52  * Destructor.
53  */
55 
56  /**
57  * This operator gets called by OSG every update cycle. It calls the specified functor.
58  *
59  * \param handled the osg node, stateset or whatever
60  * \param nv the node visitor
61  */
62  virtual void operator()( typename WGECallbackTraits< ParentType >::HandledType* handled, osg::NodeVisitor* nv );
63 
64 protected:
65 private:
66  /**
67  * The property controlling the callback
68  */
69  WPropMatrix4X4 m_prop;
70 };
71 
72 template < typename ParentType, typename TargetType >
74  WGECallbackTraits< ParentType >::CallbackType(),
75  m_prop( prop )
76 {
77  // initialize members
78 }
79 
80 template < typename ParentType, typename TargetType >
82 {
83  // cleanup
84 }
85 
86 template < typename ParentType, typename TargetType >
88  osg::NodeVisitor* nv )
89 {
90  TargetType* m = dynamic_cast< TargetType* >( handled );
91  if( m )
92  {
93  m->setMatrix( m_prop->get() );
94  }
95 
96  WGECallbackTraits< ParentType >::traverse( this, handled, nv );
97 }
98 
99 #endif // WGEPROPERTYTRANSFORMATIONCALLBACK_H
100 
This class is needed as OSG does not define a uniform callback type.
static void traverse(CallbackType *inst, HandledType *handled, osg::NodeVisitor *nv)
Call traversal method if existing for the specific callback type.
Type HandledType
The type of the element used as parameter in the () operator.
WPropMatrix4X4 m_prop
The property controlling the callback.
virtual void operator()(typename WGECallbackTraits< ParentType >::HandledType *handled, osg::NodeVisitor *nv)
This operator gets called by OSG every update cycle.
WGEPropertyTransformationCallback(WPropMatrix4X4 prop)
Default constructor.