LCOV - code coverage report
Current view: top level - seq - viewData.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 49 104 47.1 %
Date: 2014-06-18 Functions: 10 15 66.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2012, Stefan Eilemann <eile@eyescale.ch>
       3             :  *                    2012, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "viewData.h"
      20             : 
      21             : #ifndef EQ_2_0_API
      22             : #  include <eq/client/configEvent.h>
      23             : #endif
      24             : #include <eq/client/event.h>
      25             : #include <eq/client/eventICommand.h>
      26             : #include <co/dataIStream.h>
      27             : #include <co/dataOStream.h>
      28             : 
      29             : namespace seq
      30             : {
      31           8 : ViewData::ViewData()
      32             :         : _modelMatrix( eq::Matrix4f::IDENTITY )
      33             :         , _spinX( 5 )
      34             :         , _spinY( 5 )
      35             :         , _advance( 0 )
      36             :         , _statistics( false )
      37           8 :         , _ortho( false )
      38             : {
      39           8 :     moveModel( 0.f, 0.f, -2.f );
      40           8 : }
      41             : 
      42          16 : ViewData::~ViewData()
      43          16 : {}
      44             : 
      45          10 : void ViewData::serialize( co::DataOStream& os, const uint64_t dirtyBits )
      46             : {
      47          10 :     co::Serializable::serialize( os, dirtyBits );
      48          10 :     if( dirtyBits & DIRTY_MODELMATRIX )
      49          10 :         os << _modelMatrix;
      50          10 :     if( dirtyBits & DIRTY_STATISTICS )
      51           8 :         os << _statistics;
      52          10 :     if( dirtyBits & DIRTY_ORTHO )
      53           8 :         os << _ortho;
      54          10 : }
      55             : 
      56           2 : void ViewData::deserialize( co::DataIStream& is, const uint64_t dirtyBits )
      57             : {
      58           2 :     co::Serializable::deserialize( is, dirtyBits );
      59           2 :     if( dirtyBits & DIRTY_MODELMATRIX )
      60           2 :         is >> _modelMatrix;
      61           2 :     if( dirtyBits & DIRTY_STATISTICS )
      62           1 :         is >> _statistics;
      63           2 :     if( dirtyBits & DIRTY_ORTHO )
      64           1 :         is >> _ortho;
      65           2 : }
      66             : #ifndef EQ_2_0_API
      67           0 : bool ViewData::handleEvent( const eq::ConfigEvent* event )
      68             : {
      69           0 :     return _handleEvent( event->data );
      70             : }
      71             : #endif
      72             : 
      73           0 : bool ViewData::handleEvent( eq::EventICommand command )
      74             : {
      75           0 :     const eq::Event& event = command.read< eq::Event >();
      76           0 :     return _handleEvent( event );
      77             : }
      78             : 
      79           0 : bool ViewData::_handleEvent( const eq::Event& event )
      80             : {
      81           0 :     switch( event.type )
      82             :     {
      83             :       case eq::Event::CHANNEL_POINTER_BUTTON_RELEASE:
      84             :       {
      85             :           const eq::PointerEvent& releaseEvent =
      86           0 :               event.pointerButtonRelease;
      87           0 :           if( releaseEvent.buttons == eq::PTR_BUTTON_NONE )
      88             :           {
      89           0 :               if( releaseEvent.button == eq::PTR_BUTTON1 )
      90             :               {
      91           0 :                   _spinX = releaseEvent.dy;
      92           0 :                   _spinY = releaseEvent.dx;
      93           0 :                   return true;
      94             :               }
      95           0 :               if( releaseEvent.button == eq::PTR_BUTTON2 )
      96             :               {
      97           0 :                   _advance = -releaseEvent.dy;
      98           0 :                   return true;
      99             :               }
     100             :           }
     101           0 :           return false;
     102             :       }
     103             :       case eq::Event::CHANNEL_POINTER_MOTION:
     104           0 :           switch( event.pointerMotion.buttons )
     105             :           {
     106             :             case eq::PTR_BUTTON1:
     107           0 :                 _spinX = 0;
     108           0 :                 _spinY = 0;
     109             :                 spinModel( -0.005f * event.pointerMotion.dy,
     110           0 :                            -0.005f * event.pointerMotion.dx, 0.f );
     111           0 :                 return true;
     112             : 
     113             :             case eq::PTR_BUTTON2:
     114           0 :                 _advance = -event.pointerMotion.dy;
     115           0 :                 moveModel( 0.f, 0.f, .005f * _advance );
     116           0 :                 return true;
     117             : 
     118             :             case eq::PTR_BUTTON3:
     119             :                 moveModel(  .0005f * event.pointerMotion.dx,
     120           0 :                            -.0005f * event.pointerMotion.dy, 0.f );
     121           0 :                 return true;
     122             : 
     123             :             default:
     124           0 :                 return false;
     125             :           }
     126             : 
     127             :       case eq::Event::CHANNEL_POINTER_WHEEL:
     128             :           moveModel( -0.05f * event.pointerWheel.yAxis, 0.f,
     129           0 :                       0.05f * event.pointerWheel.xAxis );
     130           0 :           return true;
     131             : 
     132             :       case eq::Event::MAGELLAN_AXIS:
     133           0 :           _spinX = 0;
     134           0 :           _spinY = 0;
     135           0 :           _advance = 0;
     136             :           spinModel(  0.0001f * event.magellan.zRotation,
     137             :                      -0.0001f * event.magellan.xRotation,
     138           0 :                      -0.0001f * event.magellan.yRotation );
     139             :           moveModel(  0.0001f * event.magellan.xAxis,
     140             :                      -0.0001f * event.magellan.zAxis,
     141           0 :                       0.0001f * event.magellan.yAxis );
     142           0 :           return true;
     143             : 
     144             :       case eq::Event::KEY_PRESS:
     145           0 :           switch( event.keyPress.key )
     146             :           {
     147             :             case 's':
     148           0 :                 showStatistics( !getStatistics( ));
     149           0 :                 return true;
     150             :             case 'o':
     151           0 :                 setOrtho( !useOrtho( ));
     152           0 :                 return true;
     153             :           }
     154           0 :           return false;
     155             : 
     156             :       default:
     157           0 :           return false;
     158             :     }
     159             : }
     160             : 
     161           1 : void ViewData::spinModel( const float x, const float y, const float z )
     162             : {
     163           1 :     if( x == 0.f && y == 0.f && z == 0.f )
     164           1 :         return;
     165             : 
     166           1 :     Vector3f translation;
     167           1 :     _modelMatrix.get_translation( translation );
     168           1 :     _modelMatrix.set_translation( Vector3f::ZERO );
     169           1 :     _modelMatrix.pre_rotate_x( x );
     170           1 :     _modelMatrix.pre_rotate_y( y );
     171           1 :     _modelMatrix.pre_rotate_z( z );
     172           1 :     _modelMatrix.set_translation( translation);
     173           1 :     setDirty( DIRTY_MODELMATRIX );
     174             : }
     175             : 
     176           9 : void ViewData::moveModel( const float x, const float y, const float z )
     177             : {
     178           9 :     if( x == 0.f && y == 0.f && z == 0.f )
     179          10 :         return;
     180             : 
     181           8 :     Vector3f translation;
     182           8 :     _modelMatrix.get_translation( translation );
     183           8 :     if( translation.squared_length() < 0.01f )
     184           8 :         _modelMatrix.set_translation( translation + Vector3f( x, y, z ));
     185             :     else
     186           0 :         _modelMatrix.scale_translation( Vector3f( 1.f + x, 1.f + y, 1.f + z ));
     187           8 :     setDirty( DIRTY_MODELMATRIX );
     188             : }
     189             : 
     190           0 : void ViewData::showStatistics( const bool on )
     191             : {
     192           0 :     if( _statistics == on )
     193           0 :         return;
     194             : 
     195           0 :     _statistics = on;
     196           0 :     setDirty( DIRTY_STATISTICS );
     197             : }
     198             : 
     199           0 : void  ViewData::setOrtho( const bool on )
     200             : {
     201           0 :     if( _ortho == on )
     202           0 :         return;
     203             : 
     204           0 :     _ortho = on;
     205           0 :     setDirty( DIRTY_ORTHO );
     206             : }
     207             : 
     208           1 : bool ViewData::update()
     209             : {
     210           1 :     if( _spinX == 0 && _spinY == 0 && _advance == 0 )
     211           0 :         return false;
     212             : 
     213           1 :     spinModel( -0.001f * _spinX, -0.001f * _spinY, 0.f );
     214           1 :     moveModel( 0.0f, 0.0f, 0.001f * _advance );
     215           1 :     return true;
     216             : }
     217             : 
     218           3 : }

Generated by: LCOV version 1.10