-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.cpp
206 lines (160 loc) · 5.23 KB
/
window.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
#include "window.h"
#include <mediator.h>
#include <transform.h>
#include <stdio.h>
Window::Window(QGraphicsView* drawWindow)
{
this->drawWindow = drawWindow;
double width = drawWindow->geometry().width() / 2;
double height = drawWindow->geometry().height() / 2;
this->xwmin = -width;
this->ywmin = -height;
this->xwmax = width;
this->ywmax = height;
this->vup << new Coordinate(this->xwmin, this->ywmin) << new Coordinate(this->xwmin, this->ywmax);
this->viewport = new Viewport(450, drawWindow);
}
void Window::redraw(QList<GeometricShape*> objectsToDraw)
{
this->viewport->prepareToRedraw(this->xwmin, this->ywmin, this->xwmax, this->ywmax);
foreach(GeometricShape* geometricShape, objectsToDraw)
{
this->viewport->drawGeometricShape(geometricShape);
}
this->viewport->updateScene();
}
void Window::zoomIn(int percent)
{
if(this->xwmax - this->xwmin > percent * 2 && this->ywmax - this->ywmin > percent * 2)
{
this->xwmax -= percent;
this->xwmin += percent;
this->ywmax -= percent;
this->ywmin += percent;
this->redraw(Mediator::getInstance()->getCppGeometricShapes());
}
}
void Window::zoomOut(int percent)
{
this->xwmax += percent;
this->xwmin -= percent;
this->ywmax += percent;
this->ywmin -= percent;
this->redraw(Mediator::getInstance()->getCppGeometricShapes());
}
void Window::move(int u, mov_dir direction)
{
if(u != 0)
{
//Novas Coordenadas para o vup
double ax = this->vup[0]->getXAxisCoord() + u;
double ay = this->vup[0]->getYAxisCoord() + u;
double bx = this->vup[1]->getXAxisCoord() + u;
double by = this->vup[1]->getYAxisCoord() + u;
this->vup[0]->setXAxisCoord(ax);
this->vup[0]->setYAxisCoord(ay);
this->vup[1]->setXAxisCoord(bx);
this->vup[1]->setYAxisCoord(by);
float xvar = 0;
float yvar = 0;
if(direction == HORIZONTAL){
xvar = u;
}else{
// if(this->vup[0]->getYAxisCoord() > this->vup[1]->getYAxisCoord())
// u = -u;
yvar = u;
}
//movendo a window
this->xwmax += xvar;
this->xwmin += xvar;
this->ywmax += yvar;
this->ywmin += yvar;
//redesenhando os objetos
redraw(Mediator::getInstance()->getCppGeometricShapes());
}
}
//void Window::move(int u, mov_dir direction)
//{
// if(u != 0)
// {
// //Novas Coordenadas para o vup
// double ax = this->vup[0]->getXAxisCoord() + u;
// double ay = this->vup[0]->getYAxisCoord() + u;
// double bx = this->vup[1]->getXAxisCoord() + u;
// double by = this->vup[1]->getYAxisCoord() + u;
// this->vup[0]->setXAxisCoord(ax);
// this->vup[0]->setYAxisCoord(ay);
// this->vup[1]->setXAxisCoord(bx);
// this->vup[1]->setYAxisCoord(by);
// //Calculando vetor normalizado de vup com tamanho "u" e mesmo sentido
// float rx = bx - ax;
// float ry = by - ay;
// float sqrt1 = sqrt(rx*rx + ry*ry);
// float v[2] = {(bx - ax)/sqrt1, (by - ay)/sqrt1};
// //Calculando vetor ortorgonal a vup se a direção do movimento for horizontal
// if(direction == HORIZONTAL)
// {
// if(v[1]!=0)
// {
// v[1] = -v[0]/v[1];
// v[0] = 1;
// }
// else
// {
// v[0] = 0;
// v[1] = -1;
// }
// sqrt1 = sqrt(v[0]*v[0] + v[1]*v[1]);
// v[0] = v[0]/sqrt1;
// v[1] = v[1]/sqrt1;
// //Verifica se o vup está virado para baixo
// //se sim inverte a direção da movimentação
// if(this->vup[0]->getYAxisCoord() > this->vup[1]->getYAxisCoord())
// u = -u;
// }
// v[0] *= u;
// v[1] *= u;
// //movendo a window
// this->xwmax += v[0];
// this->xwmin += v[0];
// this->ywmax += v[1];
// this->ywmin += v[1];
// //redesenhando os objetos
// redraw(Mediator::getInstance()->getCppGeometricShapes());
// }
//}
//void Window::rotate(double angle)
//{
// Coordinate* coordA = this->vup[0];
// Coordinate* coordB = this->vup[1];
// float* wc = this->getCenter();
// float rx = wc[0];
// float ry = wc[1];
// Transform* t = Transform::getInstance();
// t->rotateGeometricShape(new Line(coordA, coordB), -angle, rx, ry);
// QList<GeometricShape*> objectsToRotate = Mediator::getInstance()->getCppGeometricShapes();
// foreach(GeometricShape* gs, objectsToRotate)
// {
// gs->calcCpp(angle, rx, ry);
// }
// this->redraw(objectsToRotate);
//}
float* Window::getCenter()
{
float rx = (this->xwmin + this->xwmax)/2;
float ry = (this->ywmin + this->ywmax)/2;
float a[2] = {rx, ry};
return a;
}
float Window::getAngle()
{
Coordinate* coordA = this->vup[0];
Coordinate* coordB = this->vup[1];
double v[2] = {coordB->getXAxisCoord() - coordA->getXAxisCoord(),
coordB->getYAxisCoord() - coordA->getYAxisCoord()};
float a = v[1] / sqrt(v[0]*v[0] + v[1]*v[1]);
a = acos(a)*(180/M_PI);
if(v[0] < 0)
a = -a;
return a;
}