Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <time.h>
- #include <math.h>
- #if defined (__APPLE__) || defined(MACOSX)
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include "EstruturasDeDados.h"
- #include "winGL.h"
- int wLargura = 500,
- wAltura = 500;
- tPonto nuvemAsteroides[10];
- tPonto navePos;
- bool mostraNave = true,
- animacao = false,
- linha = false,
- desenhaQuad = false;
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void temporizar(int v) {
- navePos.x -= 5;
- if (navePos.x < 0)
- navePos.x = wLargura;
- navePos.y -= 2;
- if (navePos.y < 0 )
- navePos.y = wAltura;
- glutPostRedisplay();
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void idle() {
- if (animacao) {
- navePos.x += 3;
- if (navePos.x > wLargura)
- navePos.x = 0;
- navePos.y += 1;
- if (navePos.y > wAltura)
- navePos.y = 0;
- glutPostRedisplay();
- }
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void tecladoEspecial(int key, int x, int y) {
- switch (key) {
- case GLUT_KEY_UP : // setas do teclado
- break;
- case GLUT_KEY_DOWN : // setas do teclado
- break;
- case GLUT_KEY_LEFT : // setas do teclado
- break;
- case GLUT_KEY_RIGHT : // setas do teclado
- break;
- }
- glutPostRedisplay();
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void teclado(unsigned char key, int x, int y) {
- switch (key) {
- case 27 : exit(0);
- break;
- case 'l' :
- case 'L' : linha = !linha;
- break;
- case 'q' :
- case 'Q' : desenhaQuad = !desenhaQuad;
- break;
- case 'n' :
- case 'N' : mostraNave = !mostraNave;
- break;
- case 'R' :
- case 'r' : animacao = !animacao;
- break;
- case 't' :
- case 'T' : glutTimerFunc( 500, temporizar, 1);
- break;
- }
- glutPostRedisplay();
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void mouse(int button, int button_state, int x, int y ) {
- if (button_state == GLUT_DOWN ) {
- switch (button) {
- case GLUT_LEFT_BUTTON : printf("LEFT\n"); // faz alguma coisa quando o botao esquerdo for pressionado
- break;
- case GLUT_RIGHT_BUTTON : printf("RIGHT\n"); // faz alguma coisa quando o botao direito for pressionado
- break;
- }
- glutPostRedisplay();
- }
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- void desenho(void) {
- int i;
- tPonto max = { wLargura, wLargura };
- tPonto min = { 0, 0 };
- tPonto medio = { wLargura/2.0 , wLargura/2.0 };
- tPonto medio2 = { 0.0 , wLargura/2.0 };
- glClear(GL_COLOR_BUFFER_BIT);
- if (mostraNave)
- desenhaNave(navePos, RED);
- if (linha) {
- desenhaLinha(min, medio, BLUE);
- desenhaLinha(medio2, max, BLUE);
- }
- for (i = 0 ; i < 10 ; i++)
- desenhaAsteroide(nuvemAsteroides[i], 10.0, RED);
- if (desenhaQuad) {
- desenhaQuadrante(min, medio, GRAY);
- desenhaQuadrante(medio, max, GRAY);
- }
- glutSwapBuffers();
- }
- /// ***********************************************************************
- /// **
- /// ***********************************************************************
- int main(int argc, char** argv) {
- int i;
- srand ( time(NULL) );
- for (i = 0 ; i < 10 ; i++) {
- nuvemAsteroides[i].x = rand() % wLargura;
- nuvemAsteroides[i].y = rand() % wAltura;
- }
- navePos.x = wLargura / 2.0;
- navePos.y = wAltura / 2.0;
- criaJanela(argc, argv);
- initOpenGL();
- initEventos();
- return 0;
- }
Add Comment
Please, Sign In to add comment