GLC_lib
2.5.0
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Users
laumaya
git
glc_lib
src
viewport
glc_tsrmover.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
24
25
#include "
glc_tsrmover.h
"
26
#include "
glc_viewport.h
"
27
28
#include "../geometry/glc_point.h"
29
30
// Default constructor
31
GLC_TsrMover::GLC_TsrMover
(
GLC_Viewport
* pViewport,
const
QList<GLC_RepMover*>& repsList)
32
:
GLC_Mover
(pViewport, repsList)
33
{
34
35
}
36
37
// Copy constructor
38
GLC_TsrMover::GLC_TsrMover
(
const
GLC_TsrMover
& tsrMover)
39
:
GLC_Mover
(tsrMover)
40
{
41
42
}
43
44
45
GLC_TsrMover::~GLC_TsrMover
()
46
{
47
48
}
49
51
// Get Functions
53
54
// Return a clone of the mover
55
GLC_Mover
*
GLC_TsrMover::clone
()
const
56
{
57
return
new
GLC_TsrMover
(*
this
);
58
}
59
60
62
// Set Functions
64
65
// Initialized the mover
66
void
GLC_TsrMover::init
(
const
GLC_UserInput
& userInput)
67
{
68
m_PreviousVector
=
GLC_Point3d
(userInput.
normalyzeXTouchCenter
(), userInput.
normalyzeYTouchCenter
(), 0.0);
69
}
70
71
// Move the camera
72
bool
GLC_TsrMover::move
(
const
GLC_UserInput
& userInput)
73
{
74
if
(!(userInput.
normalyzeXTouchCenter
() < 0.0) && !(userInput.
normalyzeYTouchCenter
() < 0.0))
75
{
76
m_PreviousVector
=
GLC_Point3d
(userInput.
normalyzeXTouchCenter
(), userInput.
normalyzeYTouchCenter
(), 0.0);
77
}
78
else
79
{
80
qDebug() <<
"Pas cool"
;
81
if
(!userInput.
translation
().
isNull
())
82
{
83
m_PreviousVector
=
GLC_Vector3d
(userInput.
translation
().
x
(), userInput.
translation
().
y
(), 0.0) +
m_PreviousVector
;
84
}
85
}
86
87
const
double
x=
m_PreviousVector
.
x
();
88
const
double
y=
m_PreviousVector
.
y
();
89
//GLC_Point3d center2= m_pViewport->unProject(x * m_pViewport->viewHSize(), y * m_pViewport->viewVSize());
90
91
//qDebug() << "touch center= " << x << " , " << y;
92
93
94
if
(!qFuzzyCompare(userInput.
scaleFactor
(), 0))
95
{
96
GLC_Point
dummy(
m_pViewport
->
cameraHandle
()->
target
());
97
m_pViewport
->
setDistMinAndMax
(dummy.boundingBox());
98
99
GLC_Point2d
nPos=
m_pViewport
->
mapNormalyzeToOpenGLScreen
(x, y);
100
GLC_Point3d
nPos3D(nPos.
x
(), nPos.
y
(), 1.0);
101
GLC_Point3d
projected=
m_pViewport
->
compositionMatrix
().
inverted
() * nPos3D;
102
103
m_pViewport
->
cameraHandle
()->
zoom
(userInput.
scaleFactor
());
104
105
m_pViewport
->
setDistMinAndMax
(dummy.boundingBox());
106
GLC_Point3d
projected2=
m_pViewport
->
compositionMatrix
().
inverted
() * nPos3D;
107
GLC_Vector3d
delta= projected - projected2;
108
m_pViewport
->
cameraHandle
()->
translate
(delta);
109
}
110
111
if
(!qFuzzyCompare(userInput.
rotationAngle
(), 0))
112
{
113
GLC_Point
dummy(
m_pViewport
->
cameraHandle
()->
target
());
114
m_pViewport
->
setDistMinAndMax
(dummy.boundingBox());
115
116
GLC_Point2d
nPos=
m_pViewport
->
mapNormalyzeToOpenGLScreen
(x, y);
117
GLC_Point3d
nPos3D(nPos.
x
(), nPos.
y
(), 1.0);
118
GLC_Point3d
center=
m_pViewport
->
compositionMatrix
().
inverted
() * nPos3D;
119
120
GLC_Vector3d
axis=
m_pViewport
->
cameraHandle
()->
forward
();
121
122
m_pViewport
->
cameraHandle
()->
rotateAround
(axis, userInput.
rotationAngle
(), center);
123
}
124
125
if
(!userInput.
translation
().
isNull
())
126
{
127
double
transX= userInput.
translation
().
x
() *
m_pViewport
->
viewHSize
();
128
double
transY= userInput.
translation
().
y
() *
m_pViewport
->
viewVSize
();
129
130
GLC_Vector3d
mappedTranslation(-transX, -transY, 0.0);
131
// Compute the length of camera's field of view
132
const
double
ChampsVision =
m_pViewport
->
cameraHandle
()->
distEyeTarget
() *
m_pViewport
->
viewTangent
();
133
134
// the side of camera's square is mapped on Vertical length of window
135
// Ratio OpenGL/Pixel = dimend GL / dimens Pixel
136
const
double
Ratio= ChampsVision /
static_cast<
double
>
(
m_pViewport
->
viewVSize
());
137
138
mappedTranslation= mappedTranslation * Ratio;
139
m_pViewport
->
cameraHandle
()->
pan
(mappedTranslation);
140
}
141
142
return
true
;
143
}
144
©2005-2013 Laurent Ribon