Search Projects

Tuesday, March 13, 2018

Robot Computer Graphics Program in C

OpenGL is amazing, it have potential of great stuffs from creating a small triangle to big structures. We have seen many robot program in OpenGL. Here we come with another robot computer graphics program in C with the use of OpenGL API.

Features 

  • A human features with hands,legs, neck, head and face drawn with simple approach.
  • A colorful robot with animation made.
  • A dat file created that used as input for certain restrictions which we can't hard code in program.
  • Four header files used -
    1. vars.h - It contains all the global variables used in the program. Also have dimension for the body if the robot.dat is unreadable or not present.
    2. file.h -  This header used for reading input from robot.dat file.
    3. keyboard.h -  As name suggests it contains keyboard input functions.
    4. mouse.h - Same as keyboard.h, it also have mouse input functions.
  • Program uses selection buffer to determine what body part was selected, the judging by button pushed and mouse movement, the proper transformation is executed.

Main Functions

main();                            read data file, initialize glut stuff
     init();                              lighting and material stuff, initialize matrices to identity
     display();                        glut display function (calls display_robot(rendermode))
     display_robot(mode);    call each of the body part functions
     reshape_window();       glut reshape function

     draw_body(mode);        draw the torso and neck
     draw_head(mode);        draw the head and face
     draw_leftarm(mode);     draw all of the left arm
     draw_rightarm(mode);    draw all of the right arm
     draw_leftleg(mode);     draw all of the left leg
     draw_rightleg(mode);    draw all of the right leg

Mouse Interface:
   To translate the robot (x, y direction): click the right mouse button on the torso,
      and drag it around the screen.  Once the button is released, the robot will move (in
      the direction of the vector from where the button was pushed to where it was released)
   To move the robot forward and backward (z direction):
      right click once on the torso to move it forward
      left click once on the torso to move it backward
      note: the amount which the robot moves in the z direction for each click can be
        adjusted using the '-' and '+' keys.  (default == 0.2), each adjustment is by 0.2
   
   To rotate body parts or the torso(about x or y axis):
      left click on the body part you want to rotate. (hold in the button)
        then drag the mouse the direction you want the robot to rotate.
        upon release of the button, the rotation will occur.
        (the amount of rotation is the distance of the drag (in pixels) mod 360)
   To rotate about the z axis:
      click and drag with the middle button.  the amount of rotation is determined
        by the horizontal change (mode 360)

Keyboard Interface:
   Rotations:  push 'q' for x axis, 'w' for y, 'e' for z
               push 'Q' for -x, 'W' for -y, 'E' for -z
               then choose the body part with, 0-9, 'o','p','[',']'
                  0-torso, 1- head, 2-leftupperarm, 3-leftlowerarm, 4-leftwrist
                  5-rightupperarm, 6- rightlowerarm, 7- rightwrist,
                  8-leftupperleg, 9- leftlowerleg, 'o'- left foot,
                  'p'-rightupperleg, '['-rightlowerleg, ']'-right foot
   Translation:
               use same q,w,e and Q,W,E for axis/direction selection
               then push 't' to translate
               use + and - to adjust the amount of translation




No comments:

Post a Comment