-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColisãoCirculos
141 lines (112 loc) · 2.6 KB
/
ColisãoCirculos
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
#include <stdlib.h>
#include <GL/glut.h>
#include <iostream>
using namespace std;
#define janela_altura 600
#define janela_largura 600
void keyboard(unsigned char key, int x, int y);
void resize(GLsizei w, GLsizei h);
void display(void);
float xr = 1, yr = 1, trans = 110;
void movimentoSetas(int key, int x, int y) {
switch (key) {
case GLUT_KEY_UP:
yr++;
cout << y << endl;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN:
yr--;
cout << y << endl;
glutPostRedisplay();
break;
case GLUT_KEY_LEFT:
xr--;
cout << x << endl;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT:
xr++;
cout << x << endl;
glutPostRedisplay();
break;
}
}
int main(int arcg, char** arcv)
{
printf("Use as setas do teclado para movimentar");
glutInit(&arcg, arcv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(janela_altura, janela_largura);
glutInitWindowPosition(10, 300);
glutCreateWindow("Glut Colisão - Davi Calais Souza");
glutKeyboardFunc(&keyboard);
glutReshapeFunc(&resize);
glutDisplayFunc(display);
glutSpecialFunc(movimentoSetas);
glutMainLoop();
return EXIT_SUCCESS;
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case '\x1B':
exit(EXIT_SUCCESS);
break;
}
}
void resize(GLsizei w, GLsizei h)
{
if (h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h) {
gluOrtho2D(0.0f, janela_altura, 0.0f, janela_largura * h / w);
}
else {
gluOrtho2D(0.0f, janela_altura * w / h, 0.0f, janela_largura);
}
glMatrixMode(GL_MODELVIEW);
}
void display() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
float trans = sqrt((xr * xr) + (yr * yr));
if (trans <= 100) {
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
}
else {
glClearColor(0.0f, 1.0f, 1.0f, 0.0f);
}
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(janela_altura / 2, janela_largura / 2, 0);
GLfloat circ_pnt = 100;
GLfloat ang, raioX = 50.0f, raioY = 50.0f;
glBegin(GL_POLYGON);
glColor3f(1.0f, 1.0f, 1.0f);
for (int i = 0; i < circ_pnt; i++)
{
ang = (2 * 3.14 * i) / circ_pnt;
glVertex2f(cos(ang) * raioX, sin(ang) * raioY);
printf("%f %f\n", cos(ang) * raioX, sin(ang) * raioY);
}
glEnd();
glEnable(GL_POINT_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 1.0f);
for (int i = 0; i < circ_pnt; i++)
{
ang = (2 * 3.14 * i) / circ_pnt;
glVertex2f((cos(ang) * raioX) + xr, (sin(ang) * raioY) + yr);
printf("%f %f\n", cos(ang) * raioX, sin(ang) * raioY);
}
glEnd();
glFlush();
glutPostRedisplay();
glutSwapBuffers();
}