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