Advertisement
Guest User

Untitled

a guest
May 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <GL/glut.h>
  6.  
  7.  
  8. static int shoulderAngle = 0, elbowAngle = 0, handAngle = 0;
  9.  
  10.  
  11. void special(int key, int, int) {
  12. switch (key) {
  13. case GLUT_KEY_LEFT: (elbowAngle += 5) %= 360; break;
  14. case GLUT_KEY_RIGHT: (elbowAngle -= 5) %= 360; break;
  15. case GLUT_KEY_UP: (shoulderAngle += 5) %= 360; break;
  16. case GLUT_KEY_DOWN: (shoulderAngle -= 5) %= 360; break;
  17. case GLUT_KEY_PAGE_DOWN: (handAngle += 5) %= 360; break;
  18. case GLUT_KEY_PAGE_UP: (handAngle -= 5) %= 360; break;
  19.  
  20. default: return;
  21. }
  22. glutPostRedisplay();
  23. }
  24.  
  25.  
  26. void wireBox(GLdouble width, GLdouble height, GLdouble depth) {
  27. glPushMatrix();
  28. glScalef(width, height, depth);
  29. glutSolidCube (1.0);
  30. //glutWireCube(1.0);
  31. glPopMatrix();
  32. }
  33.  
  34.  
  35. void display() {
  36.  
  37. glClear(GL_COLOR_BUFFER_BIT);
  38. glMatrixMode(GL_MODELVIEW);
  39. glPushMatrix();
  40.  
  41. glRotatef((GLfloat)shoulderAngle, 0.0, 0.0, 1.0);
  42. glTranslatef(1.0, 1.0, 0.0);
  43. wireBox(2.0, 0.4, 1.0);
  44.  
  45.  
  46. glTranslatef(1.0, 0.0, 0.0);
  47. glRotatef((GLfloat)elbowAngle, 1.0, 0.0, 0.0);
  48. glTranslatef(1.0, 0.0, 0.0);
  49. wireBox(2.0, 0.4, 1.0);
  50.  
  51. glTranslatef(1.0, 0.0, 0.0);
  52. glRotatef((GLfloat)handAngle, 0.0, 0.0, 1.0);
  53. glTranslatef(1.0, 0.0, 0.0);
  54. wireBox(2.0, 0.4, 1.0);
  55.  
  56.  
  57.  
  58. glTranslatef(1.0, 0.0, 0.0);
  59. glColor3f(21,0,2);
  60. glRotatef((GLfloat)handAngle, 1.0, 0.0, 1.0);
  61. glTranslatef(1.0, 0.0, 0.0);
  62. glutSolidSphere(1.0,10,10);
  63.  
  64. glTranslatef(1.0, 0.0, 0.0);
  65. glRotatef((GLfloat)handAngle, 0.0, 0.0, 1.0);
  66. glTranslatef(1.0, 0.0, 0.0);
  67. wireBox(2.0, 0.1, 0.1);
  68.  
  69.  
  70.  
  71.  
  72. glPopMatrix();
  73. glFlush();
  74. }
  75.  
  76.  
  77. void reshape(GLint w, GLint h) {
  78. glViewport(0, 0, w, h);
  79. glMatrixMode(GL_PROJECTION);
  80. glLoadIdentity();
  81. gluPerspective(65.0, GLfloat(w)/GLfloat(h), 1.0, 20.0);
  82. }
  83.  
  84.  
  85. void init() {
  86. glShadeModel(GL_FLAT);
  87. glMatrixMode(GL_MODELVIEW);
  88. glLoadIdentity();
  89. gluLookAt(1,2,8, 0,0,0, 0,1,0);
  90. }
  91.  
  92.  
  93. int main(int argc, char** argv) {
  94. glutInit(&argc, argv);
  95. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  96. glutInitWindowPosition(80, 80);
  97. glutInitWindowSize(800, 600);
  98. glutCreateWindow("Robot Arm");
  99. glutDisplayFunc(display);
  100. glutReshapeFunc(reshape);
  101. glutSpecialFunc(special);
  102. init();
  103. glutMainLoop();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement