Moka controlers
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
controler-input-events.cc
Go to the documentation of this file.
1
/*
2
* lib-controler : Un contrôleur générique de scène 3D.
3
* Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4
* http://www.sic.sp2mi.univ-poitiers.fr/
5
* Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6
* guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7
*
8
* This file is part of lib-controler
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
//******************************************************************************
25
#include "
controler.hh
"
26
#include "
view-precompile.hh
"
27
//******************************************************************************
28
TMode
CControler::getMode
()
const
29
{
return
FCurrentMode
; }
30
//******************************************************************************
31
void
CControler::setMode
(
TMode
AMode)
32
{
33
if
(AMode ==
FCurrentMode
)
34
return
;
35
36
// Sortie du mode courant :
37
exitMode
();
38
39
// Entrée dans le nouveau mode :
40
FCurrentMode
= AMode;
41
42
// Fonction à exécuter pour entrer dans le mode.
43
onEnterMode
();
44
}
45
//******************************************************************************
46
void
CControler::toggleMode
(
TMode
AMode)
47
{
48
if
(AMode ==
FCurrentMode
)
setMode
(
MODE_DEFAULT
);
49
else
setMode
(AMode);
50
}
51
//******************************************************************************
52
void
CControler::exitMode
()
53
{
54
// Sortie de l'opération courante
55
operationModeStop
(0,0);
56
57
// Fonction à exécuter pour sortir du mode.
58
onExitMode
();
59
60
// Revenir au mode par defaut
61
FCurrentMode
=
MODE_DEFAULT
;
62
}
63
//******************************************************************************
64
void
CControler::onEnterMode
()
65
{
66
switch
(
FCurrentMode
)
67
{
68
case
MODE_SELECTION
:
modeSelectionBegin
();
break
;
69
}
70
}
71
//------------------------------------------------------------------------------
72
void
CControler::onExitMode
()
73
{
74
switch
(
FCurrentMode
)
75
{
76
case
MODE_SELECTION
:
modeSelectionEnd
();
break
;
77
}
78
}
79
//******************************************************************************
80
void
CControler::onOperationModeStart
()
81
{
82
switch
(
FCurrentMode
)
83
{
84
case
MODE_SELECTION
:
85
FCurrentModeOperation
=
MODE_OPERATION_SELECTION
;
86
modeSelectionOperationStart
();
87
break
;
88
}
89
}
90
//------------------------------------------------------------------------------
91
void
CControler::onOperationModeMove
()
92
{
93
switch
(
FCurrentModeOperation
)
94
{
95
case
MODE_OPERATION_SELECTION
:
modeSelectionOperationMove
();
96
break
;
97
case
MODE_OPERATION_SCENE_TRANSLATION
:
modeSceneTranslationOperationMove
();
98
break
;
99
case
MODE_OPERATION_SCENE_ROTATION
:
modeSceneRotationOperationMove
();
100
break
;
101
case
MODE_OPERATION_SCENE_SCALE
:
modeSceneScaleOperationMove
();
102
break
;
103
}
104
}
105
//------------------------------------------------------------------------------
106
void
CControler::onOperationModeStop
()
107
{
108
switch
(
FCurrentModeOperation
)
109
{
110
case
MODE_OPERATION_SELECTION
:
modeSelectionOperationStop
();
break
;
111
case
MODE_OPERATION_SCENE_TRANSLATION
:
112
case
MODE_OPERATION_SCENE_ROTATION
:
113
case
MODE_OPERATION_SCENE_SCALE
:
modeSceneTransformationOperationStop
();
114
break
;
115
}
116
}
117
//******************************************************************************
118
void
CControler::operationModeStart
(
TViewId
AViewId,
int
Ax,
int
Ay)
119
{
120
if
(
FCurrentModeOperation
!=
MODE_OPERATION_NONE
)
121
operationModeStop
(
FLastX
,
FLastY
);
122
123
assert(
FViews
[AViewId] != NULL);
124
125
FCurrentViewId
= AViewId;
126
FFirstX
=
FLastX
= Ax;
FDeltaX
= 0;
127
FFirstY
=
FLastY
= Ay;
FDeltaY
= 0;
128
129
// Fonction à exécuter quand on commence une opération d'un mode.
130
onOperationModeStart
();
131
}
132
//------------------------------------------------------------------------------
133
void
CControler::operationModeMove
(
int
Ax,
int
Ay)
134
{
135
if
(
FCurrentModeOperation
==
MODE_OPERATION_NONE
)
return
;
136
137
FLastX
= Ax;
FDeltaX
=
FLastX
-
FFirstX
;
138
FLastY
= Ay;
FDeltaY
=
FLastY
-
FFirstY
;
139
140
// Fonction à exécuter au milieu d'une opération d'un mode.
141
onOperationModeMove
();
142
}
143
//------------------------------------------------------------------------------
144
void
CControler::operationModeStop
(
int
Ax,
int
Ay)
145
{
146
if
(
FCurrentModeOperation
==
MODE_OPERATION_NONE
)
return
;
147
148
FLastX
= Ax;
FDeltaX
=
FLastX
-
FFirstX
;
149
FLastY
= Ay;
FDeltaY
=
FLastY
-
FFirstY
;
150
151
// Fonction à exécuter quand on termine une opération d'un mode.
152
onOperationModeStop
();
153
154
155
// On arête l'opération.
156
FCurrentModeOperation
=
MODE_OPERATION_NONE
;
157
}
158
//******************************************************************************
159
void
CControler::operationModeIndependentStart
(
TModeOperation
AOperation,
160
TViewId
AViewId,
161
int
Ax,
int
Ay )
162
{
163
if
(
FCurrentModeOperation
!=
MODE_OPERATION_NONE
||
164
( AOperation!=
MODE_OPERATION_SCENE_TRANSLATION
&&
165
AOperation!=
MODE_OPERATION_SCENE_ROTATION
&&
166
AOperation!=
MODE_OPERATION_SCENE_SCALE
))
167
return
;
168
169
FCurrentModeOperation
= AOperation;
170
171
FCurrentViewId
= AViewId;
172
173
FFirstX
=
FLastX
= Ax;
FDeltaX
= 0;
174
FFirstY
=
FLastY
= Ay;
FDeltaY
= 0;
175
176
CViewPrecompile
* view =
FViews
[
FCurrentViewId
];
177
assert(view != NULL);
178
179
FMemoEyePosition
= view->
getEyePosition
();
180
FMemoAimedPosition
= view->
getAimedPosition
();
181
182
view->
unproject
(
FFirstX
,
FFirstY
,
FFirst3D
);
183
}
184
//******************************************************************************
lib-controler
controler-input-events.cc
Generated on Tue Apr 9 2013 09:51:16 for Moka controlers by
1.8.2