Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glut.h>
- #include <math.h>
- #define janela_altura 400
- #define janela_largura 600
- #define PI 3.1415926535898
- float trans = 110;
- void display(void);
- void tela(GLsizei w, GLsizei h);
- void keyboard(unsigned char tecla, int x, int y);
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv); // suporte a janelas
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- // PADRAO DE CORES
- glutInitWindowSize(janela_largura, janela_altura); // tamanho da janela
- glutInitWindowPosition(100, 100); // posicao que surge a janela
- glutCreateWindow("colisao_circulos"); // cria janela
- //glutFullScreen();
- glutKeyboardFunc(&keyboard); // chama teclado
- glutReshapeFunc(tela); // configura a tela
- glutDisplayFunc(display);
- glutMainLoop(); // redesenhar
- return(0);
- }
- void keyboard(unsigned char tecla, int x, int y)
- {
- printf("\ntecla %c\n", tecla);
- printf("\n\nDigite 1 para esquerda: ");
- printf("\ntecla %c\n", tecla);
- printf("\no mouse estava em %d x %d\n", x, y);
- if (tecla == '1')
- {
- trans = trans - 1;
- printf("\n o valor de translacao e %.2f\n", trans);
- printf("\n a distancia entre o raio deles e 110");
- printf("\n o raio de cada circulo e 50 (50+50=100)");
- printf("\n portanto....");
- printf("\n o segundo circulo esta a %.2f de distancia", (trans - 100));
- }
- if (tecla == '2')
- {
- trans = trans + 1;
- printf("\n o valor de translacao e %.2f\n", &trans);
- }
- glutPostRedisplay();
- }
- void desenhar()
- {
- glLineWidth(2); // grossura da linha
- GLfloat circ_pnt = 100;
- GLfloat ang, raioX, raioY;
- glTranslatef(-100, 0, 0);
- circ_pnt = 100;
- raioX = 50.0f;
- raioY = 50.0f;
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < circ_pnt; i++)
- {
- glColor3f(1.0, 0.0, 0.0); // cor
- ang = (2 * PI * i) / circ_pnt;
- glVertex2f(cos(ang) * raioX, sin(ang) * raioY);
- }
- glEnd();
- glBegin(GL_LINES); /// linha para ter a base
- glVertex3f(0, 0, 0);
- glVertex3f(raioX, 0, 0);
- glEnd();
- glTranslatef(trans, 0, 0);
- circ_pnt = 100;
- raioX = 50.0;
- raioY = 50.0;
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < circ_pnt; i++)
- {
- glColor3f(1.0, 1.0, 0.0); // cor
- ang = (2 * PI * i) / circ_pnt;
- glVertex2f(cos(ang) * raioX, sin(ang) * raioY);
- }
- glEnd();
- glBegin(GL_LINES); // linha para ter a base
- glVertex3f(0, 0, 0);
- glVertex3f((raioX * (-1)), 0, 0);
- glEnd();
- }
- void display()
- {
- glMatrixMode(GL_MODELVIEW); //coordenadas de desenho
- glLoadIdentity();
- if (trans - 100 > 0)
- {
- glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // cor do fundo
- }
- else
- {
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // cor do fundo
- }
- glClear(GL_COLOR_BUFFER_BIT); // EXECUTA LIMPESA
- // Especificar o local aonde o desenho acontece: bem no centro da janela
- glTranslatef(janela_largura / 2, janela_altura / 2, 0.0f);
- glViewport(0, 0, janela_largura, janela_altura);
- desenhar();
- glFlush(); // execute o desenho
- }
- void tela(GLsizei w, GLsizei h)
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- // cria a janela (esq, direita, embaixo, em cima)
- gluOrtho2D(0, janela_largura, 0, janela_altura);
- glMatrixMode(GL_MODELVIEW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement