Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 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;
  8. int ang11 = 90, ang12 = 0, ang21 = 90, ang22 = 0;
  9.  
  10. void init(void) {
  11. glClearColor(0.0, 0.0, 0.0, 0.0);
  12. }
  13.  
  14. void display(void) {
  15. glClear(GL_COLOR_BUFFER_BIT);
  16. glPushMatrix();
  17.  
  18. //Esfera na origem
  19. glTranslatef(0.0, 0.0, 0.0);
  20. glutWireSphere(0.3, 10, 10);
  21.  
  22. //pinca 1
  23. glPushMatrix();
  24. glTranslatef(1.0, 0.0, 0.0);
  25. glPushMatrix();
  26. glRotatef((GLfloat) ang11, 0.0, 0.0, 1.0);
  27. glScalef(0.5, 4.0, 1.0);
  28. glutWireCube(0.5);
  29. glPopMatrix();
  30. glPushMatrix();
  31. glTranslatef(1.0, 1.0, 0.0);
  32. glRotatef((GLfloat)ang12, 0.0, 0.0, 1.0);
  33. glScalef(0.5, 4.0, 1.0);
  34. glutWireCube(0.5);
  35. glPopMatrix();
  36. //Retornando a origem
  37. glPopMatrix();
  38.  
  39. //pinca 2
  40. glPushMatrix();
  41. glTranslatef(0.0, 1.0, 0.0);
  42. glPushMatrix();
  43. glRotatef((GLfloat)ang21, 0.0, 0.0, 1.0);
  44. glScalef(4.0, 0.5, 1.0);
  45. glutWireCube(0.5);
  46. glPopMatrix();
  47. glPushMatrix();
  48. glTranslatef(1.0, 1.0, 0.0);
  49. glRotatef((GLfloat)ang22, 0.0, 0.0, 1.0);
  50. glScalef(4.0, 0.5, 1.0);
  51. glutWireCube(0.5);
  52. glPopMatrix();
  53. //Retornando a origem
  54. glPopMatrix();
  55. /* origem volta para o sistema de coordenadas original */
  56. glPopMatrix();
  57. glutSwapBuffers();
  58. }
  59.  
  60. void reshape(int w, int h) {
  61. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  62. glMatrixMode(GL_PROJECTION);
  63. glLoadIdentity();
  64. gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
  65. glMatrixMode(GL_MODELVIEW);
  66. glLoadIdentity();
  67. glTranslatef(0.0, 0.0, -5.0);
  68. }
  69.  
  70. void keyboard(unsigned char key, int x, int y) {
  71. switch (key) {
  72. case 'o':
  73. ang11 = (ang11 + 1) % 360;
  74. ang12 = (ang12 + 1) % 360;
  75. ang21 = (ang21 - 1) % 360;
  76. ang22 = (ang22 - 1) % 360;
  77. glutPostRedisplay();
  78. break;
  79. case 'O':
  80. ang11 = (ang11 - 1) % 360;
  81. ang12 = (ang12 - 1) % 360;
  82. ang21 = (ang21 + 1) % 360;
  83. ang22 = (ang22 + 1) % 360;
  84. glutPostRedisplay();
  85. break;
  86. case 27:
  87. exit(0);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93.  
  94. int main(int argc, char** argv) {
  95. glutInit(&argc, argv);
  96. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  97. glutInitWindowSize(800, 600);
  98. glutInitWindowPosition(100, 100);
  99. glutCreateWindow(argv[0]);
  100. init();
  101. glutDisplayFunc(display);
  102. glutReshapeFunc(reshape);
  103. glutKeyboardFunc(keyboard);
  104. glutMainLoop();
  105. return 0;
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement