Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include <iostream>
- #include <stdlib.h>
- #include <GL/glut.h>
- using namespace std;
- 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;
- static int limitePincaDir = 0, limitePincaEsq = 0, limiteSimultaneo = 0, limiteBracoDir = 0, limiteBracoEsq = 0, limitePunhoDir = 0, limitePunhoEsq = 0, limitePassosLado = 0, limitePassosReto = 0;
- static int posX = 0, posZ = 0, posY = 0;
- void init(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- }
- void display(void) {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- /*Plataforma servindo como chão*/
- glColor3f(0.6, 0.6, 0.6);
- glBegin(GL_QUADS);
- glVertex3f(-8.0, 0.0, 8.0);
- glVertex3f(8.0, 0.0, 8.0);
- glVertex3f(8.0, 0.0, -8.0);
- glVertex3f(-8.0, 0.0, -8.0);
- glEnd();
- /* origem do corpo */
- glTranslatef(posX, posY, posZ);
- glColor3f(0.3f, 0.3f, 0.3f);
- glTranslatef(0.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 2.0, 1.5);
- glutSolidCube(1.0);
- glPopMatrix();
- /* origem braço direito */
- glTranslatef(1.2, 0.7, 0.0);
- glRotatef((GLfloat)bracoDir, 0.0, 0.0, 1.0);
- glTranslatef(0.25, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.4, 1.0);
- glutSolidCube(0.5);
- glPopMatrix();
- /* origem punho direito */
- glTranslatef(0.5, 0.0, 0.0);
- glRotatef((GLfloat)aBracoDir, 0.0, 0.0, 1.0);
- glTranslatef(0.25, 0.0, 0.0);
- glPushMatrix();
- glScalef(1.0, 0.4, 1.0);
- glutSolidCube(0.5);
- glPopMatrix();
- glColor3f(0.0f, 1.0f, 0.2f);
- glTranslatef(0.3, 0.0, 0.0);
- glutSolidSphere(0.15, 10, 10);
- //pinca 1 direito
- glColor3f(1.0f, 1.0f, 1.0f);
- glPushMatrix();
- glRotatef((GLfloat)Lang11, 0.0, 0.0, 1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(0.0, -0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPushMatrix();
- glRotatef((GLfloat)Lang12, 0.0, 0.0, 1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(-4.2, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- //pinca 2 direito
- glPushMatrix();
- glRotatef((GLfloat)Lang12, 0.0, 0.0, -1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(0.0, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPushMatrix();
- glRotatef((GLfloat)Lang11, 0.0, 0.0, -1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(4.2, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(posX, posY, posZ);
- /* origem braço esquerdo */
- glColor3f(0.3f, 0.3f, 0.3f);
- glTranslatef(-1.2, 0.7, 0.0);
- glRotatef((GLfloat)bracoEsq, 0.0, 0.0, 1.0);
- glTranslatef(0.25, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.4, 1.0);
- glutSolidCube(0.5);
- glPopMatrix();
- /* origem punho esquerdo */
- glTranslatef(0.5, 0.0, 0.0);
- glRotatef((GLfloat)aBracoEsq, 0.0, 0.0, 1.0);
- glTranslatef(0.25, 0.0, 0.0);
- glPushMatrix();
- glScalef(1.0, 0.4, 1.0);
- glutSolidCube(0.5);
- glPopMatrix();
- glColor3f(0.0f, 1.0f, 0.2f);
- glTranslatef(0.3, 0.0, 0.0);
- glutSolidSphere(0.15, 10, 10);
- //pinca 1 esquerda
- glColor3f(1.0f, 1.0f, 1.0f);
- glPushMatrix();
- glRotatef((GLfloat)Rang11, 0.0, 0.0, 1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(0.0, -0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPushMatrix();
- glRotatef((GLfloat)Rang12, 0.0, 0.0, 1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(-4.2, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- //pinca 2 esquerda
- glPushMatrix();
- glRotatef((GLfloat)Rang12, 0.0, 0.0, -1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(0.0, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPushMatrix();
- glRotatef((GLfloat)Rang11, 0.0, 0.0, -1.0);
- glScalef(0.2, 4.0, 1.0);
- glTranslatef(4.2, 0.1, 0.0);
- glutSolidCube(0.2);
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- /* origem cabeca */
- glTranslatef(posX, posY, posZ);
- glColor3f(0.1f, 0.1f, 0.1f);
- glTranslatef(0.0, 0.0, 0.0);
- glTranslatef(0.0, 1.3, 0.0);
- glPushMatrix();
- glScalef(2.4, 2.4, 1.4);
- glutSolidCube(0.3);
- glPopMatrix();
- glColor3f(0.5f, 0.3f, 1.0f);
- glTranslatef(-0.22, 0.0, 0.0);
- glutSolidSphere(0.07, 10, 10);
- glTranslatef(0.0, 0.0, 0.0);
- glTranslatef(0.42, 0.0, 0.0);
- glutSolidSphere(0.07, 10, 10);
- /* origem volta para o sistema de coordenadas original */
- glPopMatrix();
- glutSwapBuffers();
- }
- void reshape(int w, int h) {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(2, 2, -10, 0, 0, 0, 0, 1, 0);
- }
- void keyboard(unsigned char key, int x, int y) {
- switch (key) {
- case 's':
- if (limiteBracoDir < 15) {
- bracoDir = (bracoDir + 5) % 360;
- glutPostRedisplay();
- limiteBracoDir++;
- }
- break;
- case 'S':
- if (limiteBracoDir > 0) {
- bracoDir = (bracoDir - 5) % 360;
- glutPostRedisplay();
- limiteBracoDir--;
- }
- break;
- case 'w':
- if (limiteBracoEsq < 15) {
- bracoEsq = (bracoEsq - 5) % 360;
- glutPostRedisplay();
- limiteBracoEsq++;
- }
- break;
- case 'W':
- if (limiteBracoEsq > 0) {
- bracoEsq = (bracoEsq + 5) % 360;
- glutPostRedisplay();
- limiteBracoEsq--;
- }
- break;
- case 'd':
- if (limitePunhoDir < 20) {
- aBracoDir = (aBracoDir - 5) % 360;
- glutPostRedisplay();
- limitePunhoDir++;
- }
- break;
- case 'D':
- if (limitePunhoDir > -20) {
- aBracoDir = (aBracoDir + 5) % 360;
- glutPostRedisplay();
- limitePunhoDir--;
- }
- break;
- case 'e':
- if (limitePunhoEsq < 20) {
- aBracoEsq = (aBracoEsq - 5) % 360;
- glutPostRedisplay();
- limitePunhoEsq++;
- }
- break;
- case 'E':
- if (limitePunhoEsq > -20) {
- aBracoEsq = (aBracoEsq + 5) % 360;
- glutPostRedisplay();
- limitePunhoEsq--;
- }
- break;
- case 'r':
- if (limitePincaDir < 15) {
- Rang11 = (Rang11 + 2) % 360;
- Rang12 = (Rang12 + 2) % 360;
- Rang21 = (Rang21 - 2) % 360;
- Rang22 = (Rang22 - 2) % 360;
- glutPostRedisplay();
- limitePincaDir++;
- }
- break;
- case 'R':
- if (limitePincaDir > 0) {
- Rang11 = (Rang11 - 2) % 360;
- Rang12 = (Rang12 - 2) % 360;
- Rang21 = (Rang21 + 2) % 360;
- Rang22 = (Rang22 + 2) % 360;
- glutPostRedisplay();
- limitePincaDir--;
- }
- break;
- case 'f':
- if (limitePincaEsq < 15) {
- Lang11 = (Lang11 + 2) % 360;
- Lang12 = (Lang12 + 2) % 360;
- Lang21 = (Lang21 - 2) % 360;
- Lang22 = (Lang22 - 2) % 360;
- glutPostRedisplay();
- limitePincaEsq++;
- }
- break;
- case 'F':
- if (limitePincaEsq > 0) {
- Lang11 = (Lang11 - 2) % 360;
- Lang12 = (Lang12 - 2) % 360;
- Lang21 = (Lang21 + 2) % 360;
- Lang22 = (Lang22 + 2) % 360;
- glutPostRedisplay();
- limitePincaEsq--;
- }
- break;
- case 'j':
- if (limitePassosLado > -6) {
- posX = (posX + 1) % 360;
- glutPostRedisplay();
- limitePassosLado--;
- }
- break;
- case 'l':
- if (limitePassosLado < 6) {
- posX = (posX - 1) % 360;
- glutPostRedisplay();
- limitePassosLado++;
- }
- break;
- case 'i':
- if (limitePassosReto > -8) {
- posZ = (posZ + 1) % 360;
- glutPostRedisplay();
- limitePassosReto--;
- }
- break;
- case 'k':
- if (limitePassosReto < 5) {
- posZ = (posZ - 1) % 360;
- glutPostRedisplay();
- limitePassosReto++;
- }
- break;
- case 27:
- exit(0);
- break;
- default:
- break;
- }
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 600);
- glutInitWindowPosition(100, 100);
- glutCreateWindow(argv[0]);
- init();
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement