Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 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 aBracoDir = 0, aBracoEsq = 0, bracoDir = -50, bracoEsq = 230, Lang11 = 90, Lang12 = 180, Lang21 = 90, Lang22 = 0, Rang11 = 90, Rang12 = 180, Rang21 = 90, Rang22 = 0;
  8. static int limitePincaDir = 0, limitePincaEsq = 0, limiteSimultaneo = 0, limiteBracoDir = 0, limiteBracoEsq = 0, limitePunhoDir = 0, limitePunhoEsq = 0, limitePassosLado = 0, limitePassosReto = 0;
  9. static int posX = 0, posZ = 0, posY = 0;
  10.  
  11. void init(void) {
  12. glClearColor(0.0, 0.0, 0.0, 0.0);
  13. }
  14.  
  15. void display(void) {
  16. glClear(GL_COLOR_BUFFER_BIT);
  17. glPushMatrix();
  18.  
  19. /*Plataforma servindo como chão*/
  20. glColor3f(0.6, 0.6, 0.6);
  21. glBegin(GL_QUADS);
  22. glVertex3f(-8.0, 0.0, 8.0);
  23. glVertex3f(8.0, 0.0, 8.0);
  24. glVertex3f(8.0, 0.0, -8.0);
  25. glVertex3f(-8.0, 0.0, -8.0);
  26. glEnd();
  27.  
  28. /* origem do corpo */
  29. glTranslatef(posX, posY, posZ);
  30. glColor3f(0.3f, 0.3f, 0.3f);
  31. glTranslatef(0.0, 0.0, 0.0);
  32. glPushMatrix();
  33. glScalef(2.0, 2.0, 1.5);
  34. glutSolidCube(1.0);
  35. glPopMatrix();
  36.  
  37. /* origem braço direito */
  38. glTranslatef(1.2, 0.7, 0.0);
  39. glRotatef((GLfloat)bracoDir, 0.0, 0.0, 1.0);
  40. glTranslatef(0.25, 0.0, 0.0);
  41. glPushMatrix();
  42. glScalef(2.0, 0.4, 1.0);
  43. glutSolidCube(0.5);
  44. glPopMatrix();
  45.  
  46. /* origem punho direito */
  47. glTranslatef(0.5, 0.0, 0.0);
  48. glRotatef((GLfloat)aBracoDir, 0.0, 0.0, 1.0);
  49. glTranslatef(0.25, 0.0, 0.0);
  50. glPushMatrix();
  51. glScalef(1.0, 0.4, 1.0);
  52. glutSolidCube(0.5);
  53. glPopMatrix();
  54.  
  55. glColor3f(0.0f, 1.0f, 0.2f);
  56. glTranslatef(0.3, 0.0, 0.0);
  57. glutSolidSphere(0.15, 10, 10);
  58.  
  59. //pinca 1 direito
  60. glColor3f(1.0f, 1.0f, 1.0f);
  61. glPushMatrix();
  62. glRotatef((GLfloat)Lang11, 0.0, 0.0, 1.0);
  63. glScalef(0.2, 4.0, 1.0);
  64. glTranslatef(0.0, -0.1, 0.0);
  65. glutSolidCube(0.2);
  66. glPopMatrix();
  67. glPushMatrix();
  68. glRotatef((GLfloat)Lang12, 0.0, 0.0, 1.0);
  69. glScalef(0.2, 4.0, 1.0);
  70. glTranslatef(-4.2, 0.1, 0.0);
  71. glutSolidCube(0.2);
  72. glPopMatrix();
  73.  
  74. //pinca 2 direito
  75. glPushMatrix();
  76. glRotatef((GLfloat)Lang12, 0.0, 0.0, -1.0);
  77. glScalef(0.2, 4.0, 1.0);
  78. glTranslatef(0.0, 0.1, 0.0);
  79. glutSolidCube(0.2);
  80. glPopMatrix();
  81. glPushMatrix();
  82. glRotatef((GLfloat)Lang11, 0.0, 0.0, -1.0);
  83. glScalef(0.2, 4.0, 1.0);
  84. glTranslatef(4.2, 0.1, 0.0);
  85. glutSolidCube(0.2);
  86. glPopMatrix();
  87.  
  88. glPopMatrix();
  89. glPushMatrix();
  90.  
  91. glTranslatef(posX, posY, posZ);
  92. /* origem braço esquerdo */
  93. glColor3f(0.3f, 0.3f, 0.3f);
  94. glTranslatef(-1.2, 0.7, 0.0);
  95. glRotatef((GLfloat)bracoEsq, 0.0, 0.0, 1.0);
  96. glTranslatef(0.25, 0.0, 0.0);
  97. glPushMatrix();
  98. glScalef(2.0, 0.4, 1.0);
  99. glutSolidCube(0.5);
  100. glPopMatrix();
  101.  
  102. /* origem punho esquerdo */
  103. glTranslatef(0.5, 0.0, 0.0);
  104. glRotatef((GLfloat)aBracoEsq, 0.0, 0.0, 1.0);
  105. glTranslatef(0.25, 0.0, 0.0);
  106. glPushMatrix();
  107. glScalef(1.0, 0.4, 1.0);
  108. glutSolidCube(0.5);
  109. glPopMatrix();
  110.  
  111. glColor3f(0.0f, 1.0f, 0.2f);
  112. glTranslatef(0.3, 0.0, 0.0);
  113. glutSolidSphere(0.15, 10, 10);
  114.  
  115. //pinca 1 esquerda
  116. glColor3f(1.0f, 1.0f, 1.0f);
  117. glPushMatrix();
  118. glRotatef((GLfloat)Rang11, 0.0, 0.0, 1.0);
  119. glScalef(0.2, 4.0, 1.0);
  120. glTranslatef(0.0, -0.1, 0.0);
  121. glutSolidCube(0.2);
  122. glPopMatrix();
  123. glPushMatrix();
  124. glRotatef((GLfloat)Rang12, 0.0, 0.0, 1.0);
  125. glScalef(0.2, 4.0, 1.0);
  126. glTranslatef(-4.2, 0.1, 0.0);
  127. glutSolidCube(0.2);
  128. glPopMatrix();
  129.  
  130. //pinca 2 esquerda
  131. glPushMatrix();
  132. glRotatef((GLfloat)Rang12, 0.0, 0.0, -1.0);
  133. glScalef(0.2, 4.0, 1.0);
  134. glTranslatef(0.0, 0.1, 0.0);
  135. glutSolidCube(0.2);
  136. glPopMatrix();
  137. glPushMatrix();
  138. glRotatef((GLfloat)Rang11, 0.0, 0.0, -1.0);
  139. glScalef(0.2, 4.0, 1.0);
  140. glTranslatef(4.2, 0.1, 0.0);
  141. glutSolidCube(0.2);
  142. glPopMatrix();
  143.  
  144. glPopMatrix();
  145. glPushMatrix();
  146.  
  147. /* origem cabeca */
  148. glTranslatef(posX, posY, posZ);
  149. glColor3f(0.1f, 0.1f, 0.1f);
  150. glTranslatef(0.0, 0.0, 0.0);
  151. glTranslatef(0.0, 1.3, 0.0);
  152. glPushMatrix();
  153. glScalef(2.4, 2.4, 1.4);
  154. glutSolidCube(0.3);
  155. glPopMatrix();
  156.  
  157. glColor3f(0.5f, 0.3f, 1.0f);
  158. glTranslatef(-0.22, 0.0, 0.0);
  159. glutSolidSphere(0.07, 10, 10);
  160.  
  161. glTranslatef(0.0, 0.0, 0.0);
  162. glTranslatef(0.42, 0.0, 0.0);
  163. glutSolidSphere(0.07, 10, 10);
  164.  
  165. /* origem volta para o sistema de coordenadas original */
  166. glPopMatrix();
  167. glutSwapBuffers();
  168.  
  169. }
  170.  
  171. void reshape(int w, int h) {
  172. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  173. glMatrixMode(GL_PROJECTION);
  174. glLoadIdentity();
  175. gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
  176. glMatrixMode(GL_MODELVIEW);
  177. glLoadIdentity();
  178. gluLookAt(2, 2, -10, 0, 0, 0, 0, 1, 0);
  179. }
  180.  
  181. void keyboard(unsigned char key, int x, int y) {
  182. switch (key) {
  183. case 's':
  184. if (limiteBracoDir < 15) {
  185. bracoDir = (bracoDir + 5) % 360;
  186. glutPostRedisplay();
  187. limiteBracoDir++;
  188. }
  189. break;
  190. case 'S':
  191. if (limiteBracoDir > 0) {
  192. bracoDir = (bracoDir - 5) % 360;
  193. glutPostRedisplay();
  194. limiteBracoDir--;
  195. }
  196. break;
  197. case 'w':
  198. if (limiteBracoEsq < 15) {
  199. bracoEsq = (bracoEsq - 5) % 360;
  200. glutPostRedisplay();
  201. limiteBracoEsq++;
  202. }
  203. break;
  204. case 'W':
  205. if (limiteBracoEsq > 0) {
  206. bracoEsq = (bracoEsq + 5) % 360;
  207. glutPostRedisplay();
  208. limiteBracoEsq--;
  209. }
  210. break;
  211. case 'd':
  212. if (limitePunhoDir < 20) {
  213. aBracoDir = (aBracoDir - 5) % 360;
  214. glutPostRedisplay();
  215. limitePunhoDir++;
  216. }
  217. break;
  218. case 'D':
  219. if (limitePunhoDir > -20) {
  220. aBracoDir = (aBracoDir + 5) % 360;
  221. glutPostRedisplay();
  222. limitePunhoDir--;
  223. }
  224. break;
  225. case 'e':
  226. if (limitePunhoEsq < 20) {
  227. aBracoEsq = (aBracoEsq - 5) % 360;
  228. glutPostRedisplay();
  229. limitePunhoEsq++;
  230. }
  231. break;
  232. case 'E':
  233. if (limitePunhoEsq > -20) {
  234. aBracoEsq = (aBracoEsq + 5) % 360;
  235. glutPostRedisplay();
  236. limitePunhoEsq--;
  237. }
  238. break;
  239. case 'r':
  240. if (limitePincaDir < 15) {
  241. Rang11 = (Rang11 + 2) % 360;
  242. Rang12 = (Rang12 + 2) % 360;
  243. Rang21 = (Rang21 - 2) % 360;
  244. Rang22 = (Rang22 - 2) % 360;
  245. glutPostRedisplay();
  246. limitePincaDir++;
  247. }
  248. break;
  249. case 'R':
  250. if (limitePincaDir > 0) {
  251. Rang11 = (Rang11 - 2) % 360;
  252. Rang12 = (Rang12 - 2) % 360;
  253. Rang21 = (Rang21 + 2) % 360;
  254. Rang22 = (Rang22 + 2) % 360;
  255. glutPostRedisplay();
  256. limitePincaDir--;
  257. }
  258. break;
  259. case 'f':
  260. if (limitePincaEsq < 15) {
  261. Lang11 = (Lang11 + 2) % 360;
  262. Lang12 = (Lang12 + 2) % 360;
  263. Lang21 = (Lang21 - 2) % 360;
  264. Lang22 = (Lang22 - 2) % 360;
  265. glutPostRedisplay();
  266. limitePincaEsq++;
  267. }
  268. break;
  269. case 'F':
  270. if (limitePincaEsq > 0) {
  271. Lang11 = (Lang11 - 2) % 360;
  272. Lang12 = (Lang12 - 2) % 360;
  273. Lang21 = (Lang21 + 2) % 360;
  274. Lang22 = (Lang22 + 2) % 360;
  275. glutPostRedisplay();
  276. limitePincaEsq--;
  277. }
  278. break;
  279. case 'j':
  280. if (limitePassosLado > -6) {
  281. posX = (posX + 1) % 360;
  282. glutPostRedisplay();
  283. limitePassosLado--;
  284. }
  285. break;
  286. case 'l':
  287. if (limitePassosLado < 6) {
  288. posX = (posX - 1) % 360;
  289. glutPostRedisplay();
  290. limitePassosLado++;
  291. }
  292. break;
  293. case 'i':
  294. if (limitePassosReto > -8) {
  295. posZ = (posZ + 1) % 360;
  296. glutPostRedisplay();
  297. limitePassosReto--;
  298. }
  299. break;
  300. case 'k':
  301. if (limitePassosReto < 5) {
  302. posZ = (posZ - 1) % 360;
  303. glutPostRedisplay();
  304. limitePassosReto++;
  305. }
  306. break;
  307. case 27:
  308. exit(0);
  309. break;
  310. default:
  311. break;
  312. }
  313. }
  314.  
  315. int main(int argc, char** argv) {
  316. glutInit(&argc, argv);
  317. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  318. glutInitWindowSize(800, 600);
  319. glutInitWindowPosition(100, 100);
  320. glutCreateWindow(argv[0]);
  321. init();
  322. glutDisplayFunc(display);
  323. glutReshapeFunc(reshape);
  324. glutKeyboardFunc(keyboard);
  325. glutMainLoop();
  326. return 0;
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement