Line data Source code
1 :
2 : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Cedric Stalder <cedric.stalder@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include "observer.h"
20 :
21 : #include "config.h"
22 : #include "global.h"
23 : #include "view.h"
24 :
25 : #include <co/dataIStream.h>
26 : #include <co/dataOStream.h>
27 :
28 : namespace eq
29 : {
30 : namespace server
31 : {
32 :
33 : typedef fabric::Observer< Config, Observer > Super;
34 :
35 430 : Observer::Observer( Config* parent )
36 : : Super( parent )
37 430 : , _state( STATE_ACTIVE )
38 : {
39 430 : _updateEyes();
40 430 : }
41 :
42 856 : Observer::~Observer()
43 : {
44 856 : }
45 :
46 20 : void Observer::setDirty( const uint64_t bits )
47 : {
48 20 : Super::setDirty( bits );
49 28 : for( ViewsCIter i = _views.begin(); i != _views.end(); ++i )
50 8 : (*i)->setDirty( View::DIRTY_OBSERVER );
51 20 : }
52 :
53 0 : void Observer::deserialize( co::DataIStream& is, const uint64_t dirtyBits )
54 : {
55 0 : Super::deserialize( is, dirtyBits );
56 :
57 0 : if( dirtyBits & ( DIRTY_EYE_POSITION | DIRTY_HEAD ))
58 0 : _updateEyes();
59 0 : if( dirtyBits & DIRTY_FOCUS ||
60 0 : ( (dirtyBits & DIRTY_HEAD) && getFocusMode() != FOCUSMODE_FIXED ))
61 : {
62 0 : _updateViews();
63 : }
64 0 : if( dirtyBits & DIRTY_HEAD )
65 0 : _inverseHeadMatrix = getHeadMatrix().inverse();
66 0 : }
67 :
68 4 : ServerPtr Observer::getServer()
69 : {
70 4 : Config* config = getConfig();
71 4 : LBASSERT( config );
72 4 : return ( config ? config->getServer() : 0 );
73 : }
74 :
75 698 : void Observer::addView( View* view )
76 : {
77 698 : LBASSERT( lunchbox::find( _views, view ) == _views.end( ));
78 698 : _views.push_back( view );
79 698 : }
80 :
81 0 : void Observer::removeView( View* view )
82 : {
83 0 : ViewsIter i = lunchbox::find( _views, view );
84 0 : LBASSERT( i != _views.end( ));
85 0 : if( i != _views.end( ))
86 0 : _views.erase( i );
87 0 : }
88 :
89 2 : void Observer::init()
90 : {
91 2 : _updateEyes();
92 2 : _updateViews();
93 2 : _inverseHeadMatrix = getHeadMatrix().inverse();
94 2 : }
95 :
96 432 : void Observer::_updateEyes()
97 : {
98 432 : const Matrix4f& head = getHeadMatrix();
99 1728 : for( size_t i = 0; i < NUM_EYES; ++i )
100 1296 : _eyeWorld[ i ] = head * getEyePosition( Eye( 1 << i ));
101 :
102 432 : LBVERB << "Eye position: " << _eyeWorld[ fabric::EYE_CYCLOP_BIT ]
103 432 : << std::endl;
104 432 : }
105 :
106 2 : void Observer::_updateViews()
107 : {
108 4 : for( ViewsIter i = _views.begin(); i != _views.end(); ++i )
109 2 : (*i)->updateFrusta();
110 2 : }
111 :
112 0 : void Observer::postDelete()
113 : {
114 0 : _state = STATE_DELETE;
115 0 : getConfig()->postNeedsFinish();
116 0 : }
117 :
118 : }
119 : }
120 : #include "../fabric/observer.ipp"
121 : template class eq::fabric::Observer< eq::server::Config, eq::server::Observer >;
122 : /** @cond IGNORE */
123 : template std::ostream& eq::fabric::operator << ( std::ostream&,
124 84 : const eq::fabric::Observer< eq::server::Config, eq::server::Observer >& );
125 : /** @endcond */
|