Equalizer  1.6.1
eqPly/frameData.cpp
1 
2 /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2011, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "frameData.h"
31 
32 namespace eqPly
33 {
34 
35 FrameData::FrameData()
36  : _rotation( eq::Matrix4f::ZERO )
37  , _modelRotation( eq::Matrix4f::ZERO )
38  , _position( eq::Vector3f::ZERO )
39  , _renderMode( mesh::RENDER_MODE_DISPLAY_LIST )
40  , _colorMode( COLOR_MODEL )
41  , _quality( 1.0f )
42  , _ortho( false )
43  , _statistics( false )
44  , _help( false )
45  , _wireframe( false )
46  , _pilotMode( false )
47  , _idle( false )
48  , _compression( true )
49 {
50  reset();
51 }
52 
53 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits )
54 {
55  co::Serializable::serialize( os, dirtyBits );
56  if( dirtyBits & DIRTY_CAMERA )
57  os << _position << _rotation << _modelRotation;
58  if( dirtyBits & DIRTY_FLAGS )
59  os << _modelID << _renderMode << _colorMode << _quality << _ortho
60  << _statistics << _help << _wireframe << _pilotMode << _idle
61  << _compression;
62  if( dirtyBits & DIRTY_VIEW )
63  os << _currentViewID;
64  if( dirtyBits & DIRTY_MESSAGE )
65  os << _message;
66 }
67 
68 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits )
69 {
70  co::Serializable::deserialize( is, dirtyBits );
71  if( dirtyBits & DIRTY_CAMERA )
72  is >> _position >> _rotation >> _modelRotation;
73  if( dirtyBits & DIRTY_FLAGS )
74  is >> _modelID >> _renderMode >> _colorMode >> _quality >> _ortho
75  >> _statistics >> _help >> _wireframe >> _pilotMode >> _idle
76  >> _compression;
77  if( dirtyBits & DIRTY_VIEW )
78  is >> _currentViewID;
79  if( dirtyBits & DIRTY_MESSAGE )
80  is >> _message;
81 }
82 
83 void FrameData::setModelID( const eq::uint128_t& id )
84 {
85  if( _modelID == id )
86  return;
87 
88  _modelID = id;
89  setDirty( DIRTY_FLAGS );
90 }
91 
92 void FrameData::setColorMode( const ColorMode mode )
93 {
94  _colorMode = mode;
95  setDirty( DIRTY_FLAGS );
96 }
97 
98 void FrameData::setRenderMode( const mesh::RenderMode mode )
99 {
100  _renderMode = mode;
101  setDirty( DIRTY_FLAGS );
102 }
103 
104 void FrameData::setIdle( const bool idle )
105 {
106  if( _idle == idle )
107  return;
108 
109  _idle = idle;
110  setDirty( DIRTY_FLAGS );
111 }
112 
113 void FrameData::toggleOrtho()
114 {
115  _ortho = !_ortho;
116  setDirty( DIRTY_FLAGS );
117 }
118 
119 void FrameData::toggleStatistics()
120 {
121  _statistics = !_statistics;
122  setDirty( DIRTY_FLAGS );
123 }
124 
125 void FrameData::toggleHelp()
126 {
127  _help = !_help;
128  setDirty( DIRTY_FLAGS );
129 }
130 
131 void FrameData::toggleWireframe()
132 {
133  _wireframe = !_wireframe;
134  setDirty( DIRTY_FLAGS );
135 }
136 
137 void FrameData::toggleColorMode()
138 {
139  _colorMode = static_cast< ColorMode >(( _colorMode + 1) % COLOR_ALL );
140  setDirty( DIRTY_FLAGS );
141 }
142 
143 void FrameData::adjustQuality( const float delta )
144 {
145  _quality += delta;
146  _quality = LB_MAX( _quality, 0.1f );
147  _quality = LB_MIN( _quality, 1.0f );
148  setDirty( DIRTY_FLAGS );
149  LBINFO << "Set non-idle image quality to " << _quality << std::endl;
150 }
151 
152 void FrameData::togglePilotMode()
153 {
154  _pilotMode = !_pilotMode;
155  setDirty( DIRTY_FLAGS );
156 }
157 
158 void FrameData::toggleRenderMode()
159 {
160  _renderMode = static_cast< mesh::RenderMode >(
161  ( _renderMode + 1) % mesh::RENDER_MODE_ALL );
162 
163  LBINFO << "Switched to " << _renderMode << std::endl;
164  setDirty( DIRTY_FLAGS );
165 }
166 
167 void FrameData::toggleCompression()
168 {
169  _compression = !_compression;
170  setDirty( DIRTY_FLAGS );
171 }
172 
173 void FrameData::spinCamera( const float x, const float y )
174 {
175  if( x == 0.f && y == 0.f )
176  return;
177 
178  _rotation.pre_rotate_x( x );
179  _rotation.pre_rotate_y( y );
180  setDirty( DIRTY_CAMERA );
181 }
182 
183 void FrameData::spinModel( const float x, const float y, const float z )
184 {
185  if( x == 0.f && y == 0.f && z == 0.f )
186  return;
187 
188  _modelRotation.pre_rotate_x( x );
189  _modelRotation.pre_rotate_y( y );
190  _modelRotation.pre_rotate_z( z );
191  setDirty( DIRTY_CAMERA );
192 }
193 
194 void FrameData::moveCamera( const float x, const float y, const float z )
195 {
196  if( _pilotMode )
197  {
198  eq::Matrix4f matInverse;
199  compute_inverse( _rotation, matInverse );
200  eq::Vector4f shift = matInverse * eq::Vector4f( x, y, z, 1 );
201 
202  _position += shift;
203  }
204  else
205  {
206  _position.x() += x;
207  _position.y() += y;
208  _position.z() += z;
209  }
210 
211  setDirty( DIRTY_CAMERA );
212 }
213 
214 void FrameData::setCameraPosition( const eq::Vector3f& position )
215 {
216  _position = position;
217  setDirty( DIRTY_CAMERA );
218 }
219 
220 void FrameData::setRotation( const eq::Vector3f& rotation )
221 {
222  _rotation = eq::Matrix4f::IDENTITY;
223  _rotation.rotate_x( rotation.x() );
224  _rotation.rotate_y( rotation.y() );
225  _rotation.rotate_z( rotation.z() );
226  setDirty( DIRTY_CAMERA );
227 }
228 
229 void FrameData::setModelRotation( const eq::Vector3f& rotation )
230 {
231  _modelRotation = eq::Matrix4f::IDENTITY;
232  _modelRotation.rotate_x( rotation.x() );
233  _modelRotation.rotate_y( rotation.y() );
234  _modelRotation.rotate_z( rotation.z() );
235  setDirty( DIRTY_CAMERA );
236 }
237 
238 void FrameData::reset()
239 {
240  eq::Matrix4f model = eq::Matrix4f::IDENTITY;
241  model.rotate_x( static_cast<float>( -M_PI_2 ));
242  model.rotate_y( static_cast<float>( -M_PI_2 ));
243 
244  if( _position == eq::Vector3f( 0.f, 0.f, -2.f ) &&
245  _rotation == eq::Matrix4f::IDENTITY && _modelRotation == model )
246  {
247  _position.z() = 0.f;
248  }
249  else
250  {
251  _position = eq::Vector3f::ZERO;
252  _position.z() = -2.f;
253  _rotation = eq::Matrix4f::IDENTITY;
254  _modelRotation = model;
255  }
256  setDirty( DIRTY_CAMERA );
257 }
258 
259 void FrameData::setCurrentViewID( const eq::uint128_t& id )
260 {
261  _currentViewID = id;
262  setDirty( DIRTY_VIEW );
263 }
264 
265 void FrameData::setMessage( const std::string& message )
266 {
267  if( _message == message )
268  return;
269 
270  _message = message;
271  setDirty( DIRTY_MESSAGE );
272 }
273 
274 }
Render using the colors defined in the ply file.
Definition: eqPly.h:78
vmml::vector< 3, float > Vector3f
A three-component float vector.
Definition: vmmlib.h:46
vmml::matrix< 4, 4, float > Matrix4f
A 4x4 float matrix.
Definition: vmmlib.h:39
ColorMode
Definition: eqPly.h:76