GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_turntablemover.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  Copyright (C) 2009 Laurent Bauer
6  http://glc-lib.sourceforge.net
7 
8  GLC-lib is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  GLC-lib is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with GLC-lib; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  *****************************************************************************/
23 
24 #include "glc_turntablemover.h"
25 #include "glc_viewport.h"
26 
27 // Default constructor
28 GLC_TurnTableMover::GLC_TurnTableMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
29 : GLC_Mover(pViewport, repsList)
30 , m_Sign(1.0)
31 {
32 
33 }
34 
35 
36 // Copy constructor
38 : GLC_Mover(mover)
39 , m_Sign(mover.m_Sign)
40 {
41 }
42 
43 
45 {
46 }
47 
48 
50 // Get Functions
52 
53 // Return a clone of the mover
55 {
56  return new GLC_TurnTableMover(*this);
57 }
58 
59 
61 // Set Functions
63 
64 // Initialized the mover
66 {
67  GLC_Mover::m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()),0.0);
69  // Calculate angle sign
70  m_Sign= pCamera->defaultUpVector() * pCamera->upVector();
71  if (m_Sign == 0)
72  {
73  m_Sign= 1;
74  }
75  else
76  {
77  m_Sign= m_Sign / fabs(m_Sign);
78  }
79 
80  pCamera->setUpCam(pCamera->defaultUpVector() * m_Sign);
81 }
82 
83 
85 {
87  // Turn table rotation
88  const double rotSpeed= 2.3;
89  const double width= static_cast<double> ( GLC_Mover::m_pViewport->viewVSize() );
90  const double height= static_cast<double> ( GLC_Mover::m_pViewport->viewHSize() );
91 
92  const double alpha = -((static_cast<double>(userInput.x()) - GLC_Mover::m_PreviousVector.x()) / width) * rotSpeed;
93  const double beta = ((static_cast<double>(userInput.y()) - GLC_Mover::m_PreviousVector.y()) / height) * rotSpeed;
94 
95  // Rotation around the screen vertical axis
96  pCamera->rotateAroundTarget(pCamera->defaultUpVector(), alpha * m_Sign);
97 
98  // Rotation around the screen horizontal axis
99  GLC_Vector3d incidentVector= -pCamera->forward();
100  GLC_Vector3d rightVector= incidentVector ^ pCamera->upVector();
101  if (!rightVector.isNull())
102  {
103  pCamera->rotateAroundTarget(rightVector, beta);
104  }
105 
106  m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()), 0.0);
107 
108  return true;
109 }

©2005-2013 Laurent Ribon