Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <stdlib.h>
- static int shoulder = 0, elbow = 0, fingerBase = 0, fingerUp = 0 , chest = 0 , r =0 , l = 0 , hipside1 = 0 , hipside2 = 0 , rightk = 0 , leftK =0 ;
- int moving, startx, starty;
- GLfloat angle = 0.0; /* in degrees */
- GLfloat angle2 = 0.0; /* in degrees */
- void init(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glShadeModel(GL_FLAT);
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- glRotatef(angle2, 1.0, 0.0, 0.0);
- glRotatef(angle, 0.0, 1.0, 0.0);
- glTranslatef(-1.0, 1.0, 0.0);
- glRotatef((GLfloat)chest, 0.0, 1.0, 0.0);
- glTranslatef(1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 2.5, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // start of Arm 1 -----------------------------------
- glPushMatrix();
- // Draw Shoulder
- glTranslatef(2.0, 1.0, 0.0);
- glRotatef((GLfloat)shoulder, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.6, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw Ellbow
- glTranslatef(1.0, 0.0, 0.0);
- glRotatef((GLfloat)elbow, 0.0, 0.0, -1.0);
- glTranslatef(1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.6, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- //Draw finger 1
- // fisrt part
- glPushMatrix();
- glTranslatef(1.0, -0.3, 0.0);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, 1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- //second part
- glTranslatef(0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, 1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //Draw finger 2
- // fisrt part
- glPushMatrix();
- glTranslatef(1.0, 0.25, -0.15);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //finger 3
- // fisrt part
- glPushMatrix();
- glTranslatef(1.0, 0.25, 0.45);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //finger 4
- // fisrt part
- glPushMatrix();
- glTranslatef(1.0, 0.25, 0.15);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- // finger 5
- // fisrt part
- glPushMatrix();
- glTranslatef(1.0, 0.25, -0.45);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, -1.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- // end of Arm -----------------------------------
- // start of Arm 2-----------------------------------
- glPushMatrix();
- // Draw Shoulder
- glTranslatef(-2.0, 1.0, 0.0);
- glRotatef((GLfloat)shoulder, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.6, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw Ellbow
- glTranslatef(-1.0, 0.0, 0.0);
- glRotatef((GLfloat)elbow, 0.0, 0.0, 1.0);
- glTranslatef(-1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(2.0, 0.6, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- //Draw finger 1
- // fisrt part
- glPushMatrix();
- glTranslatef(-1.0, -0.3, 0.0);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, -1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- //second part
- glTranslatef(-0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, -1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //Draw finger 2
- // fisrt part
- glPushMatrix();
- glTranslatef(-1.0, 0.25, -0.15);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(-0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //finger 3
- // fisrt part
- glPushMatrix();
- glTranslatef(-1.0, 0.25, 0.45);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(-0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- //finger 4
- // fisrt part
- glPushMatrix();
- glTranslatef(-1.0, 0.25, 0.15);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(-0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- // finger 5
- // fisrt part
- glPushMatrix();
- glTranslatef(-1.0, 0.25, -0.45);
- glRotatef((GLfloat)fingerBase, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- // second part
- glTranslatef(-0.15, 0.0, 0.0);
- glRotatef((GLfloat)fingerUp, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.3, 0.1, 0.1);
- glutWireCube(1);
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- // end of Arm -----------------------------------
- // START of LEG 1 -----------------------------------
- glPushMatrix();
- // Draw Hip
- glTranslatef(0.85, -2.2, 0.0);
- glRotatef((GLfloat)r, -1.0, 0.0, 0.0);
- glRotatef((GLfloat)hipside1, 0.0, 0.0, 1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 1.5, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw Knee
- glTranslatef(1.0, -1.8, 0.0);
- glRotatef((GLfloat)rightk, 1.0, 0.0, 0.0);
- glTranslatef(-1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 2.0, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw foot
- glTranslatef(1.0, -1.0, 0.25);
- glTranslatef(-1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 0.6, 1.5);
- glutSolidCube(1.0);
- glPopMatrix();
- glPopMatrix();
- // END of LEG 1-----------------------------------
- // START of LEG 2 -----------------------------------
- glPushMatrix();
- // Draw Hip
- glTranslatef(-0.56, -2.2, 0.0);
- glRotatef((GLfloat)l, -1.0, 0.0, 0.0);
- glRotatef((GLfloat)hipside2, 0.0, 0.0, -1.0);
- glTranslatef(-0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 1.5, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw knee
- glTranslatef(1.0, -1.8, 0.0);
- glRotatef((GLfloat)leftK, 1.0, 0.0, 0.0);
- glTranslatef(-1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 2.0, 1.0);
- glutWireCube(1.0);
- glPopMatrix();
- // Draw foot
- glTranslatef(1.0, -1.0, 0.25);
- glTranslatef(-1.0, 0.0, 0.0);
- glPushMatrix();
- glScalef(0.6, 0.6, 1.5);
- glutSolidCube(1.0);
- glPopMatrix();
- glPopMatrix();
- // END of LEG 2 -----------------------------------
- // Head
- glTranslatef(0.0, 2.0, 0.0);
- glRotatef((GLfloat)shoulder, 0.0, 0.0, 0.0);
- glTranslatef(0.15, 0.0, 0.0);
- glPushMatrix();
- glScalef(1.0, 1.0, 1.0);
- glutWireSphere(0.5 , 50 , 50);
- glPopMatrix();
- glPopMatrix();
- glutSwapBuffers();
- }
- void reshape(int w, int h)
- {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(85.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -5.0);
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 's':
- shoulder = (shoulder + 5) % 180;
- glutPostRedisplay();
- break;
- case 'S':
- shoulder = (shoulder - 5) % 180;
- glutPostRedisplay();
- break;
- case 'e':
- elbow = (elbow + 5) % 180;
- glutPostRedisplay();
- break;
- case 'E':
- elbow = (elbow - 5) % 180;
- glutPostRedisplay();
- break;
- case 'f':
- fingerBase = (fingerBase + 5) % 90;
- glutPostRedisplay();
- break;
- case 'F':
- fingerBase = (fingerBase - 5) % 90;
- glutPostRedisplay();
- break;
- case 'g':
- fingerUp = (fingerUp + 5) % 180;
- glutPostRedisplay();
- break;
- case 'G':
- fingerUp = (fingerUp - 5) % 180;
- glutPostRedisplay();
- break;
- case 'r':
- r = (r + 5) % 90;
- glutPostRedisplay();
- break;
- case 'R':
- r = (r - 5) % 90;
- glutPostRedisplay();
- break;
- case 'l':
- l = (l + 5) % 90;
- glutPostRedisplay();
- break;
- case 'L':
- l = (l - 5) % 90;
- glutPostRedisplay();
- break;
- case 't':
- rightk = (rightk + 5) % 90;
- glutPostRedisplay();
- break;
- case 'T':
- rightk = (rightk - 5) % 90;
- glutPostRedisplay();
- break;
- case 'q':
- leftK = (leftK + 5) % 90;
- glutPostRedisplay();
- break;
- case 'Q':
- leftK = (leftK - 5) % 90;
- glutPostRedisplay();
- break;
- case 'c':
- chest = (chest + 5) % 360;
- glutPostRedisplay();
- break;
- case 'C':
- chest = (chest - 5) % 360;
- glutPostRedisplay();
- break;
- case 'x':
- hipside1 = (hipside1 + 5) % 30;
- glutPostRedisplay();
- break;
- case 'X':
- hipside1 = (hipside1 - 5) % 30;
- glutPostRedisplay();
- break;
- case 'z':
- hipside2 = (hipside2 + 5) % 30;
- glutPostRedisplay();
- break;
- case 'Z':
- hipside2 = (hipside2 - 5) % 30;
- glutPostRedisplay();
- break;
- case 27:
- exit(0);
- break;
- default:
- break;
- }
- }
- static void mouse(int button, int state, int x, int y)
- {
- if (button == GLUT_LEFT_BUTTON)
- {
- if (state == GLUT_DOWN)
- {
- moving = 1;
- startx = x;
- starty = y;
- }
- if (state == GLUT_UP)
- {
- moving = 0;
- }
- }
- }
- static void motion(int x, int y)
- {
- if (moving)
- {
- angle = angle + (x - startx);
- angle2 = angle2 + (y - starty);
- startx = x;
- starty = y;
- glutPostRedisplay();
- }
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(500, 500);
- glutInitWindowPosition(100, 100);
- glutCreateWindow(argv[0]);
- init();
- glutMouseFunc(mouse);
- glutMotionFunc(motion);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement