OMKTransparencyAnimator.cpp

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, 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 "OMKTransparencyAnimator.h"
00022 
00023 #include "OMKOgreVis.h"
00024 #include "OMKOgreObject.h"
00025 #include "OgreMovableObject.h"
00026 #include "OMKParametersAccessor.h"
00027 #include "OMKEntityMaterialAction.h"
00028 
00029 using namespace OMK ;
00030 using namespace OMK::Vis ;
00031 using namespace OMK::Type ;
00032 using std::string;
00033 using Ogre::SceneNode;
00034 using Ogre::MovableObject;
00035 using Ogre::Entity;
00036 
00037 
00038 //=========================================================================
00039 // TransparencyAnimAnimator
00040 //=========================================================================
00041 
00042 //-------------------------------------------------------------------------
00043 // registration in factory
00044 //-------------------------------------------------------------------------
00045 REGISTER_ANIMATOR_FACTORY( TransparencyAnimAnimator, "TransparencyAnimator" ) ;
00046 
00047 //-------------------------------------------------------------------------
00048 // constructor
00049 //-------------------------------------------------------------------------
00050 TransparencyAnimAnimator::TransparencyAnimAnimator( VisualObject& visualObject, 
00051     const Name& id, 
00052     const ConfigurationParameterDescriptor& node ) 
00053 : OgreAnimatorT< OMK::Type::StringType >( visualObject, id, node ),
00054   _transparency( 0.0f ),
00055   _node( 0 ) 
00056 {
00057 }
00058 
00059 //-------------------------------------------------------------------------
00060 // destructor
00061 //-------------------------------------------------------------------------
00062 TransparencyAnimAnimator::~TransparencyAnimAnimator()
00063 {
00064 }
00065 
00066 //-------------------------------------------------------------------------
00067 // selfProcessVis
00068 //-------------------------------------------------------------------------
00069 void TransparencyAnimAnimator::selfProcessVis( const OMK::Type::StringType& value ) 
00070 {
00071   if (!_node)
00072   {
00073     Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &getNode() ) ;
00074     OMASSERTM( sceneNode, "No scene node found !" ) ;
00075     OgreObject* ogreObject = dynamic_cast< OgreObject* >( &getVisualObject() ) ;
00076     OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ;
00077     _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ;
00078     _node->createCopyAndUpdateWith( this ) ;
00079   }
00080   _transparency -= 0.1f ;  
00081   if( _transparency < 0.0f  )
00082     _transparency = 1.0f ; 
00083   _node->undoFor( this, false ) ;
00084 }
00085 
00086 //-------------------------------------------------------------------------
00087 // update
00088 //-------------------------------------------------------------------------
00089 void TransparencyAnimAnimator::update( NodeMaterial* node ) 
00090 {
00091   node->doAction( MaterialSetSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ) ) ;
00092   node->doAction( MaterialSetTransparency( _transparency ) ) ;
00093 }
00094 
00095 //-------------------------------------------------------------------------
00096 // getMaterialName
00097 //-------------------------------------------------------------------------
00098 Ogre::String TransparencyAnimAnimator::getMaterialName( const Ogre::String& name ) const 
00099 { 
00100   return  getUniqueMaterialName( name + "_Transparency" ) ;
00101 }
00102 
00103 
00104 //=========================================================================
00105 // TransparencyBoolAnimator
00106 //=========================================================================
00107 
00108 //-------------------------------------------------------------------------
00109 // registration in factory
00110 //-------------------------------------------------------------------------
00111 REGISTER_ANIMATOR_FACTORY( TransparencyBoolAnimator, "TransparencyBoolAnimator" ) ;
00112 
00113 //-------------------------------------------------------------------------
00114 // constructor
00115 //-------------------------------------------------------------------------
00116 TransparencyBoolAnimator::TransparencyBoolAnimator( VisualObject& visualObject, 
00117     const Name& id, 
00118     const ConfigurationParameterDescriptor& nodeCfg ) 
00119 : OgreAnimatorT< OMK::Type::BoolType >( visualObject, id, nodeCfg ),
00120   _transparency( 0.5f ),
00121   _state( false ),
00122   _node( 0 ) 
00123 {
00124   ParametersAccessor::get( &nodeCfg, "Transparency", _transparency ) ;
00125 }
00126 
00127 //-------------------------------------------------------------------------
00128 // destructor
00129 //-------------------------------------------------------------------------
00130 TransparencyBoolAnimator::~TransparencyBoolAnimator()
00131 {
00132 }
00133 
00134 //-------------------------------------------------------------------------
00135 // selfProcessVis
00136 //-------------------------------------------------------------------------
00137 void TransparencyBoolAnimator::selfProcessVis( const OMK::Type::BoolType& value ) 
00138 {
00139   if (!_node)
00140   {
00141     Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &getNode() ) ;
00142     OMASSERTM( sceneNode, "No scene node found !" ) ;
00143     OgreObject* ogreObject = dynamic_cast< OgreObject* >( &getVisualObject() ) ;
00144     OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ;
00145     _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ;
00146   }
00147   if( _state != value.getValue() )
00148   {
00149     _state = value.getValue() ;
00150     if( _state )
00151     {
00152       _node->createCopyAndUpdateWith( this ) ;
00153     }
00154     else
00155     {
00156       _node->undoFor( this, true ) ;
00157     }
00158   }
00159 }
00160 
00161 //-------------------------------------------------------------------------
00162 // update
00163 //-------------------------------------------------------------------------
00164 void TransparencyBoolAnimator::update( NodeMaterial* node ) 
00165 {
00166   node->doAction( MaterialSetSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ) ) ;
00167   node->doAction( MaterialSetTransparency( _transparency ) ) ;
00168 }
00169 
00170 //-------------------------------------------------------------------------
00171 // getMaterialName
00172 //-------------------------------------------------------------------------
00173 Ogre::String TransparencyBoolAnimator::getMaterialName( const Ogre::String& name ) const 
00174 { 
00175   return  getUniqueMaterialName( name + "_Transparency" ) ;
00176 }
00177 
00178 //=========================================================================
00179 // TransparencyValueAnimator
00180 //=========================================================================
00181 
00182 //-------------------------------------------------------------------------
00183 // registration in factory
00184 //-------------------------------------------------------------------------
00185 REGISTER_ANIMATOR_FACTORY( TransparencyValueAnimator, "TransparencyValueAnimator" ) ;
00186 
00187 //-------------------------------------------------------------------------
00188 // constructor
00189 //-------------------------------------------------------------------------
00190 TransparencyValueAnimator::TransparencyValueAnimator( VisualObject& visualObject, 
00191     const Name& id, 
00192     const ConfigurationParameterDescriptor& node ) 
00193 : OgreAnimatorT< OMK::Type::FloatType >( visualObject, id, node ),
00194   _transparency( 1.0f ),
00195   _node( 0 ) 
00196 {
00197 }
00198 
00199 //-------------------------------------------------------------------------
00200 // destructor
00201 //-------------------------------------------------------------------------
00202 TransparencyValueAnimator::~TransparencyValueAnimator()
00203 {
00204 }
00205 
00206 //-------------------------------------------------------------------------
00207 // selfProcessVis
00208 //-------------------------------------------------------------------------
00209 void TransparencyValueAnimator::selfProcessVis( const OMK::Type::FloatType& value ) 
00210 {
00211   if (!_node)
00212   {
00213     Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &getNode() ) ;
00214     OMASSERTM( sceneNode, "No scene node found !" ) ;
00215     OgreObject* ogreObject = dynamic_cast< OgreObject* >( &getVisualObject() ) ;
00216     OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ;
00217     _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ;
00218   }
00219   if( _transparency != value.getValue() )
00220   {
00221     if( 1.0f ==_transparency )
00222     {
00223       _transparency = value.getValue() ;
00224       _node->createCopyAndUpdateWith( this ) ;
00225     }
00226     else if( 1.0f == value.getValue() )
00227     {
00228       _transparency = value.getValue() ;
00229       _node->undoFor( this, true ) ;
00230     }
00231     else
00232     {
00233       _transparency = value.getValue() ;
00234       _node->undoFor( this, false ) ;
00235     }
00236   }
00237 }
00238 
00239 //-------------------------------------------------------------------------
00240 // update
00241 //-------------------------------------------------------------------------
00242 void TransparencyValueAnimator::update( NodeMaterial* node ) 
00243 {
00244   node->doAction( MaterialSetSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ) ) ;
00245   node->doAction( MaterialSetTransparency( _transparency ) ) ;
00246 }
00247 
00248 //-------------------------------------------------------------------------
00249 // getMaterialName
00250 //-------------------------------------------------------------------------
00251 Ogre::String TransparencyValueAnimator::getMaterialName( const Ogre::String& name ) const 
00252 { 
00253   return  getUniqueMaterialName( name + "_Transparency" ) ;
00254 }

logo OpenMask

Documentation generated on Mon Jun 9 11:45:57 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007