Equalizer
1.4.1
|
00001 00002 /* Copyright (c) 2009-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, this 00008 * list of conditions and the following disclaimer. 00009 * - Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * - Neither the name of Eyescale Software GmbH nor the names of its 00013 * contributors may be used to endorse or promote products derived from this 00014 * software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00019 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00020 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00021 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00022 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00023 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00024 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00025 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00026 * POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00029 #include "frameData.h" 00030 00031 namespace eqPly 00032 { 00033 00034 FrameData::FrameData() 00035 : _rotation( eq::Matrix4f::ZERO ) 00036 , _modelRotation( eq::Matrix4f::ZERO ) 00037 , _position( eq::Vector3f::ZERO ) 00038 , _modelID( lunchbox::UUID::ZERO ) 00039 , _renderMode( mesh::RENDER_MODE_DISPLAY_LIST ) 00040 , _colorMode( COLOR_MODEL ) 00041 , _quality( 1.0f ) 00042 , _ortho( false ) 00043 , _statistics( false ) 00044 , _help( false ) 00045 , _wireframe( false ) 00046 , _pilotMode( false ) 00047 , _idle( false ) 00048 , _compression( true ) 00049 , _currentViewID( lunchbox::UUID::ZERO ) 00050 { 00051 reset(); 00052 } 00053 00054 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits ) 00055 { 00056 co::Serializable::serialize( os, dirtyBits ); 00057 if( dirtyBits & DIRTY_CAMERA ) 00058 os << _position << _rotation << _modelRotation; 00059 if( dirtyBits & DIRTY_FLAGS ) 00060 os << _modelID << _renderMode << _colorMode << _quality << _ortho 00061 << _statistics << _help << _wireframe << _pilotMode << _idle 00062 << _compression; 00063 if( dirtyBits & DIRTY_VIEW ) 00064 os << _currentViewID; 00065 if( dirtyBits & DIRTY_MESSAGE ) 00066 os << _message; 00067 } 00068 00069 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits ) 00070 { 00071 co::Serializable::deserialize( is, dirtyBits ); 00072 if( dirtyBits & DIRTY_CAMERA ) 00073 is >> _position >> _rotation >> _modelRotation; 00074 if( dirtyBits & DIRTY_FLAGS ) 00075 is >> _modelID >> _renderMode >> _colorMode >> _quality >> _ortho 00076 >> _statistics >> _help >> _wireframe >> _pilotMode >> _idle 00077 >> _compression; 00078 if( dirtyBits & DIRTY_VIEW ) 00079 is >> _currentViewID; 00080 if( dirtyBits & DIRTY_MESSAGE ) 00081 is >> _message; 00082 } 00083 00084 void FrameData::setModelID( const eq::uint128_t& id ) 00085 { 00086 if( _modelID == id ) 00087 return; 00088 00089 _modelID = id; 00090 setDirty( DIRTY_FLAGS ); 00091 } 00092 00093 void FrameData::setColorMode( const ColorMode mode ) 00094 { 00095 _colorMode = mode; 00096 setDirty( DIRTY_FLAGS ); 00097 } 00098 00099 void FrameData::setRenderMode( const mesh::RenderMode mode ) 00100 { 00101 _renderMode = mode; 00102 setDirty( DIRTY_FLAGS ); 00103 } 00104 00105 void FrameData::setIdle( const bool idle ) 00106 { 00107 if( _idle == idle ) 00108 return; 00109 00110 _idle = idle; 00111 setDirty( DIRTY_FLAGS ); 00112 } 00113 00114 void FrameData::toggleOrtho() 00115 { 00116 _ortho = !_ortho; 00117 setDirty( DIRTY_FLAGS ); 00118 } 00119 00120 void FrameData::toggleStatistics() 00121 { 00122 _statistics = !_statistics; 00123 setDirty( DIRTY_FLAGS ); 00124 } 00125 00126 void FrameData::toggleHelp() 00127 { 00128 _help = !_help; 00129 setDirty( DIRTY_FLAGS ); 00130 } 00131 00132 void FrameData::toggleWireframe() 00133 { 00134 _wireframe = !_wireframe; 00135 setDirty( DIRTY_FLAGS ); 00136 } 00137 00138 void FrameData::toggleColorMode() 00139 { 00140 _colorMode = static_cast< ColorMode >(( _colorMode + 1) % COLOR_ALL ); 00141 setDirty( DIRTY_FLAGS ); 00142 } 00143 00144 void FrameData::adjustQuality( const float delta ) 00145 { 00146 _quality += delta; 00147 _quality = LB_MAX( _quality, 0.1f ); 00148 _quality = LB_MIN( _quality, 1.0f ); 00149 setDirty( DIRTY_FLAGS ); 00150 LBINFO << "Set non-idle image quality to " << _quality << std::endl; 00151 } 00152 00153 void FrameData::togglePilotMode() 00154 { 00155 _pilotMode = !_pilotMode; 00156 setDirty( DIRTY_FLAGS ); 00157 } 00158 00159 void FrameData::toggleRenderMode() 00160 { 00161 _renderMode = static_cast< mesh::RenderMode >( 00162 ( _renderMode + 1) % mesh::RENDER_MODE_ALL ); 00163 00164 LBINFO << "Switched to " << _renderMode << std::endl; 00165 setDirty( DIRTY_FLAGS ); 00166 } 00167 00168 void FrameData::toggleCompression() 00169 { 00170 _compression = !_compression; 00171 setDirty( DIRTY_FLAGS ); 00172 } 00173 00174 void FrameData::spinCamera( const float x, const float y ) 00175 { 00176 if( x == 0.f && y == 0.f ) 00177 return; 00178 00179 _rotation.pre_rotate_x( x ); 00180 _rotation.pre_rotate_y( y ); 00181 setDirty( DIRTY_CAMERA ); 00182 } 00183 00184 void FrameData::spinModel( const float x, const float y, const float z ) 00185 { 00186 if( x == 0.f && y == 0.f && z == 0.f ) 00187 return; 00188 00189 _modelRotation.pre_rotate_x( x ); 00190 _modelRotation.pre_rotate_y( y ); 00191 _modelRotation.pre_rotate_z( z ); 00192 setDirty( DIRTY_CAMERA ); 00193 } 00194 00195 void FrameData::moveCamera( const float x, const float y, const float z ) 00196 { 00197 if( _pilotMode ) 00198 { 00199 eq::Matrix4f matInverse; 00200 compute_inverse( _rotation, matInverse ); 00201 eq::Vector4f shift = matInverse * eq::Vector4f( x, y, z, 1 ); 00202 00203 _position += shift; 00204 } 00205 else 00206 { 00207 _position.x() += x; 00208 _position.y() += y; 00209 _position.z() += z; 00210 } 00211 00212 setDirty( DIRTY_CAMERA ); 00213 } 00214 00215 void FrameData::setCameraPosition( const eq::Vector3f& position ) 00216 { 00217 _position = position; 00218 setDirty( DIRTY_CAMERA ); 00219 } 00220 00221 void FrameData::setRotation( const eq::Vector3f& rotation ) 00222 { 00223 _rotation = eq::Matrix4f::IDENTITY; 00224 _rotation.rotate_x( rotation.x() ); 00225 _rotation.rotate_y( rotation.y() ); 00226 _rotation.rotate_z( rotation.z() ); 00227 setDirty( DIRTY_CAMERA ); 00228 } 00229 00230 void FrameData::setModelRotation( const eq::Vector3f& rotation ) 00231 { 00232 _modelRotation = eq::Matrix4f::IDENTITY; 00233 _modelRotation.rotate_x( rotation.x() ); 00234 _modelRotation.rotate_y( rotation.y() ); 00235 _modelRotation.rotate_z( rotation.z() ); 00236 setDirty( DIRTY_CAMERA ); 00237 } 00238 00239 void FrameData::reset() 00240 { 00241 eq::Matrix4f model = eq::Matrix4f::IDENTITY; 00242 model.rotate_x( static_cast<float>( -M_PI_2 )); 00243 model.rotate_y( static_cast<float>( -M_PI_2 )); 00244 00245 if( _position == eq::Vector3f( 0.f, 0.f, -2.f ) && 00246 _rotation == eq::Matrix4f::IDENTITY && _modelRotation == model ) 00247 { 00248 _position.z() = 0.f; 00249 } 00250 else 00251 { 00252 _position = eq::Vector3f::ZERO; 00253 _position.z() = -2.f; 00254 _rotation = eq::Matrix4f::IDENTITY; 00255 _modelRotation = model; 00256 } 00257 setDirty( DIRTY_CAMERA ); 00258 } 00259 00260 void FrameData::setCurrentViewID( const eq::uint128_t& id ) 00261 { 00262 _currentViewID = id; 00263 setDirty( DIRTY_VIEW ); 00264 } 00265 00266 void FrameData::setMessage( const std::string& message ) 00267 { 00268 if( _message == message ) 00269 return; 00270 00271 _message = message; 00272 setDirty( DIRTY_MESSAGE ); 00273 } 00274 00275 } 00276