glc_tsrmover.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00022 
00024 
00025 #include "glc_tsrmover.h"
00026 #include "glc_viewport.h"
00027 
00028 #include "../geometry/glc_point.h"
00029 
00030 // Default constructor
00031 GLC_TsrMover::GLC_TsrMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00032 : GLC_Mover(pViewport, repsList)
00033 {
00034 
00035 }
00036 
00037 // Copy constructor
00038 GLC_TsrMover::GLC_TsrMover(const GLC_TsrMover& tsrMover)
00039 : GLC_Mover(tsrMover)
00040 {
00041 
00042 }
00043 
00044 
00045 GLC_TsrMover::~GLC_TsrMover()
00046 {
00047 
00048 }
00049 
00051 // Get Functions
00053 
00054 // Return a clone of the mover
00055 GLC_Mover* GLC_TsrMover::clone() const
00056 {
00057         return new GLC_TsrMover(*this);
00058 }
00059 
00060 
00062 // Set Functions
00064 
00065 // Initialized the mover
00066 void GLC_TsrMover::init(const GLC_UserInput& userInput)
00067 {
00068         m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
00069 }
00070 
00071 // Move the camera
00072 bool GLC_TsrMover::move(const GLC_UserInput& userInput)
00073 {
00074         if (!(userInput.normalyzeXTouchCenter() < 0.0) && !(userInput.normalyzeYTouchCenter() < 0.0))
00075         {
00076                 m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
00077         }
00078         else
00079         {
00080                 qDebug() << "Pas cool";
00081                 if (!userInput.translation().isNull())
00082                 {
00083                         m_PreviousVector= GLC_Vector3d(userInput.translation().getX(), userInput.translation().getY(), 0.0) + m_PreviousVector;                 
00084                 }
00085         }
00086         
00087         const double x= m_PreviousVector.x();
00088         const double y= m_PreviousVector.y();
00089         //GLC_Point3d center2= m_pViewport->unProject(x * m_pViewport->viewHSize(), y * m_pViewport->viewVSize());
00090         
00091         //qDebug() << "touch center= " << x << " , " << y;
00092 
00093         
00094         if (!qFuzzyCompare(userInput.scaleFactor(), 0))
00095         {
00096                 GLC_Point dummy(m_pViewport->cameraHandle()->target());
00097                 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00098 
00099                 GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
00100                 GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
00101                 GLC_Point3d projected= m_pViewport->compositionMatrix().inverted() * nPos3D;
00102 
00103                 m_pViewport->cameraHandle()->zoom(userInput.scaleFactor());
00104 
00105                 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00106                 GLC_Point3d projected2= m_pViewport->compositionMatrix().inverted() * nPos3D;
00107                 GLC_Vector3d delta= projected - projected2;
00108                 m_pViewport->cameraHandle()->translate(delta);
00109         }
00110 
00111         if (!qFuzzyCompare(userInput.rotationAngle(), 0))
00112         {
00113                 GLC_Point dummy(m_pViewport->cameraHandle()->target());
00114                 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00115 
00116                 GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
00117                 GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
00118                 GLC_Point3d center= m_pViewport->compositionMatrix().inverted() * nPos3D;
00119 
00120                 GLC_Vector3d axis= m_pViewport->cameraHandle()->forward();
00121 
00122                 m_pViewport->cameraHandle()->rotateAround(axis, userInput.rotationAngle(), center);
00123         }
00124 
00125         if (!userInput.translation().isNull())
00126         {
00127                 double transX= userInput.translation().getX() * m_pViewport->viewHSize();
00128                 double transY= userInput.translation().getY() * m_pViewport->viewVSize();
00129 
00130                 GLC_Vector3d mappedTranslation(-transX, -transY, 0.0);
00131                 // Compute the length of camera's field of view
00132                 const double ChampsVision = m_pViewport->cameraHandle()->distEyeTarget() *  m_pViewport->viewTangent();
00133 
00134                 // the side of camera's square is mapped on Vertical length of window
00135                 // Ratio OpenGL/Pixel = dimend GL / dimens Pixel
00136                 const double Ratio= ChampsVision / static_cast<double>(m_pViewport->viewVSize());
00137 
00138                 mappedTranslation= mappedTranslation * Ratio;
00139                 m_pViewport->cameraHandle()->pan(mappedTranslation);
00140         }
00141 
00142         return true;
00143 }
00144 

SourceForge.net Logo

©2005-2011 Laurent Ribon