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 00023 #include "glc_zoommover.h" 00024 #include "glc_viewport.h" 00025 00026 // Default constructor 00027 GLC_ZoomMover::GLC_ZoomMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList) 00028 : GLC_Mover(pViewport, repsList) 00029 , m_MaxZoomFactor(3.0) 00030 { 00031 00032 } 00033 00034 // Copy constructor 00035 GLC_ZoomMover::GLC_ZoomMover(const GLC_ZoomMover& mover) 00036 : GLC_Mover(mover) 00037 , m_MaxZoomFactor(mover.m_MaxZoomFactor) 00038 { 00039 00040 } 00041 00042 GLC_ZoomMover::~GLC_ZoomMover() 00043 { 00044 00045 } 00046 00047 00049 // Get Functions 00051 00052 // Return a clone of the mover 00053 GLC_Mover* GLC_ZoomMover::clone() const 00054 { 00055 return new GLC_ZoomMover(*this); 00056 } 00057 00059 // Set Functions 00061 00062 // Initialized the mover 00063 void GLC_ZoomMover::init(const GLC_UserInput& userInput) 00064 { 00065 // Change origine (view center) and cover between -1 and 1 00066 const double vSize= static_cast<double>(m_pViewport->viewVSize()); 00067 m_PreviousVector.setY((vSize / 2.0 - userInput.y()) / ( vSize / 2.0)); 00068 } 00069 00070 // Move the camera 00071 bool GLC_ZoomMover::move(const GLC_UserInput& userInput) 00072 { 00073 // Change origine (View Center) and cover (from -1 to 1) 00074 const double vSize= static_cast<double>(m_pViewport->viewVSize()); 00075 const double Posy= (vSize / 2.0 - userInput.y()) / ( vSize / 2.0); 00076 00077 // Compute zoom factor between (1 / MAXZOOMFACTOR) and (MAXZOOMFACTOR) 00078 double ZoomFactor= Posy - m_PreviousVector.y(); 00079 00080 if (ZoomFactor > 0) 00081 { 00082 ZoomFactor= (m_MaxZoomFactor - 1.0) * ZoomFactor + 1.0; 00083 } 00084 else 00085 { 00086 ZoomFactor= 1.0 / ( (m_MaxZoomFactor - 1.0) * fabs(ZoomFactor) + 1.0 ); 00087 } 00088 00089 m_pViewport->cameraHandle()->zoom(ZoomFactor); 00090 00091 m_PreviousVector.setY(Posy); 00092 00093 return true; 00094 }