Advertisement
Guest User

Untitled

a guest
May 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /*
  2. * GLUT Shapes Demo
  3. *
  4. * Written by Nigel Stewart November 2003
  5. *
  6. * This program is test harness for the sphere, cone
  7. * and torus shapes in GLUT.
  8. *
  9. * Spinning wireframe and smooth shaded shapes are
  10. * displayed until the ESC or q key is pressed. The
  11. * number of geometry stacks and slices can be adjusted
  12. * using the + and - keys.
  13. */
  14.  
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22.  
  23. #ifdef __APPLE_CC__
  24. #include <GL/glut.h>
  25. #else
  26. #include <GL/glut.h>
  27. #endif
  28.  
  29. static int shoulderAngle = 0, elbowAngle = 0;
  30.  
  31. void special(int key, int x, int y)
  32. {
  33. switch (key)
  34. {
  35. case GLUT_KEY_LEFT:
  36. (elbowAngle += 5) %= 360;
  37. break;
  38. case GLUT_KEY_RIGHT:
  39. (elbowAngle -= 5) %= 360;
  40. break;
  41. case GLUT_KEY_UP:
  42. (shoulderAngle += 5) %= 360;
  43. break;
  44. case GLUT_KEY_DOWN:
  45. (shoulderAngle -= 5) %360;
  46. break;
  47. default: return;
  48. }
  49. glutPostRedisplay();
  50. }
  51.  
  52. void wireBox(GLdouble width, GLdouble height, GLdouble depth)
  53. {
  54. glPushMatrix();
  55. glScalef(width, height, depth);
  56. glutWireCube(1.0);
  57. glPopMatrix();
  58. }
  59. void display()
  60. {
  61. glClear(GL_COLOR_BUFFER_BIT);
  62. glMatrixMode(GL_MODELVIEW);
  63. glPushMatrix();
  64.  
  65. glRotated((GLfloat)shoulderAngle, 0.0, 0.0, 1.0);
  66. glTranslated(1.0, 0.0, 0.0);
  67. wireBox(2.0, 0.4, 1.0);
  68.  
  69. glTranslatef(1.0, 0.0, 0.0);
  70. glRotatef((GLfloat)elbowAngle, 0.0, 0.0, 1.0);
  71. glTranslatef(1.0, 0.0, 0.0);
  72. wireBox(2.0, 0.4, 1.0);
  73.  
  74. glPopMatrix();
  75. glFlush();
  76. }
  77. void reshape (GLint w, GLint h)
  78. {
  79. glViewport(0, 0, w, h);
  80. glMatrixMode(GL_PROJECTION);
  81. glLoadIdentity();
  82. glutPerspective(65.0, GLfloat(w)/GLfloat(h), 1.0, 20.0);
  83. }
  84. void init()
  85. {
  86. glShadeModel(GL_FLAT)
  87. glMatrixMode(GL_MODELVIEW);
  88. glLoadIdentity();
  89. gluLookAt(1,2,8, 0,0,0 0,1,0);
  90. }
  91. int main(int argc, char** argv)
  92. {
  93. glutInit(&argc, argv);
  94. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
  95. glutInitWindowPosition(80, 80);
  96. glutInitWindowSize(800, 600);
  97. glutCreateWindow("Robot Arm");
  98.  
  99. glutDisplayFunc(display);
  100. glutReshapeFunc(reshape);
  101. glutSpecialFunc(special);
  102. init();
  103. glutMainLoop();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement