examples/eqPly/frameData.cpp

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "frameData.h"
00019 
00020 namespace eqPly
00021 {
00022 
00023 FrameData::FrameData()
00024         : _modelID( EQ_ID_INVALID )
00025         , _renderMode( mesh::RENDER_MODE_DISPLAY_LIST )
00026         , _colorMode( COLOR_MODEL )
00027         , _ortho( false )
00028         , _statistics( false )
00029         , _help( false )
00030         , _wireframe( false )
00031         , _pilotMode( false )
00032         , _currentViewID( EQ_ID_INVALID )
00033 {
00034     reset();
00035     EQINFO << "New FrameData " << std::endl;
00036 }
00037 
00038 void FrameData::serialize( eq::net::DataOStream& os, const uint64_t dirtyBits )
00039 {
00040     eq::Object::serialize( os, dirtyBits );
00041     if( dirtyBits & DIRTY_CAMERA )
00042         os << _translation << _rotation << _modelRotation;
00043     if( dirtyBits & DIRTY_FLAGS )
00044         os << _modelID << _renderMode << _colorMode << _ortho << _statistics
00045            << _help << _wireframe << _pilotMode;
00046     if( dirtyBits & DIRTY_VIEW )
00047         os << _currentViewID;
00048     if( dirtyBits & DIRTY_MESSAGE )
00049         os << _message;
00050 }
00051 
00052 void FrameData::deserialize( eq::net::DataIStream& is,
00053                              const uint64_t dirtyBits )
00054 {
00055     eq::Object::deserialize( is, dirtyBits );
00056     if( dirtyBits & DIRTY_CAMERA )
00057         is >> _translation >> _rotation >> _modelRotation;
00058     if( dirtyBits & DIRTY_FLAGS )
00059         is >> _modelID >> _renderMode >> _colorMode >> _ortho >> _statistics
00060            >> _help >> _wireframe >> _pilotMode;
00061     if( dirtyBits & DIRTY_VIEW )
00062         is >> _currentViewID;
00063     if( dirtyBits & DIRTY_MESSAGE )
00064         is >> _message;
00065 }
00066 
00067 void FrameData::setModelID( const uint32_t id )
00068 {
00069     _modelID = id;
00070     setDirty( DIRTY_FLAGS );
00071 }
00072 
00073 void FrameData::setColorMode( const ColorMode mode )
00074 {
00075     _colorMode = mode;
00076     setDirty( DIRTY_FLAGS );
00077 }
00078 
00079 void FrameData::setRenderMode( const mesh::RenderMode mode )
00080 {
00081     _renderMode = mode;
00082     setDirty( DIRTY_FLAGS );
00083 }
00084 
00085 void FrameData::toggleOrtho()
00086 {
00087     _ortho = !_ortho;
00088     setDirty( DIRTY_FLAGS );
00089 }
00090 
00091 void FrameData::toggleStatistics()
00092 {
00093     _statistics = !_statistics;
00094     setDirty( DIRTY_FLAGS );
00095 }
00096 
00097 void FrameData::toggleHelp()
00098 {
00099     _help = !_help;
00100     setDirty( DIRTY_FLAGS );
00101 }
00102 
00103 void FrameData::toggleWireframe()
00104 {
00105     _wireframe = !_wireframe;
00106     setDirty( DIRTY_FLAGS );
00107 }
00108 
00109 void FrameData::toggleColorMode()
00110 {
00111     _colorMode = static_cast< ColorMode >(( _colorMode + 1) % COLOR_ALL );
00112     setDirty( DIRTY_FLAGS );
00113 }
00114 
00115 void FrameData::togglePilotMode()
00116 {
00117     _pilotMode = !_pilotMode;
00118     setDirty( DIRTY_FLAGS );
00119 }
00120 
00121 void FrameData::toggleRenderMode()
00122 {
00123     _renderMode = static_cast< mesh::RenderMode >(
00124         ( _renderMode + 1) % mesh::RENDER_MODE_ALL );
00125 
00126     EQINFO << "Switched to " << _renderMode << std::endl;
00127     setDirty( DIRTY_FLAGS );
00128 }
00129 
00130 void FrameData::spinCamera( const float x, const float y )
00131 {
00132     if( x == 0.f && y == 0.f )
00133         return;
00134 
00135     _rotation.pre_rotate_x( x );
00136     _rotation.pre_rotate_y( y );
00137     setDirty( DIRTY_CAMERA );
00138 }
00139 
00140 void FrameData::spinModel( const float x, const float y )
00141 {
00142     if( x == 0.f && y == 0.f )
00143         return;
00144 
00145     _modelRotation.pre_rotate_x( x );
00146     _modelRotation.pre_rotate_y( y );
00147     setDirty( DIRTY_CAMERA );
00148 }
00149 
00150 void FrameData::spinModel( const float x, const float y, const float z )
00151 {
00152     if( x == 0.f && y == 0.f && z == 0.f )
00153         return;
00154 
00155     _modelRotation.pre_rotate_x( x );
00156     _modelRotation.pre_rotate_y( y );
00157     _modelRotation.pre_rotate_z( z );
00158     setDirty( DIRTY_CAMERA );
00159 }
00160 
00161 void FrameData::moveCamera( const float x, const float y, const float z )
00162 {
00163     if( _pilotMode )
00164     {
00165         eq::Matrix4f matInverse;
00166         compute_inverse( _rotation, matInverse );
00167         eq::Vector4f shift = matInverse * eq::Vector4f( x, y, z, 1 );
00168 
00169         _translation += shift;
00170     }
00171     else
00172     {
00173         _translation.x() += x;
00174         _translation.y() += y;
00175         _translation.z() += z;
00176     }
00177 
00178     setDirty( DIRTY_CAMERA );
00179 }
00180 
00181 void FrameData::setCameraPosition( const float x, const float y, const float z )
00182 {
00183     _translation.x() = x;
00184     _translation.y() = y;
00185     _translation.z() = z;
00186     setDirty( DIRTY_CAMERA );
00187 }
00188 
00189 void FrameData::setTranslation( const eq::Vector3f& translation )
00190 {
00191     _translation = translation;
00192     setDirty( DIRTY_CAMERA );
00193 }
00194 
00195 void FrameData::setRotation( const eq::Vector3f& rotation )
00196 {
00197     _rotation = eq::Matrix4f::IDENTITY;
00198     _rotation.rotate_x( rotation.x() );
00199     _rotation.rotate_y( rotation.y() );
00200     _rotation.rotate_z( rotation.z() );
00201     setDirty( DIRTY_CAMERA );
00202 }
00203 
00204 void FrameData::setModelRotation(  const eq::Vector3f& rotation )
00205 {
00206     _modelRotation = eq::Matrix4f::IDENTITY;
00207     _modelRotation.rotate_x( rotation.x() );
00208     _modelRotation.rotate_y( rotation.y() );
00209     _modelRotation.rotate_z( rotation.z() );
00210     setDirty( DIRTY_CAMERA );
00211 }
00212 
00213 void FrameData::reset()
00214 {
00215     _translation   = eq::Vector3f::ZERO;
00216     _translation.z() = -2.f;
00217     _rotation      = eq::Matrix4f::IDENTITY;
00218     _modelRotation = eq::Matrix4f::IDENTITY;
00219     _modelRotation.rotate_x( static_cast<float>( -M_PI_2 ));
00220     _modelRotation.rotate_y( static_cast<float>( -M_PI_2 ));
00221     setDirty( DIRTY_CAMERA );
00222 }
00223 
00224 void FrameData::setCurrentViewID( const uint32_t id )
00225 {
00226     _currentViewID = id;
00227     setDirty( DIRTY_VIEW );
00228 }
00229 
00230 void FrameData::setMessage( const std::string& message )
00231 {
00232     if( _message == message )
00233         return;
00234 
00235     _message = message;
00236     setDirty( DIRTY_MESSAGE );
00237 }
00238 
00239 }
00240 
Generated on Mon Aug 10 18:58:33 2009 for Equalizer 0.9 by  doxygen 1.5.8