Equalizer 1.0

eVolve/frameData.cpp

00001 
00002 /* Copyright (c) 2006-2010, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *               2007-2009, Maxim Makhinya
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     , _statistics(    false )
00042     , _help(          false )
00043     , _quality( 1.0f )
00044     , _currentViewID( co::base::UUID::ZERO )
00045 {
00046     reset();
00047     EQINFO << "New FrameData " << std::endl;
00048 }
00049 
00050 void FrameData::reset()
00051 {
00052     _translation     = eq::Vector3f::ZERO;
00053     _translation.z() = -2.f;
00054     _rotation        = eq::Matrix4f::IDENTITY;
00055     _rotation.rotate_x( static_cast<float>( -M_PI_2 ));
00056     _rotation.rotate_y( static_cast<float>( -M_PI_2 ));
00057 
00058     setDirty( DIRTY_CAMERA );
00059 }
00060 
00061 void FrameData::toggleOrtho( )
00062 {
00063     _ortho = !_ortho;
00064     setDirty( DIRTY_FLAGS );
00065 }
00066 
00067 void FrameData::setOrtho( const bool ortho )
00068 {
00069     _ortho = ortho;
00070     setDirty( DIRTY_FLAGS );
00071 }
00072 
00073 void FrameData::toggleStatistics()
00074 {
00075     _statistics = !_statistics;
00076     setDirty( DIRTY_FLAGS );
00077 }
00078 
00079 void FrameData::toggleHelp()
00080 {
00081     _help = !_help;
00082     setDirty( DIRTY_FLAGS );
00083 }
00084 
00085 void FrameData::spinCamera( const float x, const float y )
00086 {
00087     _rotation.pre_rotate_x( x );
00088     _rotation.pre_rotate_y( y );
00089 
00090     setDirty( DIRTY_CAMERA );
00091 }
00092 
00093 void FrameData::moveCamera( const float x, const float y, const float z )
00094 {
00095     _translation.x() += x;
00096     _translation.y() += y;
00097     _translation.z() += z;
00098 
00099     setDirty( DIRTY_CAMERA );
00100 }
00101 
00102 void FrameData::setTranslation(   const eq::Vector3f& translation )
00103 {
00104     _translation = translation;
00105     setDirty( DIRTY_CAMERA );
00106 }
00107 
00108 void FrameData::setRotation(  const eq::Vector3f& rotation )
00109 {
00110     _rotation = eq::Matrix4f::IDENTITY;
00111     _rotation.rotate_x( rotation.x() );
00112     _rotation.rotate_y( rotation.y() );
00113     _rotation.rotate_z( rotation.z() );
00114     setDirty( DIRTY_CAMERA );
00115 }
00116 
00117 void FrameData::setCurrentViewID( const eq::uint128_t& id )
00118 {
00119     _currentViewID = id;
00120     setDirty( DIRTY_VIEW );
00121 }
00122 
00123 void FrameData::adjustQuality( const float delta )
00124 {
00125     _quality += delta;
00126     _quality = EQ_MAX( _quality, 0.1f );
00127     _quality = EQ_MIN( _quality, 1.0f );
00128     setDirty( DIRTY_FLAGS );
00129     EQINFO << "Set non-idle image quality to " << _quality << std::endl;
00130 }
00131 
00132 void FrameData::serialize( co::DataOStream& os, const uint64_t dirtyBits )
00133 {
00134     eq::fabric::Serializable::serialize( os, dirtyBits );
00135     if( dirtyBits & DIRTY_VIEW )
00136         os << _currentViewID;
00137 
00138     if( dirtyBits & DIRTY_CAMERA )
00139         os << _rotation << _translation;
00140 
00141     if( dirtyBits & DIRTY_FLAGS )
00142         os << _ortho << _statistics << _quality  << _help;
00143 
00144     if( dirtyBits & DIRTY_MESSAGE )
00145         os << _message;
00146 }
00147 
00148 void FrameData::deserialize( co::DataIStream& is, const uint64_t dirtyBits)
00149 {
00150     eq::fabric::Serializable::deserialize( is, dirtyBits );
00151     if( dirtyBits & DIRTY_VIEW )
00152         is >> _currentViewID;
00153 
00154     if( dirtyBits & DIRTY_CAMERA )
00155         is >> _rotation >> _translation;
00156 
00157     if( dirtyBits & DIRTY_FLAGS )
00158         is >> _ortho >> _statistics  >> _quality >> _help;
00159 
00160     if( dirtyBits & DIRTY_MESSAGE )
00161         is >> _message;
00162 }
00163 
00164 void FrameData::setMessage( const std::string& message )
00165 {
00166     if( _message == message )
00167         return;
00168 
00169     _message = message;
00170     setDirty( DIRTY_MESSAGE );
00171 }
00172 
00173 }
Generated on Sun May 8 2011 19:11:05 for Equalizer 1.0 by  doxygen 1.7.3