Equalizer  1.2.1
eVolve/frameData.cpp
00001 
00002 /* Copyright (c) 2006-2011, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *               2007-2011, Maxim Makhinya  <maxmah@gmail.com>
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  * - Redistributions in binary form must reproduce the above copyright notice,
00011  *   this list of conditions and the following disclaimer in the documentation
00012  *   and/or other materials provided with the distribution.
00013  * - Neither the name of Eyescale Software GmbH nor the names of its
00014  *   contributors may be used to endorse or promote products derived from this
00015  *   software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "frameData.h"
00031 
00032 #ifndef M_PI_2
00033 #  define M_PI_2 1.57079632679489661923
00034 #endif
00035 
00036 namespace eVolve
00037 {
00038 
00039 FrameData::FrameData()
00040     : _ortho(         false )
00041     , _colorMode(     COLOR_MODEL )
00042     , _bgMode(        BG_BLACK )
00043     , _normalsQuality(NQ_FULL )
00044     , _statistics(    false )
00045     , _help(          false )
00046     , _quality( 1.0f )
00047     , _currentViewID( co::base::UUID::ZERO )
00048 {
00049     reset();
00050     EQINFO << "New FrameData " << std::endl;
00051 }
00052 
00053 void FrameData::reset()
00054 {
00055     _translation     = eq::Vector3f::ZERO;
00056     _translation.z() = -2.f;
00057     _rotation        = eq::Matrix4f::IDENTITY;
00058     _rotation.rotate_x( static_cast<float>( -M_PI_2 ));
00059     _rotation.rotate_y( static_cast<float>( -M_PI_2 ));
00060 
00061     setDirty( DIRTY_CAMERA );
00062 }
00063 
00064 void FrameData::toggleBackground()
00065 {
00066     _bgMode = static_cast< BackgroundMode >(( _bgMode + 1 ) % BG_ALL );
00067     setDirty( DIRTY_FLAGS );
00068 }
00069 
00070 void FrameData::toggleNormalsQuality()
00071 {
00072     _normalsQuality = 
00073         static_cast< NormalsQuality >(( _normalsQuality + 1 ) % NQ_ALL );
00074     setDirty( DIRTY_FLAGS );
00075 }
00076 
00077 
00078 void FrameData::toggleColorMode()
00079 {
00080     _colorMode = static_cast< ColorMode >(( _colorMode + 1 ) % COLOR_ALL );
00081     setDirty( DIRTY_FLAGS );
00082 }
00083 
00084 void FrameData::toggleOrtho( )
00085 {
00086     _ortho = !_ortho;
00087     setDirty( DIRTY_FLAGS );
00088 }
00089 
00090 void FrameData::setOrtho( const bool ortho )
00091 {
00092     _ortho = ortho;
00093     setDirty( DIRTY_FLAGS );
00094 }
00095 
00096 void FrameData::toggleStatistics()
00097 {
00098     _statistics = !_statistics;
00099     setDirty( DIRTY_FLAGS );
00100 }
00101 
00102 void FrameData::toggleHelp()
00103 {
00104     _help = !_help;
00105     setDirty( DIRTY_FLAGS );
00106 }
00107 
00108 void FrameData::spinCamera( const float x, const float y )
00109 {
00110     _rotation.pre_rotate_x( x );
00111     _rotation.pre_rotate_y( y );
00112 
00113     setDirty( DIRTY_CAMERA );
00114 }
00115 
00116 void FrameData::moveCamera( const float x, const float y, const float z )
00117 {
00118     _translation.x() += x;
00119     _translation.y() += y;
00120     _translation.z() += z;
00121 
00122     setDirty( DIRTY_CAMERA );
00123 }
00124 
00125 void FrameData::setTranslation(   const eq::Vector3f& translation )
00126 {
00127     _translation = translation;
00128     setDirty( DIRTY_CAMERA );
00129 }
00130 
00131 void FrameData::setRotation(  const eq::Vector3f& rotation )
00132 {
00133     _rotation = eq::Matrix4f::IDENTITY;
00134     _rotation.rotate_x( rotation.x() );
00135     _rotation.rotate_y( rotation.y() );
00136     _rotation.rotate_z( rotation.z() );
00137     setDirty( DIRTY_CAMERA );
00138 }
00139 
00140 void FrameData::setCurrentViewID( const eq::uint128_t& id )
00141 {
00142     _currentViewID = id;
00143     setDirty( DIRTY_VIEW );
00144 }
00145 
00146 void FrameData::adjustQuality( const float delta )
00147 {
00148     _quality += delta;
00149     _quality = EQ_MAX( _quality, 0.1f );
00150     _quality = EQ_MIN( _quality, 1.0f );
00151     setDirty( DIRTY_FLAGS );
00152     EQINFO << "Set non-idle image quality to " << _quality << std::endl;
00153 }
00154 
00155 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits )
00156 {
00157     co::Serializable::serialize( os, dirtyBits );
00158     if( dirtyBits & DIRTY_VIEW )
00159         os << _currentViewID;
00160 
00161     if( dirtyBits & DIRTY_CAMERA )
00162         os << _rotation << _translation;
00163 
00164     if( dirtyBits & DIRTY_FLAGS )
00165         os  << _ortho << _colorMode << _bgMode << _normalsQuality
00166             << _statistics << _quality << _help;
00167 
00168     if( dirtyBits & DIRTY_MESSAGE )
00169         os << _message;
00170 }
00171 
00172 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits)
00173 {
00174     co::Serializable::deserialize( is, dirtyBits );
00175     if( dirtyBits & DIRTY_VIEW )
00176         is >> _currentViewID;
00177 
00178     if( dirtyBits & DIRTY_CAMERA )
00179         is >> _rotation >> _translation;
00180 
00181     if( dirtyBits & DIRTY_FLAGS )
00182         is  >> _ortho >> _colorMode >> _bgMode >> _normalsQuality
00183             >> _statistics  >> _quality >> _help;
00184 
00185     if( dirtyBits & DIRTY_MESSAGE )
00186         is >> _message;
00187 }
00188 
00189 void FrameData::setMessage( const std::string& message )
00190 {
00191     if( _message == message )
00192         return;
00193 
00194     _message = message;
00195     setDirty( DIRTY_MESSAGE );
00196 }
00197 
00198 }
Generated on Fri Jun 8 2012 15:44:30 for Equalizer 1.2.1 by  doxygen 1.8.0