Equalizer
1.2.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( co::base::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( co::base::UUID::ZERO ) 00050 { 00051 reset(); 00052 EQINFO << "New FrameData " << std::endl; 00053 } 00054 00055 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits ) 00056 { 00057 co::Serializable::serialize( os, dirtyBits ); 00058 if( dirtyBits & DIRTY_CAMERA ) 00059 os << _position << _rotation << _modelRotation; 00060 if( dirtyBits & DIRTY_FLAGS ) 00061 os << _modelID << _renderMode << _colorMode << _quality << _ortho 00062 << _statistics << _help << _wireframe << _pilotMode << _idle 00063 << _compression; 00064 if( dirtyBits & DIRTY_VIEW ) 00065 os << _currentViewID; 00066 if( dirtyBits & DIRTY_MESSAGE ) 00067 os << _message; 00068 } 00069 00070 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits ) 00071 { 00072 co::Serializable::deserialize( is, dirtyBits ); 00073 if( dirtyBits & DIRTY_CAMERA ) 00074 is >> _position >> _rotation >> _modelRotation; 00075 if( dirtyBits & DIRTY_FLAGS ) 00076 is >> _modelID >> _renderMode >> _colorMode >> _quality >> _ortho 00077 >> _statistics >> _help >> _wireframe >> _pilotMode >> _idle 00078 >> _compression; 00079 if( dirtyBits & DIRTY_VIEW ) 00080 is >> _currentViewID; 00081 if( dirtyBits & DIRTY_MESSAGE ) 00082 is >> _message; 00083 } 00084 00085 void FrameData::setModelID( const eq::uint128_t& id ) 00086 { 00087 if( _modelID == id ) 00088 return; 00089 00090 _modelID = id; 00091 setDirty( DIRTY_FLAGS ); 00092 } 00093 00094 void FrameData::setColorMode( const ColorMode mode ) 00095 { 00096 _colorMode = mode; 00097 setDirty( DIRTY_FLAGS ); 00098 } 00099 00100 void FrameData::setRenderMode( const mesh::RenderMode mode ) 00101 { 00102 _renderMode = mode; 00103 setDirty( DIRTY_FLAGS ); 00104 } 00105 00106 void FrameData::setIdle( const bool idle ) 00107 { 00108 if( _idle == idle ) 00109 return; 00110 00111 _idle = idle; 00112 setDirty( DIRTY_FLAGS ); 00113 } 00114 00115 void FrameData::toggleOrtho() 00116 { 00117 _ortho = !_ortho; 00118 setDirty( DIRTY_FLAGS ); 00119 } 00120 00121 void FrameData::toggleStatistics() 00122 { 00123 _statistics = !_statistics; 00124 setDirty( DIRTY_FLAGS ); 00125 } 00126 00127 void FrameData::toggleHelp() 00128 { 00129 _help = !_help; 00130 setDirty( DIRTY_FLAGS ); 00131 } 00132 00133 void FrameData::toggleWireframe() 00134 { 00135 _wireframe = !_wireframe; 00136 setDirty( DIRTY_FLAGS ); 00137 } 00138 00139 void FrameData::toggleColorMode() 00140 { 00141 _colorMode = static_cast< ColorMode >(( _colorMode + 1) % COLOR_ALL ); 00142 setDirty( DIRTY_FLAGS ); 00143 } 00144 00145 void FrameData::adjustQuality( const float delta ) 00146 { 00147 _quality += delta; 00148 _quality = EQ_MAX( _quality, 0.1f ); 00149 _quality = EQ_MIN( _quality, 1.0f ); 00150 setDirty( DIRTY_FLAGS ); 00151 EQINFO << "Set non-idle image quality to " << _quality << std::endl; 00152 } 00153 00154 void FrameData::togglePilotMode() 00155 { 00156 _pilotMode = !_pilotMode; 00157 setDirty( DIRTY_FLAGS ); 00158 } 00159 00160 void FrameData::toggleRenderMode() 00161 { 00162 _renderMode = static_cast< mesh::RenderMode >( 00163 ( _renderMode + 1) % mesh::RENDER_MODE_ALL ); 00164 00165 EQINFO << "Switched to " << _renderMode << std::endl; 00166 setDirty( DIRTY_FLAGS ); 00167 } 00168 00169 void FrameData::toggleCompression() 00170 { 00171 _compression = !_compression; 00172 setDirty( DIRTY_FLAGS ); 00173 } 00174 00175 void FrameData::spinCamera( const float x, const float y ) 00176 { 00177 if( x == 0.f && y == 0.f ) 00178 return; 00179 00180 _rotation.pre_rotate_x( x ); 00181 _rotation.pre_rotate_y( y ); 00182 setDirty( DIRTY_CAMERA ); 00183 } 00184 00185 void FrameData::spinModel( const float x, const float y, const float z ) 00186 { 00187 if( x == 0.f && y == 0.f && z == 0.f ) 00188 return; 00189 00190 _modelRotation.pre_rotate_x( x ); 00191 _modelRotation.pre_rotate_y( y ); 00192 _modelRotation.pre_rotate_z( z ); 00193 setDirty( DIRTY_CAMERA ); 00194 } 00195 00196 void FrameData::moveCamera( const float x, const float y, const float z ) 00197 { 00198 if( _pilotMode ) 00199 { 00200 eq::Matrix4f matInverse; 00201 compute_inverse( _rotation, matInverse ); 00202 eq::Vector4f shift = matInverse * eq::Vector4f( x, y, z, 1 ); 00203 00204 _position += shift; 00205 } 00206 else 00207 { 00208 _position.x() += x; 00209 _position.y() += y; 00210 _position.z() += z; 00211 } 00212 00213 setDirty( DIRTY_CAMERA ); 00214 } 00215 00216 void FrameData::setCameraPosition( const eq::Vector3f& position ) 00217 { 00218 _position = position; 00219 setDirty( DIRTY_CAMERA ); 00220 } 00221 00222 void FrameData::setRotation( const eq::Vector3f& rotation ) 00223 { 00224 _rotation = eq::Matrix4f::IDENTITY; 00225 _rotation.rotate_x( rotation.x() ); 00226 _rotation.rotate_y( rotation.y() ); 00227 _rotation.rotate_z( rotation.z() ); 00228 setDirty( DIRTY_CAMERA ); 00229 } 00230 00231 void FrameData::setModelRotation( const eq::Vector3f& rotation ) 00232 { 00233 _modelRotation = eq::Matrix4f::IDENTITY; 00234 _modelRotation.rotate_x( rotation.x() ); 00235 _modelRotation.rotate_y( rotation.y() ); 00236 _modelRotation.rotate_z( rotation.z() ); 00237 setDirty( DIRTY_CAMERA ); 00238 } 00239 00240 void FrameData::reset() 00241 { 00242 eq::Matrix4f model = eq::Matrix4f::IDENTITY; 00243 model.rotate_x( static_cast<float>( -M_PI_2 )); 00244 model.rotate_y( static_cast<float>( -M_PI_2 )); 00245 00246 if( _position == eq::Vector3f( 0.f, 0.f, -2.f ) && 00247 _rotation == eq::Matrix4f::IDENTITY && _modelRotation == model ) 00248 { 00249 _position.z() = 0.f; 00250 } 00251 else 00252 { 00253 _position = eq::Vector3f::ZERO; 00254 _position.z() = -2.f; 00255 _rotation = eq::Matrix4f::IDENTITY; 00256 _modelRotation = model; 00257 } 00258 setDirty( DIRTY_CAMERA ); 00259 } 00260 00261 void FrameData::setCurrentViewID( const eq::uint128_t& id ) 00262 { 00263 _currentViewID = id; 00264 setDirty( DIRTY_VIEW ); 00265 } 00266 00267 void FrameData::setMessage( const std::string& message ) 00268 { 00269 if( _message == message ) 00270 return; 00271 00272 _message = message; 00273 setDirty( DIRTY_MESSAGE ); 00274 } 00275 00276 } 00277