OMKMKMHumano.cpp

Go to the documentation of this file.
00001 #include "OMKMKMHumano.h"
00002 #include "OMKTransform.h"
00003 #include "OMKAddVisualObjectPrm.h"
00004 #include "OMKVisBase.h"
00005 #include "OMKParametersAccessor.inl"
00006 #include "OMKAddAnimatorPrm.h"
00007 #include "OMKConversion.h"
00008 #include "OMKGroundService.h"
00009 #include "OBTServiceManager.h"
00010 
00011 using namespace OMK ;
00012 using namespace OMK::Type ;
00013 using namespace OMK::Vis ;
00014 
00015 //-------------------------------------------------------------------------
00016 REGISTER_OBJECT_FACTORY( OMK::MKMHumano, "MKMHumano" ) ;
00017 //-----------------------------------------------------------------------------
00018 
00019 MKMHumano::MKMHumano( Controller& ctrl, const ObjectDescriptor& objectDescriptor )
00020 : MovingHumano( ctrl, objectDescriptor ),
00021   _treehMesh(),
00022   _avatarMaster(),
00023   _controlMesh()
00024 { 
00025 }
00026 
00027 //-----------------------------------------------------------------------------
00028 
00029 MKMHumano::~MKMHumano() 
00030 {
00031 }
00032 //-----------------------------------------------------------------------------
00033 
00034 void MKMHumano::finish() 
00035 {
00036   _avatarMaster.close() ;
00037 }
00038 //-----------------------------------------------------------------------------
00039 void MKMHumano::computeParameters() 
00040 {
00041   if( !_initDone )
00042   {
00043     bool ok = true ;
00044 
00045     // Retrieve parameters
00046     const ConfigurationParameterDescriptor* node = getConfigurationParameters() ;
00047     ok = ok && ( node != 0 ) ;
00048 
00049     if( !_position.get().isUniformScale() ) OMERROR( "Scale must be uniform" ) ;
00050     std::string name = getName().getString() ; 
00051     ParametersAccessor::get( node, "Name", name ) ;
00052 
00053     std::string meshFile ;
00054     ok = ok && ParametersAccessor::get( node, "Mesh", meshFile, this ) ;
00055 
00056     std::string nodeAssociationFile ;
00057     ok = ok && ParametersAccessor::get( node, "NodeAssociation", nodeAssociationFile, this ) ;
00058 
00059     mkSystem::COgreAvatarMeshMaster::ESoftAxis axis = mkSystem::COgreAvatarMeshMaster::EAxis_Default ;
00060     std::map< std::string, mkSystem::COgreAvatarMeshMaster::ESoftAxis > softAxisMapping ;
00061     softAxisMapping[ "Default"      ] = mkSystem::COgreAvatarMeshMaster::EAxis_Default      ;
00062     softAxisMapping[ "UserDefined"  ] = mkSystem::COgreAvatarMeshMaster::EAxis_UserDefined  ;
00063     softAxisMapping[ "BipedeMax"    ] = mkSystem::COgreAvatarMeshMaster::EAxis_BipedeMax    ;
00064     softAxisMapping[ "BipedeQuidam" ] = mkSystem::COgreAvatarMeshMaster::EAxis_BipedeQuidam ;
00065 
00066     ParametersAccessor::get( node, "Axis", axis,  softAxisMapping ) ;
00067 
00068     bool useShadows = true ;
00069     ParametersAccessor::get( node, "UseShadows", useShadows ) ;
00070     
00071     bool footPrint = true ;
00072     ParametersAccessor::get( node, "FootPrint", footPrint ) ;
00073 
00074     float heightCorrection = footPrint ? 0.0f : -1.0f ;
00075     ParametersAccessor::get( node, "HeightCorrection", heightCorrection ) ;
00076 
00077     float footPrintResistance = 0.5f ;
00078     ParametersAccessor::get( node, "FootPrintResistance", footPrintResistance ) ;
00079 
00080     bool stackBlending = false ; // true = stack, false = dynamic, default dynamic
00081     std::map< std::string, bool > blendingMapping ;
00082     blendingMapping[ "Stack"   ] = true  ;
00083     blendingMapping[ "Dynamic" ] = false ;
00084     ParametersAccessor::get( node, "StackBlending", stackBlending, blendingMapping ) ;
00085 
00086     if( ok )
00087     { // All parameters are ok
00088       // Initialisation
00089       _treehMesh.init() ;
00090       _initialisationSequence = _avatarMaster.init( _treehMesh, meshFile,
00091                           name, true,
00092                           nodeAssociationFile,
00093                           useShadows, axis, 1.0f/_position.get().getScale().X(),
00094                           0.0f ) ;
00095       _controlMesh.init( _treehMesh ) ;
00096       // Configuration
00097       _controlMesh.setPosition( -_position.get().getTranslate().X(), _position.get().getTranslate().Z(), _position.get().getTranslate().Y() ) ;
00098       _controlMesh.enableFootprint( footPrint ) ;
00099       _controlMesh.setHeightCorrection( heightCorrection ) ;
00100       _controlMesh.setFootprintResistance( footPrintResistance ) ;
00101       _controlMesh.enableConstraints( false ) ;
00102 
00103       GroundService* groundService = OBT::getService< GroundService >( 'Grnd' ) ;
00104       if( groundService )
00105       {
00106         _controlMesh.getControlFootprint().setGroundClass( &groundService->getGround() ) ;
00107       }
00108       if( stackBlending )
00109         _controlMesh.setStackBlending() ; 
00110       else 
00111         _controlMesh.setDynamicBlending() ;
00112       // Need at least one update
00113       _controlMesh.update( 1e-9f );
00114     }
00115     else
00116     {
00117       OMERROR( "Unable to initialise MKM" ) ;
00118     }
00119   }
00120   // Call the ancestor to send the intialisation data
00121   MovingHumano::computeParameters() ;
00122   // The avatar master is initialised => update the posture
00123   if( _avatarMaster.isInitialized() )
00124     {
00125     _controlMesh.update( 1.0f / getObjectDescriptor().getFrequency() );
00126     _controlMesh.getPosture().computeToRelative( _avatarMaster );
00127     HBT::PostureData* posture = _avatarMaster.computeAndGetPostureDatas() ;
00128     _posture.set( *posture );
00129     Transform pos( _position.get() ) ;
00130     pos.setTranslate( convert( posture->rootPos ) ) ;
00131     pos.setRotate( convert( posture->rootQuat ) ) ;
00132     _position.set( pos ) ; 
00133   }
00134 }

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007