-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
204 lines (174 loc) · 4.89 KB
/
main.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 <windows.h>
#ifdef __APPLE__
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector>
#include <time.h>
#include <math.h>
#define KEY_ESC 27
#include "rTree.cpp"
using namespace std;
const int N= 4;
int ID= 0;
bool flagObj=false;
objeto*nuevoObj;
float XX,YY,XX2,YY2;
bool flag=true;
//quad p( punto2D(0.0,0.0),punto2D(1.0,1.0),0);
rTree<N> p;
void OnMouseClick(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
cout<<(float)x/600<<" "<<(float)y/600<<endl;
if(flagObj)
nuevoObj->insertarPunto(punto2D((float)x/600,1.0-(float)(y)/600));
else{
nuevoObj=new objeto(0,punto2D((float)x/600,1.0-(float)(y)/600));
flagObj=true;
}
}else if (button == GLUT_RIGHT_BUTTON || button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
flag=false;
}
}
void OnMouseMotion(int x, int y)
{
XX=(float)x/600;
YY=1.0-(float)y/600;
XX2=XX+0.05;
YY2=YY+0.05;
XX=XX-0.05;
YY=YY-0.05;
flag=true;
//opcional
//hacer algo x,z cuando se mueve el mouse
}
void idle(){ // AGREGAR ESTA FUNCION
glutPostRedisplay();
}
//funcion llamada a cada imagen
void glPaint(void) {
//El fondo de la escena al color initial
glClear(GL_COLOR_BUFFER_BIT); //CAMBIO
glLoadIdentity();
glOrtho(0.0f, 300.0f,0.0f, 300.0f, -1.0f, 1.0f);
//dibujar quadTree (qt->draw())
p.draw();
if(flag){
//p.searchdraw2(XX,YY,XX2,YY2);
//p.searchdraw2beta(XX,YY,XX2,YY2);
glColor3d(255,0,0);
int h=(XX+XX2)*150;
int k=(YY+YY2)*150;
int r=(YY2-YY)*150;
double M_PI=3.14;
double PI2=M_PI*2;
glBegin(GL_LINE_LOOP);
for(int i=0;i<=50;++i){
glVertex2d(h+cos(i*PI2/50)*r,k+sin(i*PI2/50)*r);
}
glEnd();
p.buscarCircle(XX,YY,XX2,YY2);
//p.searchdrawcirculo(XX,YY,XX2,YY2);
}//dibuja el gizmo
//displayGizmo();
//doble buffer, mantener esta instruccion al fin de la funcion
glutSwapBuffers();
}
//
//inicializacion de OpenGL
//
void init_GL(void) {
//Color del fondo de la escena
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //(R, G, B, transparencia) en este caso un fondo negro
//modo projeccion
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
//en el caso que la ventana cambie de tamaño
GLvoid window_redraw(GLsizei width, GLsizei height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
GLvoid window_key(unsigned char key, int x, int y) {
switch (key) {
case KEY_ESC:
exit(0);
break;
case 13:
cout<<"enter"<<endl;
if (flagObj){
p.insertion(*nuevoObj);
flagObj=false;
}
break;
default:
break;
}
}
/* Program entry point */
int main(int argc, char *argv[])
{
colores.push_back(tripleta(255,0,0));
/*colores.push_back(tripleta(0,255,0));
colores.push_back(tripleta(0,0,255));
colores.push_back(tripleta(255,255,0));
colores.push_back(tripleta(255,0,255));
colores.push_back(tripleta(0,255,255));*/
/*objeto algo(0,punto2D(0.3,0.00));
algo.insertarPunto(punto2D(0.3,1.0));
algo.insertarPunto(punto2D(0.4,0.1));
p.insertion(algo);
objeto algo2(0,punto2D(0.1,0.6));
algo2.insertarPunto(punto2D(0.1,0.65));
algo2.insertarPunto(punto2D(0.4,0.7));
p.insertion(algo2);
objeto algo3(0,punto2D(0.5,0.0));
algo3.insertarPunto(punto2D(0.5,1));
algo3.insertarPunto(punto2D(0.6,0.4));
p.insertion(algo3);
objeto algo4(0,punto2D(0.5,0.7));
algo4.insertarPunto(punto2D(0.5,0.75));
algo4.insertarPunto(punto2D(0.7,0.8));
p.insertion(algo4);*/
/*objeto algo5(0,punto2D(0.15,0.15));
algo5.insertarPunto(punto2D(0.2,0.2));
algo5.insertarPunto(punto2D(0.1,0.1));
p.insertion(algo5);*/
//srand(time(0));
/*for(float i=0.0;i<1;i+=0.005){
p.insertar(punto2D(i,i));
p.insertar(punto2D(i,1.0-i));
//p.imprimir();
}
*/
/*for(int i=0;i<1000000;++i){
p.insertar(punto2D((float)rand()/RAND_MAX,(float)rand()/RAND_MAX));
}*/
//p.cargarImagen();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600); //tamaño de la ventana
glutInitWindowPosition(100, 100); //posicion de la ventana
glutCreateWindow("R-Tree"); //titulo de la ventana
init_GL(); //funcion de inicializacion de OpenGL
glutDisplayFunc(glPaint);
glutReshapeFunc(&window_redraw);
// Callback del teclado
glutKeyboardFunc(&window_key);
glutMouseFunc(&OnMouseClick);
glutMotionFunc(&OnMouseMotion);
glutIdleFunc(&idle);
//qt = new quadTree();
glutMainLoop(); //bucle de rendering
//no escribir nada abajo de mainloop
return 0;
}