forked from mhernando/Apolo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faceDesign.cpp
305 lines (248 loc) · 7.43 KB
/
faceDesign.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#include "faceDesign.h"
DEFINE_EVENT_TYPE(wxEVT_FACEVERTEX_ADDED)
DEFINE_EVENT_TYPE(wxEVT_ALIGN_DONE)
DEFINE_EVENT_TYPE(wxEVT_CHECK_FACEVERTEX)
DEFINE_EVENT_TYPE(wxEVT_FACEVERTEX_MOVED)
DEFINE_EVENT_TYPE(wxEVT_CHECK_POINT_SELECTED)
DEFINE_EVENT_TYPE(wxEVT_SET_NEW_POINT)
DEFINE_EVENT_TYPE(wxEVT_STARTED_MOVEMENT)
DEFINE_EVENT_TYPE(wxEVT_MOVEMENT_DONE)
BEGIN_EVENT_TABLE(FaceDesign, wxGLCanvas)
EVT_PAINT(FaceDesign::Paint)
EVT_LEFT_DOWN(FaceDesign::SelectedPoint)
EVT_RIGHT_DOWN(FaceDesign::startToMove)
EVT_RIGHT_UP(FaceDesign::finishMoving)
EVT_MIDDLE_DOWN(FaceDesign::CheckPoint)
EVT_MIDDLE_UP(FaceDesign::SetNewMovedPoint)
EVT_COMMAND(wxID_ANY,wxEVT_FACEVERTEX_ADDED,FaceDesign::AlignPoints)
EVT_COMMAND(wxID_ANY,wxEVT_CHECK_FACEVERTEX,FaceDesign::AlignPoints) //Cuando escogemos un punto a arrastrar también debemos calibrarlo para compararlo adecuadamente
EVT_COMMAND(wxID_ANY,wxEVT_FACEVERTEX_MOVED,FaceDesign::AlignPoints)//Cuando soltamos el punto movido también debe calibrarse
EVT_COMMAND(wxID_ANY,wxEVT_STARTED_MOVEMENT,FaceDesign::AlignPoints)//El punto a partir del que movemos la ventana se calibra
EVT_COMMAND(wxID_ANY,wxEVT_MOVEMENT_DONE,FaceDesign::AlignPoints) //El punto final al que movemos la ventana también se calibra
END_EVENT_TABLE()
FaceDesign::FaceDesign(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size)
:wxGLCanvas(parent,id,pos,size)
{
design.SetViewPoint(-5,-5,5,5);
window=parent;
previouszoom=100;
startN=false;
finishN=false;
align=false;
}
void FaceDesign::InitFaceDesign()
{
SetCurrent();
design.init();
}
void FaceDesign::CalculateScale()
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
Scale.x=x2Df-x2Di;
Scale.y=y2Df-y2Di;
}
void FaceDesign::ZoomChange(double zoom)
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
if (zoom<previouszoom) //estamos disminuyendo zoom
{
double aux=previouszoom-zoom;
x2Di=x2Di-0.05*aux;
x2Df=x2Df+0.05*aux;
y2Di=y2Di-0.05*aux;
y2Df=y2Df+0.05*aux;
}
if (zoom>previouszoom) //estamos aumentando zoom
{
double aux=zoom-previouszoom;
x2Di=x2Di+0.05*aux;
x2Df=x2Df-0.05*aux;
y2Di=y2Di+0.05*aux;
y2Df=y2Df-0.05*aux;
}
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
previouszoom=zoom;
}
void FaceDesign::SelectedPoint(wxMouseEvent& event)
{
Point = event.GetPosition();
if(event.LeftDown())
{
pointTomove=false;
setPointMoved=false;
wxCommandEvent DesignEvent( wxEVT_FACEVERTEX_ADDED,GetId() );
DesignEvent.SetEventObject( window);
GetEventHandler()->ProcessEvent(DesignEvent);
}
SetFocus();
event.Skip();
}
void FaceDesign::CheckPoint(wxMouseEvent& event)
//Función que se encargará de crear el evento cuando pulsamos el botón central del ratón y que conducirá al PointList para comprobar el punto
{
Point = event.GetPosition();
if(event.MiddleDown())
{
pointTomove=true;
setPointMoved=false;
wxCommandEvent DesignEvent( wxEVT_CHECK_FACEVERTEX,GetId() );
DesignEvent.SetEventObject( window);
GetEventHandler()->ProcessEvent(DesignEvent);
}
SetFocus();
event.Skip();
}
void FaceDesign::SetNewMovedPoint(wxMouseEvent& event)
//Función que se encargará de crear el evento cuando pulsamos el botón central del ratón y que conducirá al PointList para comprobar el punto
{
Point = event.GetPosition();
if(event.MiddleUp())
{
pointTomove=false;
setPointMoved=true;
wxCommandEvent DesignEvent( wxEVT_FACEVERTEX_MOVED,GetId() );
DesignEvent.SetEventObject( window);
GetEventHandler()->ProcessEvent(DesignEvent);
}
SetFocus();
event.Skip();
}
void FaceDesign::ClearObjects()
{
design.clearObjects();
}
void FaceDesign::AddObject(GLObject * obj)
{
design.addObject(obj);
}
void FaceDesign::UpdateWorld(World* w)
{
this->design.clearObjects();
this->design.addObject(w);
Refresh(false);
}
void FaceDesign::AlignPoints(wxCommandEvent& event)
{
wxSize SizeDesign;
Vector2D Transform;
this->CalculateScale();
SizeDesign=this->GetVirtualSize();
Point.x-=SizeDesign.GetWidth()/2;
Transform.x=SizeDesign.GetWidth()/Scale.x;
Point.y-=SizeDesign.GetHeight()/2;
Transform.y=SizeDesign.GetHeight()/Scale.y;
puntox=Point.x/Transform.x+((x2Di+x2Df)/2);
puntoy=-Point.y/Transform.y+((y2Di+y2Df)/2); //Cambiamos el signo para que se corresponda con la orientación de la ventana
//Crea el evento de alineación el cúal usará facewidget para añadir definitivamente el punto
if((pointTomove==true)&&(setPointMoved==false)) //Si estamos arrastrando el vértice
{
wxCommandEvent CheckingEvent(wxEVT_CHECK_POINT_SELECTED,GetId() );
CheckingEvent.SetEventObject(window);
GetEventHandler()->ProcessEvent(CheckingEvent);
}
else if((setPointMoved==true)&&(pointTomove==false)) //Si estamos fijando la nueva posición del vértice arrastrado
{
wxCommandEvent ChangingEvent(wxEVT_SET_NEW_POINT,GetId() );
ChangingEvent.SetEventObject(window);
GetEventHandler()->ProcessEvent(ChangingEvent);
}
else if((startN==true)||(finishN==true))
{
movementControl();
}
else //Estamos dibujando simplemente un vértice
{
wxCommandEvent AlignEvent(wxEVT_ALIGN_DONE,GetId() );
AlignEvent.SetEventObject(window);
GetEventHandler()->ProcessEvent(AlignEvent);
}
}
void FaceDesign::Paint(wxPaintEvent& event)
{
wxPaintDC(this);
SetCurrent();
design.Draw();
SwapBuffers();
}
void FaceDesign::startToMove(wxMouseEvent& event) //Clickeamos el punto que se toma como referencia para desplazar la ventana
{
if(event.RightDown())
{
Point = event.GetPosition();
startN=true;
finishN=false;
wxCommandEvent NavigateFirstEvent(wxEVT_STARTED_MOVEMENT,GetId() );
NavigateFirstEvent.SetEventObject(window);
GetEventHandler()->ProcessEvent(NavigateFirstEvent);
}
SetFocus();
event.Skip();
}
void FaceDesign::finishMoving(wxMouseEvent& event) //Cuando se deja de clickear se está estableciendo la nueva situación del punto
{
if(event.RightUp())
{
Point = event.GetPosition();
startN=false;
finishN=true;
wxCommandEvent NavigateFinalEvent(wxEVT_MOVEMENT_DONE,GetId() );
NavigateFinalEvent.SetEventObject(window);
GetEventHandler()->ProcessEvent(NavigateFinalEvent);
}
SetFocus();
event.Skip();
}
void FaceDesign::movementControl()
{
if (startN==true)
{
PointAux.x=puntox; //se guarda la componente X del punto calibrado en PointAux
PointAux.y=puntoy; //se guarda la componente Y del punto calibrado en PointAux
}
if (finishN==true)
{
double difx=PointAux.x-puntox; //se calcula el desplazamiento en la componenteX
double dify=PointAux.y-puntoy; //se calcula el desplazamiento en la componenteY
x2Di=x2Di+difx;
y2Di=y2Di+dify;
x2Df=x2Df+difx;
y2Df=y2Df+dify;
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
startN=false;
finishN=false;
Refresh();
}
}
void FaceDesign::ChangePosition(bool up,bool down,bool right,bool left)
{
if ((up==true)&&(down==true)) return; //no puede moverse arriba y abajo a la vez
if ((right==true)&&(left==true)) return; //no puede moverse a la izquierda y a la derecha a la vez
if (right==true)
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
x2Di=x2Di+0.5;
x2Df=x2Df+0.5;
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
}
if (left==true)
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
x2Di=x2Di-0.5;
x2Df=x2Df-0.5;
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
}
if (up==true)
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
y2Di=y2Di+0.5;
y2Df=y2Df+0.5;
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
}
if (down==true)
{
design.GetViewPoint(x2Di,y2Di,x2Df,y2Df);
y2Di=y2Di-0.5;
y2Df=y2Df-0.5;
design.SetViewPoint(x2Di,y2Di,x2Df,y2Df);
}
}