OMKMKMMotionTaskExtension.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 "OMKMKMMotionTaskExtension.h"
00022 #include "OMKAvatarVisualObject.h"
00023 #include "OMKParametersAccessor.inl"
00024 
00025 using namespace OMK ;
00026 using namespace OMK::Type ;
00027 
00028 REGISTER_EXTENSION_FACTORY( MKMMotionTaskExtension, "MotionTask" ) ;
00029 
00030 //-------------------------------------------------------------------------
00031 // constructor
00032 //-------------------------------------------------------------------------
00033 MKMMotionTaskExtension::MKMMotionTaskExtension( OMK::ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension ) 
00034 : ExtensionT< MKMHumano >( owner, id, registerExtension ),
00035   _activate( Name( id.getString() + "Activation" ), false ),
00036   _motionTask(),
00037   _initDone( false ),
00038   _motion(),
00039   _startAt( 0.0f ),
00040   _stopAt( -1.0f ),
00041   _startingDuration( 1.0f ),
00042   _stoppingDuration( 1.0f ),
00043   _weight( 1.0f ),
00044   _rank( 2.0f )
00045 {
00046   owner->addAttribute( _activate ) ;
00047 }
00048 
00049 //-------------------------------------------------------------------------
00050 // destructor
00051 //-------------------------------------------------------------------------
00052 MKMMotionTaskExtension::~MKMMotionTaskExtension()
00053 {
00054   if( _initDone )
00055   { // stop the task
00056     _motionTask.setStoppingDuration( 0.0f ) ;
00057     _motionTask.stop() ;
00058     // The destructor does the next step to unregister the task from the controller
00059   }
00060 }
00061 bool MKMMotionTaskExtension::loadExtensionParameters( const ConfigurationParameterDescriptor * node ) 
00062 {
00063   // Retrieve all the parameters
00064   bool ok = true ;
00065   ok = ok && ParametersAccessor::get( node, "Motion", _motion, getOwner() ) ;
00066   ParametersAccessor::get( node, "StartAt", _startAt ) ;
00067   ParametersAccessor::get( node, "StopAt", _stopAt ) ;
00068   ParametersAccessor::get( node, "StartingDuration", _startingDuration ) ;
00069   ParametersAccessor::get( node, "StoppingDuration", _stoppingDuration ) ;
00070   ParametersAccessor::get( node, "PriorityWeight", _weight ) ;
00071   ParametersAccessor::get( node, "PriorityRank", _rank ) ;
00072   _activate.loadParameters( node, "Activation" ) ;
00073 
00074   return ok ;
00075 }
00076 void MKMMotionTaskExtension::preComputeParameters()
00077 {
00078   // Waiting for the avatar master is intialised
00079   if( !_initDone && getOwner()->_avatarMaster.isInitialized() )
00080   {
00081     // Defines the motion task and starts it
00082     _initDone = true ;
00083     _motionTask.init( getOwner()->_controlMesh, _motion ) ;
00084     _motionTask.setStartAtAbsoluteTime( _startAt ) ;
00085     _motionTask.setStopAtAbsoluteTime( _stopAt ) ;
00086     _motionTask.setStartingDuration( _startingDuration ) ;
00087     _motionTask.setStoppingDuration( _stoppingDuration ) ;
00088     _motionTask.setPriorityWeight( _weight ) ;
00089     _motionTask.setPriorityRank( _rank ) ;
00090     _activate.get() ? _motionTask.start() : _motionTask.stop() ;
00091   }
00092   if( _initDone )
00093   {
00094     if( _motionTask.isActive() && !_activate.get() )
00095     {
00096       _motionTask.stop() ;
00097     }
00098     if( !_motionTask.isActive() && _activate.get() )
00099     {
00100       _motionTask.start() ;
00101     }
00102   }
00103 }

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007