OMKEntityMaterialAction.cpp

Go to the documentation of this file.
00001 #include "OMKTracer.h"
00002 #include "OMKPickUDO.h"
00003 #include "OMKEntityMaterialAction.h" 
00004 using namespace Ogre;
00005 using namespace OMK::Vis ;
00006 
00007 //=========================================================================== 
00008 // MaterialPassAction
00009 //=========================================================================== 
00010 void IMaterialPassAction::subEntityAction( SubEntityMaterial* subEntity ) const
00011 {
00012   if( !subEntity->getMaterial().isNull() )
00013   {
00014     unsigned short i = 0 ;
00015     for( Material::TechniqueIterator techniqueIt = subEntity->getMaterial()->getTechniqueIterator() ;
00016          techniqueIt.hasMoreElements() ;
00017          techniqueIt.moveNext(), ++i ) 
00018     {
00019       Technique* techniqueScr = subEntity->getMaterial()->getTechnique( i ) ;
00020       unsigned short j = 0;
00021       for( Technique::PassIterator passIt = techniqueIt.peekNext()->getPassIterator ();
00022            passIt.hasMoreElements() ;
00023            passIt.moveNext(), ++j ) 
00024       {
00025         passAction( subEntity, passIt.peekNext(), techniqueScr->getPass( j ) ) ;
00026       }
00027     }
00028   }
00029 }
00030 //=========================================================================== 
00031 
00032 
00033 //=========================================================================== 
00034 // MaterialSetMaterialName
00035 //=========================================================================== 
00036 void MaterialSetMaterialName::subEntityAction( SubEntityMaterial* subEntity ) const
00037 {
00038   subEntity->activateMaterial( _materialName ) ;
00039 }
00040 //=========================================================================== 
00041 
00042 
00043 //=========================================================================== 
00044 // MaterialSetTransparency
00045 //=========================================================================== 
00046 MaterialSetTransparency::MaterialSetTransparency( Ogre::Real transparency ) 
00047 : IMaterialPassAction(), 
00048 _transparency( transparency < 0.0f ? 0.0 : ( 1.0f < transparency ? 1.0f : transparency ) ) 
00049 {
00050 }
00051 //--------------------------------------------------------------------------- 
00052 bool MaterialSetTransparency::entityAction( EntityMaterial* entity ) const
00053 {
00054   entity->getOgreEntity()->setVisible( 1.0f != _transparency ) ;
00055   return true ;
00056 }
00057 //--------------------------------------------------------------------------- 
00058 void MaterialSetTransparency::passAction( SubEntityMaterial* subEntity, 
00059                                           Pass* passDest, Pass* passSrc ) const 
00060 {
00061   ColourValue ac = passSrc->getAmbient () ;
00062   ColourValue dc = passSrc->getDiffuse () ;
00063   ColourValue sc = passSrc->getSpecular() ;
00064 
00065   ac.a = _transparency ;
00066   dc.a = _transparency ;
00067   sc.a = _transparency ;
00068 
00069   passDest->setDiffuse ( dc );
00070   passDest->setAmbient ( ac );
00071   passDest->setSpecular( sc );
00072 }
00073 //=========================================================================== 
00074 
00075 
00076 //=========================================================================== 
00077 // MaterialSetAwareness
00078 //=========================================================================== 
00079 ColourValue MaterialSetAwareness::computeBlend( const ColourValue& currentColor ) const
00080 {
00081   return ColourValue( computeBlend( currentColor.r, _awarenessColor.x ), 
00082                       computeBlend( currentColor.g, _awarenessColor.y ), 
00083                       computeBlend( currentColor.b, _awarenessColor.z ), 
00084                       computeBlend( currentColor.a, 1.0f              ) ) ;
00085 }
00086 //--------------------------------------------------------------------------- 
00087 void MaterialSetAwareness::passAction( SubEntityMaterial* subEntity, 
00088                                        Pass* passDest, Pass* passSrc ) const 
00089 {
00090   passDest->setDiffuse ( computeBlend( passSrc->getAmbient () ) ) ;
00091   passDest->setAmbient ( computeBlend( passSrc->getDiffuse () ) ) ;
00092   passDest->setSpecular( computeBlend( passSrc->getSpecular() ) ) ;
00093   //force reload
00094   passDest->_load() ;
00095 }
00096 //=========================================================================== 
00097 
00098 
00099 //=========================================================================== 
00100 // MaterialSetSceneBlending
00101 //=========================================================================== 
00102 void MaterialSetSceneBlending::passAction( SubEntityMaterial* subEntity, 
00103                                            Pass* passDest, Pass* passSrc ) const 
00104 {
00105   passDest->setSceneBlending( _blendType );
00106 }
00107 //=========================================================================== 
00108 
00109 
00110 //=========================================================================== 
00111 // IsProgrammable
00112 //=========================================================================== 
00113 //TODO handle multi pass
00114 void IsProgrammable::subEntityAction( SubEntityMaterial* subEntity ) const
00115 {
00116   if( !_isProgrammable )
00117   {
00118     _isProgrammable = getFirstPassOfFirstTechnique( subEntity )->isProgrammable() ;
00119   }
00120 }
00121 //=========================================================================== 
00122 
00123 
00124 //=========================================================================== 
00125 // MaterialSetShader
00126 //=========================================================================== 
00127 void MaterialSetShader::subEntityAction( SubEntityMaterial* subEntity ) const
00128 {
00129   Pass * pass = getFirstPassOfFirstTechnique( subEntity ) ;
00130 
00131   pass->setLightingEnabled( _light );
00132 
00133   if ( "null" != _texture )
00134   {
00135      pass->createTextureUnitState( _texture ); 
00136      //TextureUnitState *texState = pass->createTextureUnitState( texture ) ; 
00137      //texState->setTextureScroll( 0.f, 0.f ) ;
00138      //texState->setColourOperation( Ogre::LBO_MODULATE ) ;  
00139 
00140      //texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
00141   }  
00142   if ( "null" != _fragment)
00143   { //fragment Program
00144     pass->setFragmentProgram( _fragment );
00145     //copy params passed 
00146     Ogre::GpuProgramParametersSharedPtr fragmentParams = pass->getFragmentProgramParameters() ;
00147     fragmentParams->copyConstantsFrom( *_fragmentPrm ) ;
00148   }
00149   if ( "null" != _vertex)
00150   { //vertex Program
00151     pass->setVertexProgram( _vertex );
00152     //copy params passed 
00153     Ogre::GpuProgramParametersSharedPtr vertexParams = pass->getVertexProgramParameters() ;
00154     vertexParams->copyConstantsFrom( *_vertexPrm ) ;
00155   } 
00156   pass->_load() ;
00157   
00158   OMTRACEID( "DEBUG_MAT", "Shader OK " 
00159           << " fragment " << _fragment 
00160           << " vertex " << _vertex );
00161 }
00162 
00163 //=========================================================================== 
00164 
00165 //===========================================================================
00166 // MaterialAddPickUDO
00167 //===========================================================================
00168 bool MaterialAddPickUDO::entityAction( EntityMaterial* entity ) const 
00169 { 
00170   OMTRACEID( "UDO", "Adding PickUDO " << entity->getOgreEntity()->getName() ) ;
00171   entity->getOgreEntity()->setUserObject( new PickUDO() );
00172   return false ;
00173 }
00174 //===========================================================================
00175 
00176 //===========================================================================
00177 // MaterialRemovePickUDO
00178 //===========================================================================
00179 bool MaterialRemovePickUDO::entityAction( EntityMaterial* entity ) const
00180 { 
00181   // look for a PickUDO
00182   PickUDO* udo = dynamic_cast< PickUDO* >( entity->getOgreEntity()->getUserObject() ) ;
00183   // it is a PickUDO => delete it
00184   delete udo;
00185   OMTRACEID( "UDO", "removing PickUDO" );
00186   return false ;
00187 }
00188 //===========================================================================
00189 

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007