server/observer.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "observer.h"
00019
00020 #include "config.h"
00021 #include "global.h"
00022 #include "paths.h"
00023
00024 #include <eq/net/dataIStream.h>
00025 #include <eq/net/dataOStream.h>
00026
00027 using namespace eq::base;
00028
00029 namespace eq
00030 {
00031 namespace server
00032 {
00033
00034 Observer::Observer()
00035 : _config( 0 )
00036 , _inverseHeadMatrix( Matrix4f::IDENTITY )
00037 {
00038 #ifdef EQ_USE_DEPRECATED
00039 setEyeBase(Global::instance()->getConfigFAttribute(Config::FATTR_EYE_BASE));
00040 #endif
00041 _updateEyes();
00042 }
00043
00044 Observer::Observer( const Observer& from, Config* config )
00045 : eq::Observer( from )
00046 , _config( 0 )
00047 , _inverseHeadMatrix( from._inverseHeadMatrix )
00048 {
00049 config->addObserver( this );
00050 EQASSERT( _config );
00051 _updateEyes();
00052 }
00053
00054 Observer::~Observer()
00055 {
00056 }
00057
00058 void Observer::getInstanceData( net::DataOStream& os )
00059 {
00060
00061
00062
00063
00064 const uint64_t dirty = DIRTY_CUSTOM - 1;
00065 os << dirty;
00066 serialize( os, dirty );
00067 }
00068
00069 void Observer::deserialize( net::DataIStream& is, const uint64_t dirtyBits )
00070 {
00071 eq::Observer::deserialize( is, dirtyBits );
00072
00073 if( dirtyBits & ( DIRTY_EYE_BASE | DIRTY_HEAD ))
00074 _updateEyes();
00075 if( dirtyBits & DIRTY_HEAD )
00076 getHeadMatrix().inverse( _inverseHeadMatrix );
00077 }
00078
00079 ObserverPath Observer::getPath() const
00080 {
00081 EQASSERT( _config );
00082
00083 const ObserverVector& observers = _config->getObservers();
00084 ObserverVector::const_iterator i = std::find( observers.begin(),
00085 observers.end(), this );
00086 EQASSERT( i != observers.end( ));
00087
00088 ObserverPath path;
00089 path.observerIndex = std::distance( observers.begin(), i );
00090 return path;
00091 }
00092
00093 void Observer::unmap()
00094 {
00095 net::Session* session = getSession();
00096 EQASSERT( session );
00097 EQASSERT( getID() != EQ_ID_INVALID );
00098
00099 session->unmapObject( this );
00100 }
00101
00102 void Observer::init()
00103 {
00104 _updateEyes();
00105 getHeadMatrix().inverse( _inverseHeadMatrix );
00106 }
00107
00108 void Observer::_updateEyes()
00109 {
00110 const float eyeBase_2 = .5f * getEyeBase();
00111 const Matrix4f& head = getHeadMatrix();
00112
00113
00114
00115
00116 _eyes[eq::EYE_CYCLOP].x() = head.at( 0, 3 );
00117 _eyes[eq::EYE_CYCLOP].y() = head.at( 1, 3 );
00118 _eyes[eq::EYE_CYCLOP].z() = head.at( 2, 3 );
00119 _eyes[eq::EYE_CYCLOP] /= head.at( 3, 3 );
00120
00121 _eyes[eq::EYE_LEFT].x() = ( -eyeBase_2 * head.at( 0, 0 ) + head.at( 0, 3 ));
00122 _eyes[eq::EYE_LEFT].y() = ( -eyeBase_2 * head.at( 1, 0 ) + head.at( 1, 3 ));
00123 _eyes[eq::EYE_LEFT].z() = ( -eyeBase_2 * head.at( 2, 0 ) + head.at( 2, 3 ));
00124 _eyes[eq::EYE_LEFT] /= ( -eyeBase_2 * head.at( 3, 0 ) + head.at( 3, 3 ));
00125
00126 _eyes[eq::EYE_RIGHT].x() = ( eyeBase_2 * head.at( 0, 0 ) + head.at( 0, 3 ));
00127 _eyes[eq::EYE_RIGHT].y() = ( eyeBase_2 * head.at( 1, 0 ) + head.at( 1, 3 ));
00128 _eyes[eq::EYE_RIGHT].z() = ( eyeBase_2 * head.at( 2, 0 ) + head.at( 2, 3 ));
00129 _eyes[eq::EYE_RIGHT] /= ( eyeBase_2 * head.at( 3, 0 ) + head.at( 3, 3 ));
00130
00131 EQVERB << "Eye position: " << _eyes[ eq:: EYE_CYCLOP ] << std::endl;
00132 }
00133
00134
00135 }
00136 }