#include <HBTPlayer.h>
Collaboration diagram for HBT::Player:
Public Member Functions | |
Player () | |
Default constructor. | |
Player (const std::string &fileName) | |
Constructor. | |
virtual | ~Player () |
Destructor. | |
void | open (const std::string &fileName) |
Open the file. | |
operator bool () const | |
Boolean operator. | |
Player & | read (InitialisationSequence &intialisationSequence) |
The initialisation sequence reader. | |
Player & | read (unsigned int &date, PostureData &posture) |
The posture reader. | |
void | setLoop (bool loop=true) |
Set the behiavor at the end of the file. | |
Protected Member Functions | |
Readers | |
void | read (std::string &txt) |
Read a string. | |
void | read (bool &flag) |
Read a bool. | |
void | read (Ogre::Vector3 &vect) |
Read an Ogre::Vector3. | |
void | read (Ogre::Quaternion &quat) |
Read an Ogre::Quaternion. | |
template<typename T> | |
void | read (std::vector< T > &tab) |
Read a vector of T. | |
template<typename T> | |
void | read (T &val) |
Read a T. | |
Protected Attributes | |
bool | _initRead |
The flag to know if the initialisation sequence is read. | |
bool | _loop |
The flag to loop at the end of the file. | |
std::ifstream | _file |
The file where the data will be written. | |
PostureData | _lastPosture |
The last read posture. | |
unsigned int | _lastDate |
The last read date. |
The format is a binary file in three parts, see Recorder.
Example of use :
AvatarMesh avatar ; // Open the file Player player( filename ) ; // Do the initialisations of the avatar mesh InitialisationSequence initialisationSequence ; player.read( InitialisationSequence ) ; avatar.init( ogreSceneManager, &initialisationSequence ) ; avatar.show() ; for( ;; ) { // And for each step update the posture unsigned int date ; PostureData posture ; player.read( date, posture ) ; avatar.update( posture ) ; }
Definition at line 35 of file HBTPlayer.h.
Player::Player | ( | ) |
Player::Player | ( | const std::string & | fileName | ) |
Player::~Player | ( | ) | [virtual] |
Destructor.
Closes the file.
Definition at line 25 of file HBTPlayer.cpp.
References _file.
00026 { 00027 _file.close() ; 00028 }
void Player::open | ( | const std::string & | fileName | ) |
Open the file.
[in] | fileName,the | file where the data will be read. |
Definition at line 30 of file HBTPlayer.cpp.
References _file, and _initRead.
Referenced by OMK::HumanoPlayer::loadParameters(), and Player().
HBT::Player::operator bool | ( | ) | const [inline] |
Boolean operator.
Definition at line 55 of file HBTPlayer.h.
00055 { return _initRead ; }
Player & Player::read | ( | InitialisationSequence & | intialisationSequence | ) |
The initialisation sequence reader.
This reader must be called first, before any call to the posture reader.
Definition at line 89 of file HBTPlayer.cpp.
References _file, _initRead, HBT::InitialisationSequence::boneNumber, HBT::InitialisationSequence::generalScale, HBT::Recorder::HEADER, HBT::InitialisationSequence::humanName, HBT::InitialisationSequence::meshFile, HBT::InitialisationSequence::postureQuat, HBT::InitialisationSequence::rootPos, HBT::InitialisationSequence::rootQuat, and HBT::InitialisationSequence::useShadows.
Referenced by OMK::HumanoPlayer::computeParameters(), OMK::HumanoPlayer::loadParameters(), and read().
00090 { 00091 OBT_ASSERT( _file.is_open() && "The file is not opened" ) ; 00092 // Go to the beginning of the file 00093 _file.seekg( 0 ) ; 00094 00095 // Tag 00096 std::string header ; 00097 read( header ) ; 00098 size_t length = Recorder::HEADER.length() ; 00099 OBT_ASSERT( header.substr( 0, length ) == Recorder::HEADER && "Not the good header" ) ; 00100 // Version 00101 if( header.substr( length ) == "0" ) 00102 { 00103 read( initialisationSequence.meshFile ) ; 00104 read( initialisationSequence.humanName ) ; 00105 read( initialisationSequence.useShadows ) ; 00106 read( initialisationSequence.generalScale ) ; 00107 read( initialisationSequence.rootQuat ) ; 00108 read( initialisationSequence.rootPos ) ; 00109 read( initialisationSequence.boneNumber ) ; 00110 read( initialisationSequence.postureQuat ) ; 00111 } 00112 else 00113 { 00114 OBT_ASSERT( false && "not the good version" ) ; // version 00115 } 00116 00117 _initRead = true ; 00118 return *this ; 00119 }
Player & Player::read | ( | unsigned int & | date, | |
PostureData & | posture | |||
) |
The posture reader.
This reader must be called after the call to the initialisation sequence reader.
See setLoop to know the behavior at the end of the file.
Definition at line 121 of file HBTPlayer.cpp.
References _file, _initRead, _lastDate, _lastPosture, _loop, HBT::PostureData::generalScale, HBT::PostureData::postureQuat, HBT::PostureData::quatModified, read(), HBT::PostureData::rootPos, and HBT::PostureData::rootQuat.
00122 { 00123 OBT_ASSERT( _file.is_open() && "The file is not opened" ) ; 00124 OBT_ASSERT( _initRead && "You must read InitialisationSequence before reading the posture data" ) ; 00125 _file.peek() ; 00126 if( !_file.eof() ) 00127 { 00128 read( _lastDate ) ; 00129 read( _lastPosture.rootPos ) ; 00130 read( _lastPosture.rootQuat ) ; 00131 read( _lastPosture.generalScale ) ; 00132 read( _lastPosture.postureQuat ) ; 00133 read( _lastPosture.quatModified ) ; 00134 } 00135 else if( _loop ) 00136 { 00137 _file.clear() ; 00138 InitialisationSequence initialisationSequence ; 00139 read( initialisationSequence ) ; 00140 } 00141 date = _lastDate ; 00142 posture = _lastPosture ; 00143 return *this ; 00144 }
void HBT::Player::setLoop | ( | bool | loop = true |
) | [inline] |
Set the behiavor at the end of the file.
[in] | loop,the | flag. |
Definition at line 75 of file HBTPlayer.h.
Referenced by OMK::HumanoPlayer::computeParameters(), and OMK::HumanoPlayer::loadParameters().
00075 { _loop = loop ; }
void Player::read | ( | std::string & | txt | ) | [protected] |
Read a string.
Definition at line 36 of file HBTPlayer.cpp.
References _file.
00037 { 00038 size_t size ; 00039 _file.read( (char*)&size, sizeof(size) ) ; 00040 char* txtTmp = new char[ size ] ; 00041 _file.read( txtTmp, size ) ; 00042 txt = txtTmp ; 00043 delete[] txtTmp ; 00044 }
void Player::read | ( | bool & | flag | ) | [protected] |
Read a bool.
Definition at line 46 of file HBTPlayer.cpp.
References _file.
00047 { 00048 char tmp ; 00049 _file.read( &tmp, 1 ) ; 00050 flag = tmp == '1' ; 00051 }
void Player::read | ( | Ogre::Vector3 & | vect | ) | [protected] |
void Player::read | ( | Ogre::Quaternion & | quat | ) | [protected] |
Read an Ogre::Quaternion.
Definition at line 66 of file HBTPlayer.cpp.
References _file.
00067 { 00068 _file.read( (char*)&quat.w, sizeof( Ogre::Real ) ) ; 00069 _file.read( (char*)&quat.x, sizeof( Ogre::Real ) ) ; 00070 _file.read( (char*)&quat.y, sizeof( Ogre::Real ) ) ; 00071 _file.read( (char*)&quat.z, sizeof( Ogre::Real ) ) ; 00072 }
void Player::read | ( | std::vector< T > & | tab | ) | [protected] |
Read a vector of T.
Definition at line 75 of file HBTPlayer.cpp.
00076 { 00077 tab.clear() ; 00078 size_t size ; 00079 _file.read( (char*)&size, sizeof( size_t ) ) ; 00080 for( ; size != 0 ; size-- ) 00081 { 00082 T val ; 00083 read( val ) ; 00084 tab.push_back( val ) ; 00085 } 00086 }
void Player::read | ( | T & | val | ) | [protected] |
Read a T.
Definition at line 54 of file HBTPlayer.cpp.
References _file.
00055 { 00056 _file.read( (char*)&val, sizeof( T ) ) ; 00057 }
bool HBT::Player::_initRead [protected] |
bool HBT::Player::_loop [protected] |
The flag to loop at the end of the file.
See setLoop.
Definition at line 81 of file HBTPlayer.h.
Referenced by read().
std::ifstream HBT::Player::_file [protected] |
PostureData HBT::Player::_lastPosture [protected] |
The last read posture.
Used when the loop is set to false.
Definition at line 86 of file HBTPlayer.h.
Referenced by read().
unsigned int HBT::Player::_lastDate [protected] |
The last read date.
Used when the loop is set to false.
Definition at line 89 of file HBTPlayer.h.
Referenced by read().
Documentation generated on Mon Jun 9 11:46:00 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |