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 "OMKVisualObject.h" 00022 #include "OMKAnimator.h" 00023 #include "Wm4Matrix3.h" 00024 #include "OMKParametersAccessor.inl" 00025 00026 using namespace OMK ; 00027 using namespace OMK::Vis ; 00028 using namespace Wm4 ; 00029 00030 std::string OMK::Vis::debugMsg( const OMK::Vis::VisualObject* visObj ) 00031 { 00032 std::ostringstream txt ; 00033 txt << "visual object \"" << (visObj ? visObj->getId().getString() : std::string( "null" ) ) 00034 << "\"" ; 00035 return txt.str() ; 00036 } 00037 00038 00039 //------------------------------------------------------------------------- 00040 // constructor 00041 //------------------------------------------------------------------------- 00042 VisualObject::VisualObject( VisBase& vis, const Name& id, const ConfigurationParameterDescriptor* node ) : 00043 _vis( vis ), 00044 _id( id ) 00045 { 00046 OMTRACEID( OMK_DEBUG_VIS_EXEC, "Construction of " << debugMsg( this ) ); 00047 readConfigurationParameters( node ) ; 00048 } 00049 00050 //------------------------------------------------------------------------- 00051 // destructor 00052 //------------------------------------------------------------------------- 00053 VisualObject::~VisualObject() 00054 { 00055 OMTRACEID( OMK_DEBUG_VIS_EXEC, "Destruction of " << debugMsg( this ) ); 00056 for( AnimatorsMap::iterator a( _animators.begin() ) ; 00057 a != _animators.end() ; 00058 a++ ) 00059 { 00060 delete a->second ; 00061 } 00062 _animators.clear(); 00063 } 00064 00065 //------------------------------------------------------------------------- 00066 // update 00067 //------------------------------------------------------------------------- 00068 void VisualObject::update() 00069 { 00070 // Call each animator 00071 for( AnimatorsMap::iterator a( _animators.begin() ) ; 00072 a != _animators.end() ; 00073 ++a ) 00074 { 00075 a->second->processVis() ; 00076 } 00077 00078 visualise() ; 00079 } 00080 00081 //------------------------------------------------------------------------- 00082 // readConfigurationParameters 00083 //------------------------------------------------------------------------- 00084 void VisualObject::readConfigurationParameters( const ConfigurationParameterDescriptor* node ) 00085 { 00086 // Retrieve the transform parameters 00087 // First try to load a transform 00088 00089 if( !ParametersAccessor::get( node, "Position", _transform ) ) 00090 { 00091 std::vector< float > v ; 00092 if( ParametersAccessor::get( node, "Translate", v ) 00093 && v.size() == 3 ) 00094 { 00095 _transform.setTranslate( Vector3f( v[0], v[1], v[2] ) ) ; 00096 } 00097 else 00098 { 00099 OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl 00100 << ">>> :-| no translate provided, will use 0 0 0 by default" ) ; 00101 } 00102 v.clear() ; 00103 if( ParametersAccessor::get( node, "Rotate", v ) 00104 && v.size() == 3 ) 00105 { 00106 Matrix3f matrix ; 00107 matrix.FromEulerAnglesXYZ( v[0], v[1], v[2] ) ; 00108 _transform.setRotate( matrix ) ; 00109 } 00110 else 00111 { 00112 OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl 00113 << ">>> :-| no rotate provided, will use 0 0 0 by default" ) ; 00114 } 00115 v.clear() ; 00116 float scale = 1.0f ; 00117 if( ParametersAccessor::get( node, "Scale", v ) 00118 && v.size() == 3 ) 00119 { 00120 _transform.setScale( Vector3f( v[0], v[1], v[2] ) ) ; 00121 } 00122 if( ParametersAccessor::get( node, "Scale", scale ) ) 00123 { 00124 _transform.setUniformScale( scale ) ; 00125 } 00126 else 00127 { 00128 OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl 00129 << ">>> :-| no scale provided, will use 0 0 0 by default" ) ; 00130 } 00131 } 00132 00133 } 00134 00135 //------------------------------------------------------------------------- 00136 // getAnimator 00137 //------------------------------------------------------------------------- 00138 Animator* VisualObject::getAnimator( const Name& id ) const 00139 { 00140 AnimatorsMap::const_iterator i = _animators.find( id ) ; 00141 return i != _animators.end() ? i->second : 0 ; 00142 } 00143 00144 //------------------------------------------------------------------------- 00145 // addAnimator 00146 //------------------------------------------------------------------------- 00147 void VisualObject::addAnimator( OMK::Vis::Animator* animator ) 00148 { 00149 _animators[ animator->getId() ] = animator ; 00150 } 00151 00152 //------------------------------------------------------------------------- 00153 // deleteAnimator 00154 //------------------------------------------------------------------------- 00155 void VisualObject::deleteAnimator( const Name& id ) 00156 { 00157 AnimatorsMap::iterator i = _animators.find( id ) ; 00158 OMASSERTM( i != _animators.end(), "The animator named \"" << id << "\" is not present !" ) ; 00159 // delete the animator 00160 delete i->second ; 00161 _animators.erase( i ) ; 00162 OMTRACEID( OMK_DEBUG_VIS_EXEC, ">>> :-) The animator named \"" << id << "\" is deleted" ) ; 00163 }
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |