00001 /************************************************************************/ 00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00003 /* 1993-00, thereinafter the Software */ 00004 /* */ 00005 /* The Software has been developped within the Siames Project. */ 00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00007 /* property rights */ 00008 /* */ 00009 /* The Software has been registered with the Agence pour la Protection */ 00010 /* des Programmes (APP) under registration number */ 00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00012 /* */ 00013 /* This file may be distributed under the terms of the Q Public License */ 00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00015 /* the file LICENSE.QPL included in the packaging of this file. */ 00016 /* */ 00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00018 /* Universite Rennes 1 for the software may use this file in */ 00019 /* acordance with that specific license */ 00020 /************************************************************************/ 00021 #include "OMKAwarenessAnimator.h" 00022 00023 #include "OMKOgreVis.h" 00024 #include "OMKOgreObject.h" 00025 #include "OgreMovableObject.h" 00026 #include "OMKParametersAccessor.inl" 00027 #include "OMKTracer.h" 00028 #include "OMKColor.h" 00029 #include "OMKEntityMaterialAction.h" 00030 00031 using namespace OMK ; 00032 using namespace OMK::Vis ; 00033 using namespace OMK::Type ; 00034 using std::string; 00035 using Ogre::SceneNode; 00036 using Ogre::MovableObject; 00037 using Ogre::Entity; 00038 00039 //========================================================================= 00040 // AwarenessAnimator 00041 //========================================================================= 00042 00043 //------------------------------------------------------------------------- 00044 // registration for both: string and bool 00045 //------------------------------------------------------------------------- 00046 REGISTER_TEMPLATE_ANIMATOR_FACTORY( AwarenessAnimator< OMK::Type::StringType >, "AwarenessAnimator" ) ; 00047 REGISTER_TEMPLATE_ANIMATOR_FACTORY( AwarenessAnimator< OMK::Type::BoolType >, "AwarenessBoolAnimator" ) ; 00048 00049 //------------------------------------------------------------------------- 00050 // constructor 00051 //------------------------------------------------------------------------- 00052 template< typename Type > 00053 AwarenessAnimator< Type >::AwarenessAnimator( VisualObject& visualObject, 00054 const Name& id, 00055 const ConfigurationParameterDescriptor& node ) 00056 : OgreAnimatorT< Type >( visualObject, id, node ), 00057 IUpdateMaterial(), 00058 _node( 0 ), 00059 _awareness( false ), 00060 _color( 1.0f, 1.0f, 0.0f, 0.6f )//Yellow 00061 { 00062 Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &this->getNode() ) ; 00063 OMASSERTM( sceneNode, "No scene node found !" ) ; 00064 OgreObject* ogreObject = dynamic_cast< OgreObject* >( &this->getVisualObject() ) ; 00065 OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ; 00066 _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ; 00067 00068 OMK::Type::Color colorTmp( _color.x, _color.y, _color.z, _color.w ) ; 00069 if ( ParametersAccessor::get( &node, "AwarenessColor", colorTmp ) ) 00070 { 00071 _color = Ogre::Vector4( colorTmp[0], colorTmp[1], colorTmp[2], colorTmp[3] ); 00072 } 00073 else 00074 { 00075 OMMESSAGE( "Default Yellow Parameters for the AwarenessColor" ); 00076 } 00077 } 00078 00079 //------------------------------------------------------------------------- 00080 // destructor 00081 //------------------------------------------------------------------------- 00082 template< typename Type > 00083 AwarenessAnimator< Type >::~AwarenessAnimator() 00084 { 00085 } 00086 00087 //------------------------------------------------------------------------- 00088 // doIt 00089 //------------------------------------------------------------------------- 00090 template< typename Type > 00091 void AwarenessAnimator< Type >::doIt( bool awareness ) 00092 { 00093 if( awareness != _awareness ) 00094 { 00095 _awareness = awareness ; 00096 if( _awareness ) 00097 { 00098 _node->createCopyAndUpdateWith( this ) ; 00099 } 00100 else 00101 { 00102 _node->undoFor( this, true ) ; 00103 } 00104 } 00105 } 00106 00107 //------------------------------------------------------------------------- 00108 // update 00109 //------------------------------------------------------------------------- 00110 template< typename Type > 00111 void AwarenessAnimator< Type >::update( NodeMaterial* node ) 00112 { 00113 OMASSERTM( _awareness, "The awareness should be set to true" ) ; 00114 node->doAction( MaterialSetAwareness( _color ) ) ; 00115 } 00116 00117 //------------------------------------------------------------------------- 00118 // getMaterialName 00119 //------------------------------------------------------------------------- 00120 template< typename Type > 00121 Ogre::String AwarenessAnimator< Type >::getMaterialName( const Ogre::String& name ) const 00122 { 00123 return getUniqueMaterialName(name + "_Awareness" + ( _awareness ? "1" : "0" )) ; 00124 } 00125 //------------------------------------------------------------------------- 00126 // Specific instanciations of selfProcessVis 00127 //------------------------------------------------------------------------- 00128 namespace OMK 00129 { 00130 namespace Vis 00131 { 00132 // selfProcessVis for string 00133 template<> 00134 void AwarenessAnimator< OMK::Type::StringType >::selfProcessVis( const OMK::Type::StringType& value ) 00135 { 00136 00137 OMTRACEID("OMK::AwarenessAnimator"," got " << value ); 00138 //ON/OFF now 00139 std::string str( value.getValue() ) ; 00140 std::transform( str.begin(), str.end(), str.begin(), toupper ) ; 00141 bool newAwareness = !_awareness ; 00142 if( str == "ON" ) 00143 { 00144 newAwareness = true ; 00145 } 00146 else if( str == "OFF" ) 00147 { 00148 newAwareness = false ; 00149 } 00150 doIt( newAwareness ) ; 00151 } 00152 // selfProcessVis for bool 00153 template<> 00154 void AwarenessAnimator< OMK::Type::BoolType >::selfProcessVis( const OMK::Type::BoolType& value ) 00155 { 00156 doIt( value.getValue() ) ; 00157 } 00158 } //namespace OMK 00159 } //namespace Vis 00160 //------------------------------------------------------------------------- 00161 00162 00163 //========================================================================= 00164 // AwarenessColorAnimator 00165 //========================================================================= 00166 00167 //------------------------------------------------------------------------- 00168 // registration in factory 00169 //------------------------------------------------------------------------- 00170 REGISTER_ANIMATOR_FACTORY( AwarenessColorAnimator, "AwarenessColorAnimator" ) ; 00171 00172 //------------------------------------------------------------------------- 00173 // constructor 00174 //------------------------------------------------------------------------- 00175 AwarenessColorAnimator::AwarenessColorAnimator( VisualObject& visualObject, 00176 const Name& id, 00177 const ConfigurationParameterDescriptor& node ) 00178 : OgreAnimatorT< OMK::Type::ColorType >( visualObject, id, node ), 00179 IUpdateMaterial(), 00180 _node( 0 ), 00181 _awareness( false ), 00182 _color( 1.0f, 1.0f, 0.0f, 0.6f )//default Yellow 00183 { 00184 Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &getNode() ) ; 00185 OMASSERTM( sceneNode, "No scene node found !" ) ; 00186 OgreObject* ogreObject = dynamic_cast< OgreObject* >( &visualObject ) ; 00187 OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ; 00188 _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ; 00189 } 00190 00191 //------------------------------------------------------------------------- 00192 // destructor 00193 //------------------------------------------------------------------------- 00194 AwarenessColorAnimator::~AwarenessColorAnimator() 00195 { 00196 } 00197 00198 //------------------------------------------------------------------------- 00199 // selfProcessVis 00200 //------------------------------------------------------------------------- 00201 void AwarenessColorAnimator::selfProcessVis( const OMK::Type::ColorType& value ) 00202 { 00203 00204 OMTRACEID("OMK::AwarenessAnimator"," got " << value ); 00205 //ON/OFF now 00206 Ogre::Vector4 newColor( value.getValue()[0], value.getValue()[1], value.getValue()[2], value.getValue()[3] ); 00207 bool newAwareness = 0.0f != value.getValue()[3] ; 00208 if( ( _awareness != newAwareness ) || ( newColor != _color ) ) 00209 { 00210 _color = newColor ; 00211 if( _awareness && newAwareness ) 00212 { 00213 _node->undoFor( this, false ) ; 00214 } 00215 else if( !_awareness && newAwareness ) 00216 { 00217 _awareness = true ; 00218 _node->createCopyAndUpdateWith( this ) ; 00219 } 00220 else if( _awareness && !newAwareness ) 00221 { 00222 _awareness = false ; 00223 _node->undoFor( this, true ) ; 00224 } 00225 } 00226 } 00227 00228 //------------------------------------------------------------------------- 00229 // update 00230 //------------------------------------------------------------------------- 00231 void AwarenessColorAnimator::update( NodeMaterial* node ) 00232 { 00233 OMASSERTM( _awareness, "The awareness should be set to true" ) ; 00234 node->doAction( MaterialSetAwareness( _color ) ) ; 00235 } 00236 00237 //------------------------------------------------------------------------- 00238 // getMaterialName 00239 //------------------------------------------------------------------------- 00240 Ogre::String AwarenessColorAnimator::getMaterialName( const Ogre::String& name ) const 00241 { 00242 return getUniqueMaterialName( name + "_Awareness" + ( _awareness ? "1" : "0" ) ) ; 00243 }
Documentation generated on Mon Jun 9 11:45:55 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |