GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_zoommover.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
22 
23 #include "glc_zoommover.h"
24 #include "glc_viewport.h"
25 
26 // Default constructor
27 GLC_ZoomMover::GLC_ZoomMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
28 : GLC_Mover(pViewport, repsList)
29 , m_MaxZoomFactor(3.0)
30 {
31 
32 }
33 
34 // Copy constructor
36 : GLC_Mover(mover)
37 , m_MaxZoomFactor(mover.m_MaxZoomFactor)
38 {
39 
40 }
41 
43 {
44 
45 }
46 
47 
49 // Get Functions
51 
52 // Return a clone of the mover
54 {
55  return new GLC_ZoomMover(*this);
56 }
57 
59 // Set Functions
61 
62 // Initialized the mover
63 void GLC_ZoomMover::init(const GLC_UserInput& userInput)
64 {
65  // Change origine (view center) and cover between -1 and 1
66  const double vSize= static_cast<double>(m_pViewport->viewVSize());
67  m_PreviousVector.setY((vSize / 2.0 - userInput.y()) / ( vSize / 2.0));
68 }
69 
70 // Move the camera
71 bool GLC_ZoomMover::move(const GLC_UserInput& userInput)
72 {
73  // Change origine (View Center) and cover (from -1 to 1)
74  const double vSize= static_cast<double>(m_pViewport->viewVSize());
75  const double Posy= (vSize / 2.0 - userInput.y()) / ( vSize / 2.0);
76 
77  // Compute zoom factor between (1 / MAXZOOMFACTOR) and (MAXZOOMFACTOR)
78  double ZoomFactor= Posy - m_PreviousVector.y();
79 
80  if (ZoomFactor > 0)
81  {
82  ZoomFactor= (m_MaxZoomFactor - 1.0) * ZoomFactor + 1.0;
83  }
84  else
85  {
86  ZoomFactor= 1.0 / ( (m_MaxZoomFactor - 1.0) * fabs(ZoomFactor) + 1.0 );
87  }
88 
89  m_pViewport->cameraHandle()->zoom(ZoomFactor);
90 
91  m_PreviousVector.setY(Posy);
92 
93  return true;
94 }

©2005-2013 Laurent Ribon