lib/client/observer.cpp

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "observer.h"
00019 
00020 #include "config.h"
00021 #include "observerVisitor.h"
00022 
00023 #include <eq/net/dataIStream.h>
00024 #include <eq/net/dataOStream.h>
00025 
00026 using namespace eq::base;
00027 
00028 namespace eq
00029 {
00030 
00031 Observer::Observer()
00032         : _config( 0 )
00033         , _eyeBase( 0.05f )
00034         , _headMatrix( Matrix4f::IDENTITY )
00035 {
00036 }
00037 
00038 Observer::~Observer()
00039 {
00040     EQASSERT( !_config );
00041 }
00042 
00043 void Observer::serialize( net::DataOStream& os, const uint64_t dirtyBits )
00044 {
00045     Object::serialize( os, dirtyBits );
00046 
00047     if( dirtyBits & DIRTY_EYE_BASE )
00048         os << _eyeBase;
00049     if( dirtyBits & DIRTY_HEAD )
00050         os << _headMatrix;
00051 }
00052 
00053 void Observer::deserialize( net::DataIStream& is, const uint64_t dirtyBits )
00054 {
00055     Object::deserialize( is, dirtyBits );
00056 
00057     if( dirtyBits & DIRTY_EYE_BASE )
00058         is >> _eyeBase;
00059     if( dirtyBits & DIRTY_HEAD )
00060         is >> _headMatrix;
00061 }
00062 
00063 VisitorResult Observer::accept( ObserverVisitor& visitor )
00064 {
00065     return visitor.visit( this );
00066 }
00067 
00068 void Observer::deregister()
00069 {
00070     EQASSERT( _config );
00071     EQASSERT( isMaster( ));
00072 
00073     _config->deregisterObject( this );
00074 }
00075 
00076 void Observer::setEyeBase( const float eyeBase )
00077 {
00078     _eyeBase = eyeBase;
00079     setDirty( DIRTY_EYE_BASE );
00080 }
00081 
00082 void Observer::setHeadMatrix( const Matrix4f& matrix )
00083 {
00084     _headMatrix = matrix;
00085     setDirty( DIRTY_HEAD );
00086 }
00087 
00088 std::ostream& operator << ( std::ostream& os, const Observer* observer )
00089 {
00090     if( !observer )
00091         return os;
00092     
00093     os << disableFlush << disableHeader << "observer" << std::endl;
00094     os << "{" << std::endl << indent; 
00095 
00096     const std::string& name = observer->getName();
00097     if( !name.empty( ))
00098         os << "name     \"" << name << "\"" << std::endl;
00099 
00100     const float eyeBase = observer->getEyeBase();
00101     if( eyeBase != 0.05f /* TODO use Config::FATTR_EYE_BASE */ )
00102         os << eyeBase << std::endl;
00103 
00104     os << exdent << "}" << std::endl << enableHeader << enableFlush;
00105     return os;
00106 }
00107 
00108 }
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8