Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. #ifdef __APPLE__
  2. #include <GLUT/glut.h>
  3. #else
  4. #include <GL/glut.h>
  5. #endif
  6.  
  7. #include <stdlib.h>
  8. #include <GL/glut.h>
  9. #include <iostream>
  10.  
  11. #include "constantes.h"
  12.  
  13. using namespace std;
  14.  
  15.  
  16. /*Inicializa parâmetros de rendering*/
  17. void Inicializa(void) {
  18. angle = 60.0;
  19. glClearColor(1.0f, 1.0f,1.0f,1.0f);
  20. //Usada para criar o volume de visualização
  21. glMatrixMode(GL_PROJECTION);
  22.  
  23. //Usada para permitir transformações (Trans., rot e scala)
  24. glMatrixMode(GL_MODELVIEW);
  25.  
  26. glLoadIdentity();
  27. glOrtho(-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);
  28. gluLookAt(eyex, eyey, eyez, 0, 0, 0, 0, 1, 0);
  29. }
  30.  
  31. /*Função usada para especificar o volume de visualização*/
  32. EspecificaParametrosVisualizacao(){
  33. //Usada para criar o volume de visualização
  34. glMatrixMode(GL_PROJECTION);
  35. glLoadIdentity();
  36.  
  37. //Usada para permitir transformações (Trans., rot e scala)
  38. gluPerspective(angle, fAspect, 0.1, 500);
  39. glMatrixMode(GL_MODELVIEW);
  40. glLoadIdentity();
  41.  
  42. gluLookAt(eyex, eyey, eyez, 0, 0, 0, 0, 1, 0);
  43. }
  44.  
  45. /*Função callback chamada quando o tamanho da janela é alterado*/
  46. void AlteraTamanhoJanela(GLsizei w, GLsizei h){
  47. if(h == 0){
  48. h = 1;
  49. }
  50. glViewport(0 ,0, w, h);
  51. fAspect = (GLfloat)w / (GLfloat)h;
  52. EspecificaParametrosVisualizacao();
  53. }
  54.  
  55. /*Função calback chamada para gerenciar eventos do mouse*/
  56. void GerenciaMouse(int button, int state, int x, int y){
  57. if (button == GLUT_LEFT_BUTTON){
  58. if(angle >= 10){
  59. angle -= 5;
  60. }
  61. }
  62. if (button == GLUT_RIGHT_BUTTON){
  63. if(angle <= 130){
  64. angle += 5;
  65. }
  66. }
  67. EspecificaParametrosVisualizacao();
  68. glutPostRedisplay();
  69. }
  70.  
  71. /*Configura teclas para interagir com o objeto */
  72. void teclas(unsigned char tecla, GLint x, GLint y){
  73. switch(tecla){
  74. case 'a':{
  75. eyex -=5.0;
  76. break;
  77. }
  78. case 'd':{
  79. eyex +=5.0;
  80. break;
  81. }
  82. case 's':{
  83. eyey -= 5.0;
  84. break;
  85. }
  86. case 'w':{
  87. eyey += 5.0;
  88. break;
  89. }
  90. }
  91. EspecificaParametrosVisualizacao();
  92. glutPostRedisplay();
  93. }
  94.  
  95. /*Função callbacl chamada para fazer o desenho*/
  96. void Desenha(void){
  97. glClear(GL_COLOR_BUFFER_BIT);
  98. glColor3f(0.0f, 0.0f, 1.0f);
  99.  
  100. glBegin(GL_LINES);
  101. glVertex3i(-40, -40, 0);
  102. glVertex3i(-40, 40, 0);
  103. glVertex3i(-40, 40, 0);
  104. glVertex3i(40, 40, 0);
  105. glVertex3i(40, 40, 0);
  106. glVertex3i(40, -40, 0);
  107. glVertex3i(40, -40, 0);
  108. glVertex3i(-40, -40, 0);
  109.  
  110. glVertex3i(-40, -40, 0);
  111. glVertex3i(-40, -40, -80);
  112. glVertex3i(-40, 40, 0);
  113. glVertex3i(-40, 40, -80);
  114. glVertex3i(40, 40, 0);
  115. glVertex3i(40, 40, -80);
  116. glVertex3i(40, -40, 0);
  117. glVertex3i(40, -40, -80);
  118.  
  119. glVertex3i(-40, -40, -80);
  120. glVertex3i(-40, 40, -80);
  121. glVertex3i(-40, 40, -80);
  122. glVertex3i(40, 40, -80);
  123. glVertex3i(40, 40, -80);
  124. glVertex3i(40, -40, -80);
  125. glVertex3i(40, -40, -80);
  126. glVertex3i(-40, -40, -80);
  127. glEnd();
  128. glutSwapBuffers();
  129. }
  130.  
  131. int main (int argc, char** argv) {
  132.  
  133. /*Inicializaçãod a tela*/
  134. glutInit(&argc, argv);
  135. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  136. glutInitWindowSize(640, 400);
  137. glutInitWindowPosition(700,30);
  138. glutCreateWindow("TP_2");
  139. glutKeyboardFunc(teclas);
  140. glutDisplayFunc(Desenha);
  141. glutReshapeFunc(AlteraTamanhoJanela);
  142. glutMouseFunc(GerenciaMouse);
  143.  
  144. Inicializa();
  145. glutMainLoop();
  146. return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement