HBT::AvatarMesh Class Reference

Class to add a skeleton in an Ogre visualisation. More...

#include <HBTAvatarMesh.h>

Collaboration diagram for HBT::AvatarMesh:

Collaboration graph
[legend]
List of all members.

Data

Ogre::SceneNode * _pObjectSceneNode
Ogre::SceneNode * _meshNode
Ogre::Entity * _entity
bool _hidden
bool _initialised
unsigned short _nbBones
Ogre::Quaternion _sceneNodeInverseQuat

Constructor et Destructor

 AvatarMesh ()
 Default constructor.
virtual ~AvatarMesh ()
 Destructor.
bool init (Ogre::SceneManager *ogreSceneManager, const InitialisationSequence *initSequence)
 Initialisation de la posture et du mesh 3D à partir d'un squelette.
void close ()
 Close the object.
bool isInitialised () const
 Returns the intialise state of the object.
static AvatarMeshcreate ()
 Instance creator.

Public Member Functions

Display
void update (const PostureData &postureData)
 Update the state of the avatar.
virtual void show (const bool show=true)
 Shows (or hides) the object.
virtual void hide (const bool hide=true)
 Hides (or shows) the object.
virtual bool isHidden () const
 The hide state.
Accesseurs
void * getObjectSceneNode () const
 Returns the CLine3d node.
Position, orientation and scale of the object
virtual Ogre::Vector3 getPos () const
 Get the position.
virtual Ogre::Quaternion getRot () const
 Get the orientation.
virtual Ogre::Vector3 getScl () const
 Get the scale.
virtual void setPos (const Ogre::Vector3 &vec)
 Set the position.
virtual void setRot (const Ogre::Quaternion &q)
 Set the orientation.
virtual void setScl (const Ogre::Vector3 &scl)
 Set the scale.
Bones methods.
unsigned short getNbBones () const
 The number of bones.
int getBoneID (const std::string &boneName) const
 Gets the id of a bone from its name.
void setBoneOrientation (const int boneID, const Ogre::Quaternion &quat, const bool inWorldFrame=false)
 Set the orientation of a bone.
void setBoneOrientation (const std::string &boneName, const Ogre::Quaternion &quat, const bool inWorldFrame=false)
 Set the orientation of a bone.
Ogre accessor
Ogre::SceneNode * getOgreSceneNode ()
 The Ogre scene node of the object.

Detailed Description

Class to add a skeleton in an Ogre visualisation.

This class add a skeleton in the Ogre and update it. The initialisation is made with init, and the update is made with update. Each of the methods uses a specific data struture (InitialisationSequence and PostureData) which containts appropriate data.

Definition at line 21 of file HBTAvatarMesh.h.


Constructor & Destructor Documentation

AvatarMesh::AvatarMesh (  ) 

Default constructor.

Definition at line 10 of file HBTAvatarMesh.cpp.

00011 : _pObjectSceneNode( NULL ), 
00012   _meshNode( NULL ), 
00013   _entity( NULL ), 
00014   _hidden( false ),
00015   _initialised( false )
00016 {
00017 }

AvatarMesh::~AvatarMesh (  )  [virtual]

Destructor.

Definition at line 33 of file HBTAvatarMesh.cpp.

References close().

00034 {
00035   close() ;
00036 }


Member Function Documentation

bool AvatarMesh::init ( Ogre::SceneManager *  ogreSceneManager,
const InitialisationSequence initSequence 
)

Initialisation de la posture et du mesh 3D à partir d'un squelette.

Parameters:
ogreSceneManager Reference to the Ogre scene manager
initSequence The initialisation data of the skeleton
Returns:
true if everything is ok

Definition at line 39 of file HBTAvatarMesh.cpp.

References _entity, _initialised, _meshNode, _nbBones, _pObjectSceneNode, _sceneNodeInverseQuat, HBT::InitialisationSequence::boneNumber, close(), HBT::InitialisationSequence::generalScale, HBT::InitialisationSequence::humanName, HBT::InitialisationSequence::meshFile, HBT::InitialisationSequence::postureQuat, HBT::InitialisationSequence::rootPos, HBT::InitialisationSequence::rootQuat, setPos(), setRot(), setScl(), and HBT::InitialisationSequence::useShadows.

00041 {
00042   OBT_ASSERT( ogreSceneManager && "The Scene Manager is invalid" ) ;
00043   OBT_ASSERT( initSequence->boneNumber.size() == initSequence->postureQuat.size() 
00044            && "The number of bones and quaternion don't match" ) ;
00045 
00046   if( _initialised ) close() ;
00047 
00048   //verification que le nom de l'entitée n'existe pas déjà, si oui on ajout un suffixe
00049   std::string changedName( initSequence->humanName ) ;
00050   std::string sceneMeshName( initSequence->humanName ) ;
00051   
00052   for( unsigned int counter = 0u ;ogreSceneManager->hasSceneNode( changedName ); counter++ )
00053   {
00054     ostringstream buffer ; 
00055     buffer << initSequence->humanName << "_#_" << counter ;
00056     changedName = buffer.str() ;
00057   }
00058 
00059   //on attache l'objet à la scene
00060   _entity = ogreSceneManager->createEntity( changedName, initSequence->meshFile ) ;
00061 
00062   if(initSequence->useShadows)
00063   {
00064     _entity->setCastShadows( true ) ;
00065     _entity->getMesh()->buildEdgeList() ;
00066   }
00067 
00068   //ajout des noeuds de scène
00069   _pObjectSceneNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode( changedName ) ;
00070   _meshNode = _pObjectSceneNode->createChildSceneNode(string("mesh") + changedName) ;
00071   _meshNode->attachObject( _entity ) ;
00072   _meshNode->setInheritOrientation( true ) ;
00073   _meshNode->setPosition( Ogre::Vector3::ZERO ) ;  //position 0 par rapport au noeud root MKM: c'est le noeud root MKM qui prendra en charge toutes les orientations et translations
00074   _meshNode->setOrientation( Ogre::Quaternion::IDENTITY ) ;
00075   _meshNode->setScale( Ogre::Vector3::UNIT_SCALE ) ;
00076   
00077   //contrôle manuel des bones
00078   _nbBones = _entity->getSkeleton()->getNumBones() ;
00079   for( unsigned int i = 0u ; i < _nbBones; i++ )
00080   {
00081     Bone * bone = _entity->getSkeleton()->getBone( i ) ;
00082     bone->setManuallyControlled( true ) ;
00083   }
00084 
00085   //initialisation de la posture et des bones
00086   setScl( initSequence->generalScale ) ;  // global scale
00087   setRot( initSequence->rootQuat ) ;      // root orientation
00088   setPos( initSequence->rootPos ) ;       // root position
00089 
00090   for( unsigned int pos = 0; pos < initSequence->boneNumber.size() ; pos++ )
00091   {
00092     Bone * bone =_entity->getSkeleton()->getBone( initSequence->boneNumber.at( pos ) ) ;
00093     bone->setInheritOrientation( false ) ;
00094 
00095     //il faut multiplier par l'inverse du world orientation de l'entitée car le setOrientation du bones se fait dans le repère de l'entitée en mode inheritOrientation(false)
00096     bone->setOrientation( _sceneNodeInverseQuat * initSequence->postureQuat.at( pos ) ) ;
00097     bone->_update( true, true ) ;
00098   }
00099 
00100   _initialised = true;
00101   return true;
00102 }

static AvatarMesh* HBT::AvatarMesh::create (  )  [inline, static]

Instance creator.

Returns:
A new class instance

Definition at line 40 of file HBTAvatarMesh.h.

00041   {
00042     return new AvatarMesh();
00043   }

void AvatarMesh::close (  ) 

Close the object.

Cut the link with the skeleton.

Definition at line 20 of file HBTAvatarMesh.cpp.

References _initialised, _meshNode, _pObjectSceneNode, and hide().

Referenced by init(), and ~AvatarMesh().

00021 {
00022   if( _initialised )
00023   {
00024     hide( true ) ;
00025     _pObjectSceneNode->removeChild( _meshNode->getName() ) ;
00026     _pObjectSceneNode->getParentSceneNode()->removeChild( _pObjectSceneNode->getName() ) ;
00027 
00028     _initialised = false ;
00029   }
00030 }

bool HBT::AvatarMesh::isInitialised (  )  const [inline]

Returns the intialise state of the object.

Returns:
true if the object is initialised.

Definition at line 52 of file HBTAvatarMesh.h.

00053   {
00054     return _initialised;
00055   }

void AvatarMesh::update ( const PostureData postureData  ) 

Update the state of the avatar.

Parameters:
postureData The new posture.

Definition at line 116 of file HBTAvatarMesh.cpp.

References _initialised, HBT::PostureData::generalScale, HBT::PostureData::postureQuat, HBT::PostureData::quatModified, HBT::PostureData::rootPos, HBT::PostureData::rootQuat, setBoneOrientation(), setPos(), setRot(), and setScl().

Referenced by OMK::Vis::AvatarVisualObject::updatePosture().

00117 {
00118   if( _initialised )
00119   {
00120     setScl(postureData.generalScale) ;  //scale global
00121     setRot(postureData.rootQuat) ;  //orientation du root
00122     setPos(postureData.rootPos+Vector3(0,0,0) ) ;    //position du root
00123 
00124     //on applique l'orientation pour les bones:
00125     for( unsigned int cBone = 0; 
00126          cBone < postureData.quatModified.size() ; cBone ++ )
00127     {
00128       if( postureData.quatModified.at(cBone) )
00129         setBoneOrientation(cBone, postureData.postureQuat.at( cBone ), true ) ;
00130     }
00131   }//fin if initialized
00132 }

virtual void HBT::AvatarMesh::show ( const bool  show = true  )  [inline, virtual]

Shows (or hides) the object.

Parameters:
show true (default) shows the avatar, false hides it.
See also:
hide.

Definition at line 67 of file HBTAvatarMesh.h.

00068   {
00069     hide( !show );
00070   }

void AvatarMesh::hide ( const bool  hide = true  )  [virtual]

Hides (or shows) the object.

Parameters:
show true (default) hides the avatar, false shows it.
See also:
show.

Definition at line 105 of file HBTAvatarMesh.cpp.

References _entity, _hidden, and _initialised.

Referenced by close().

00106 {
00107   if( _initialised && _hidden != hide)
00108   {
00109     _hidden = hide;
00110     _entity->setVisible( !_hidden ) ;
00111   }
00112 }

virtual bool HBT::AvatarMesh::isHidden (  )  const [inline, virtual]

The hide state.

Returns:
true if the object is hidden.

Definition at line 79 of file HBTAvatarMesh.h.

00080   {
00081     return _hidden;
00082   }

void* HBT::AvatarMesh::getObjectSceneNode (  )  const [inline]

Returns the CLine3d node.

Returns:
the object CLine3d node.

Definition at line 89 of file HBTAvatarMesh.h.

00090   {
00091     return _pObjectSceneNode;
00092   }

Ogre::Vector3 AvatarMesh::getPos (  )  const [virtual]

Get the position.

Returns:
The object position in the Ogre referential.

Definition at line 135 of file HBTAvatarMesh.cpp.

References _entity, _initialised, and _meshNode.

00136 {
00137   Ogre::Vector3 v( Ogre::Vector3::ZERO ) ;
00138   if( _initialised ) 
00139   {
00140     v = _entity->getSkeleton()->getRootBone()->getWorldPosition() ;
00141     Matrix4 sceneNodeTransform ;
00142     _meshNode->getWorldTransforms( &sceneNodeTransform ) ;
00143     v = sceneNodeTransform * v;
00144   }
00145 
00146   return v;
00147 }

Ogre::Quaternion AvatarMesh::getRot (  )  const [virtual]

Get the orientation.

Parameters:
The orientation of the object in the Ogre referential.

Definition at line 150 of file HBTAvatarMesh.cpp.

References _initialised, and _pObjectSceneNode.

00151 {
00152   
00153   return _initialised ?
00154     _pObjectSceneNode->getWorldOrientation() :
00155     Ogre::Quaternion::IDENTITY ;
00156 }

Ogre::Vector3 AvatarMesh::getScl (  )  const [virtual]

Get the scale.

Returns:
The object scale.

Definition at line 159 of file HBTAvatarMesh.cpp.

References _initialised, and _pObjectSceneNode.

00160 {
00161    return  _initialised ? 
00162      _pObjectSceneNode->_getDerivedScale() : 
00163      Ogre::Vector3::UNIT_SCALE ;
00164 }

void AvatarMesh::setPos ( const Ogre::Vector3 &  vec  )  [virtual]

Set the position.

Parameters:
vec The new object position in the Ogre referential.

Definition at line 167 of file HBTAvatarMesh.cpp.

References _entity, and _pObjectSceneNode.

Referenced by init(), and update().

00168 {
00169   assert(_pObjectSceneNode) ;
00170 
00171   Ogre::Vector3 newPos( pos ) ;
00172   Ogre::Vector3 rootBonePos( _entity->getSkeleton()->getRootBone()->getWorldPosition() ) ;
00173   Ogre::Vector3 sceneNodeScale( _pObjectSceneNode->getScale() ) ;
00174   Quaternion sceneNodeOri( _pObjectSceneNode->getWorldOrientation() ) ;
00175 
00176   newPos = newPos - sceneNodeOri * ( rootBonePos * sceneNodeScale ) ;
00177   _pObjectSceneNode->setPosition( newPos ) ;
00178   _pObjectSceneNode->_update( true, true ) ;
00179 }

void AvatarMesh::setRot ( const Ogre::Quaternion &  q  )  [virtual]

Set the orientation.

Parameters:
q The new object orientation in the Ogre referential.

Definition at line 182 of file HBTAvatarMesh.cpp.

References _meshNode, _pObjectSceneNode, and _sceneNodeInverseQuat.

Referenced by init(), and update().

00183 {
00184   OBT_ASSERT( _pObjectSceneNode ) ;
00185   _pObjectSceneNode->setOrientation( q ) ;
00186 
00187   _sceneNodeInverseQuat = _meshNode->getWorldOrientation().Inverse() ;
00188 }

void AvatarMesh::setScl ( const Ogre::Vector3 &  scl  )  [virtual]

Set the scale.

Parameters:
scl The new object scale.

Definition at line 191 of file HBTAvatarMesh.cpp.

References _pObjectSceneNode.

Referenced by init(), and update().

00192 {
00193   assert(_pObjectSceneNode) ;
00194   ( (SceneNode*)_pObjectSceneNode)->setScale(scl[0],scl[1],scl[2]) ;
00195 }

unsigned short AvatarMesh::getNbBones (  )  const

The number of bones.

Returns:
The number of bones of the object.

Definition at line 205 of file HBTAvatarMesh.cpp.

References _initialised, and _nbBones.

00206 {
00207   return _initialised ? _nbBones : 0u ;
00208 }

int AvatarMesh::getBoneID ( const std::string &  boneName  )  const

Gets the id of a bone from its name.

Parameters:
boneName bone's name.
Returns:
The bone's id.

Definition at line 198 of file HBTAvatarMesh.cpp.

References _entity, and _initialised.

00199 {
00200   return !_initialised ? 
00201     _entity->getSkeleton()->getBone( boneName )->getHandle() : -1 ;
00202 }

void AvatarMesh::setBoneOrientation ( const int  boneID,
const Ogre::Quaternion &  quat,
const bool  inWorldFrame = false 
)

Set the orientation of a bone.

Parameters:
boneID The bone's id.
The new orientation in the local referentiel.
inWorldFrame 

Definition at line 210 of file HBTAvatarMesh.cpp.

References _entity, _initialised, and _meshNode.

Referenced by update().

00213 {
00214   if( _initialised )
00215   {
00216     Ogre::Quaternion quat( q ) ;
00217     Bone * bone = _entity->getSkeleton()->getBone( boneID ) ;
00218 
00219     if( inWorldFrame )
00220     {
00221       //il faut multiplier par l'inverse du world orientation de l'entitée car il semblerais que le setOrientation du bones se fait dans le repère de l'entitée en mode inheritOrientation(false)
00222       quat = _meshNode->getWorldOrientation().Inverse() * quat;
00223     }
00224 
00225     bone->setOrientation( quat ) ;
00226 
00227     bone->_update( true, true ) ;
00228   }
00229 }

void HBT::AvatarMesh::setBoneOrientation ( const std::string &  boneName,
const Ogre::Quaternion &  quat,
const bool  inWorldFrame = false 
) [inline]

Set the orientation of a bone.

Definition at line 144 of file HBTAvatarMesh.h.

00147   {
00148     setBoneOrientation( getBoneID( boneName ), quat ) ;
00149   }

Ogre::SceneNode* HBT::AvatarMesh::getOgreSceneNode (  )  [inline]

The Ogre scene node of the object.

Returns:
The Ogre scene node.

Definition at line 156 of file HBTAvatarMesh.h.

00156 { return _pObjectSceneNode ; }


Member Data Documentation

Ogre::SceneNode* HBT::AvatarMesh::_pObjectSceneNode [protected]

Definition at line 162 of file HBTAvatarMesh.h.

Referenced by close(), getRot(), getScl(), init(), setPos(), setRot(), and setScl().

Ogre::SceneNode* HBT::AvatarMesh::_meshNode [protected]

Definition at line 163 of file HBTAvatarMesh.h.

Referenced by close(), getPos(), init(), setBoneOrientation(), and setRot().

Ogre::Entity* HBT::AvatarMesh::_entity [protected]

Definition at line 164 of file HBTAvatarMesh.h.

Referenced by getBoneID(), getPos(), hide(), init(), setBoneOrientation(), and setPos().

bool HBT::AvatarMesh::_hidden [private]

Definition at line 167 of file HBTAvatarMesh.h.

Referenced by hide().

bool HBT::AvatarMesh::_initialised [private]

Definition at line 168 of file HBTAvatarMesh.h.

Referenced by close(), getBoneID(), getNbBones(), getPos(), getRot(), getScl(), hide(), init(), setBoneOrientation(), and update().

unsigned short HBT::AvatarMesh::_nbBones [private]

Definition at line 169 of file HBTAvatarMesh.h.

Referenced by getNbBones(), and init().

Ogre::Quaternion HBT::AvatarMesh::_sceneNodeInverseQuat [private]

Definition at line 170 of file HBTAvatarMesh.h.

Referenced by init(), and setRot().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:00 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007