PanoramaControlPlugin.cc 5.93 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen       *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision: 13354 $                                                       *
*   $LastChangedBy: moebius $                                                *
*   $Date: 2012-01-12 13:39:10 +0100 (Do, 12 Jan 2012) $                     *
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
43 44
#include <ObjectTypes/SkyDome/SkyDome.hh>

45 46
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
47 48 49 50

#include <QtGui>

#include "PanoramaControlPlugin.hh"
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

PanoramaControlPlugin::PanoramaControlPlugin() :
        tool_(0)
{

}

void PanoramaControlPlugin::initializePlugin(){

  tool_ = new PanoramaToolBox();
  
  connect(tool_->hFOV  , SIGNAL( valueChanged(double) ), this, SLOT( slotValuesChanged(double) ) );
  connect(tool_->vFOV  , SIGNAL( valueChanged(double) ), this, SLOT( slotValuesChanged(double) ) );
  connect(tool_->cutOff, SIGNAL( valueChanged(double) ), this, SLOT( slotValuesChanged(double) ) );

  connect(tool_->loadButton, SIGNAL( clicked() ), this, SLOT( slotLoadImage() ) );

69 70 71
  // Add icon and toolbox
  QIcon* toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"PanoControl.png");
  emit addToolbox( tr("Panorama Control") , tool_, toolIcon_);
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

}

void PanoramaControlPlugin::slotLoadImage() {

  SkyDomeObject* domeObject = 0;

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,( DATA_SKYDOME )) ;o_it != PluginFunctions::objectsEnd(); ++o_it)
  {
    domeObject = PluginFunctions::skyDomeObject(*o_it);

    // We only take the first one
    if ( domeObject )
      break;
  }

  // No dome object found, so we have to create one
  if ( !domeObject ) {

    // Add empty triangle mesh
    int domeId = -1;
    emit addEmptyObject ( DATA_SKYDOME, domeId );

    domeObject = PluginFunctions::skyDomeObject(domeId);
  }

  if ( !domeObject ) {
    emit log(LOGERR,"Unable to get or create new Sky Dome Object");
    return;
  }

  // Ask user to load the file
  QString file = QFileDialog::getOpenFileName ( 0, "Load Panorama Image", "", "Images (*.png *.xpm *.jpg)", 0, 0 );

  // Update the texture file name
  domeObject->getSkyDome().setTextureFileName(file);

  // Update the object and its buffers
Jan Möbius's avatar
Jan Möbius committed
110
  emit updatedObject(domeObject->id(), UPDATE_TEXTURE);
Jan Möbius's avatar
Jan Möbius committed
111 112 113 114

  // Switch to shader pipeline renderer
  emit setRenderer(PluginFunctions::activeExaminer(),"Shader Pipeline Renderer Plugin");

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
}

void PanoramaControlPlugin::slotValuesChanged(double) {

  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,( DATA_SKYDOME )) ;o_it != PluginFunctions::objectsEnd(); ++o_it)
  {
    SkyDomeObject* domeObject = PluginFunctions::skyDomeObject(*o_it);

    if ( domeObject ) {
      domeObject->getSkyDome().setHorizontalFOV( tool_->hFOV->value() );
      domeObject->getSkyDome().setVerticalFOV(tool_->vFOV->value() );
      domeObject->getSkyDome().setTopOffset(tool_->cutOff->value() );

      // Only first object will be handled for now!
      break;
    }

  }

Jan Möbius's avatar
Jan Möbius committed
134
  // Only update the view, as only uniforms will change here
135 136 137
  emit updateView();
}

Jan Möbius's avatar
Jan Möbius committed
138
#if QT_VERSION < 0x050000
139
Q_EXPORT_PLUGIN2( panoramacontrolplugin , PanoramaControlPlugin );
Jan Möbius's avatar
Jan Möbius committed
140
#endif