LCOV - code coverage report
Current view: top level - seq - viewData.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 1 106 0.9 %
Date: 2016-09-29 05:02:09 Functions: 2 16 12.5 %

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

Generated by: LCOV version 1.11