Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include<windows.h>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <GL/glut.h>
  5. using namespace std;
  6.  
  7. static int posXcorpo = 0, posZcorpo = 0, posYcorpo = 0, cabeca=0;
  8.  
  9. void init(void) {
  10. glClearColor(0.0, 0.0, 0.0, 0.0);
  11. }
  12.  
  13. void display(void) {
  14. glClear(GL_COLOR_BUFFER_BIT);
  15. glColor3f(0.9f, 0.9f, 0.9f);
  16. glPushMatrix();
  17. /*Plataforma servindo como chΓ£o*/
  18. glColor3f(1.0, 1.0, 1.0);
  19. glBegin(GL_QUADS);
  20. glVertex3f(-3.0, -3.0, 0.0);
  21. glVertex3f(3.0, -3.0, 0.0);
  22. glVertex3f(3.0, -1.0, 0.0);
  23. glVertex3f(-3.0, -1.0, 0.0);
  24. glEnd();
  25. glFlush();
  26. /* origem do corpo */
  27. glTranslatef(0.0, 0.0, 0.0);
  28. glTranslatef(posXcorpo, posYcorpo, posZcorpo);
  29. glPushMatrix();
  30. glScalef(2.0, 2.0, 1.5);
  31. glutWireCube(1.0);
  32. glPopMatrix();
  33.  
  34. /* origem da cabeca */
  35. glRotatef((GLfloat)cabeca, 0.0, 1.0, 0.0);
  36. glTranslatef(0.0, 1.38, 0.0);
  37. glPushMatrix();
  38. glScalef(2.4, 2.4, 1.0);
  39. glutWireCube(0.3);
  40. glPopMatrix();
  41.  
  42. /* origem da ombro direito */
  43. glTranslatef(0.0, 0.0, 0.0);
  44. glTranslatef(1.25, -2.3, 0.2);
  45. glTranslatef(0.0, 1.5, 0.0);
  46. glPushMatrix();
  47. glScalef(1.0, 1.0, 1.0);
  48. glutSolidSphere(0.3,20,20);
  49. glPopMatrix();
  50.  
  51. /* origem da ombro esquerdo */
  52. glTranslatef(0.0, 0.0, 0.0);
  53. glTranslatef(-2.3, -0.25, 0.2);
  54. //glTranslatef(0.0, -1.5, 0.0);
  55. glPushMatrix();
  56. glScalef(1.0, 1.0, 1.0);
  57. glutSolidSphere(0.3, 20, 20);
  58. glPopMatrix();
  59.  
  60. /* origem volta para o sistema de coordenadas original */
  61. glPopMatrix();
  62. glutSwapBuffers();
  63. }
  64.  
  65. void reshape(int w, int h) {
  66. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  67. glMatrixMode(GL_PROJECTION);
  68. glLoadIdentity();
  69. gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
  70. glMatrixMode(GL_MODELVIEW);
  71. glLoadIdentity();
  72. glTranslatef(0.0, 0.0, -5.0);
  73. }
  74.  
  75. void keyboard(unsigned char key, int x, int y) {
  76. switch (key) {
  77. case 'x':
  78. posXcorpo = (posXcorpo + 1) % 360;
  79. glutPostRedisplay();
  80. break;
  81. case 'X':
  82. posXcorpo = (posXcorpo - 1) % 360;
  83. glutPostRedisplay();
  84. break;
  85. case 'z':
  86. posZcorpo = (posZcorpo + 1) % 360;
  87. glutPostRedisplay();
  88. break;
  89. case 'Z':
  90. posZcorpo = (posZcorpo - 1) % 360;
  91. glutPostRedisplay();
  92. break;
  93. case 'y':
  94. posYcorpo = (posYcorpo + 1) % 360;
  95. glutPostRedisplay();
  96. break;
  97. case 'Y':
  98. posYcorpo = (posYcorpo - 1) % 360;
  99. glutPostRedisplay();
  100. break;
  101. case 27:
  102. exit(0);
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108.  
  109. int main(int argc, char** argv) {
  110. glutInit(&argc, argv);
  111. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  112. glutInitWindowSize(800, 600);
  113. glutInitWindowPosition(100, 100);
  114. glutCreateWindow(argv[0]);
  115. init();
  116. glutDisplayFunc(display);
  117. glutReshapeFunc(reshape);
  118. glutKeyboardFunc(keyboard);
  119. glutMainLoop();
  120. return 0;
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement