You are on page 1of 6

FACULTY OF ARCHITECTURE AND ENGINEERING

DEPARTMENT OF COMPUTER ENGINEERING





Computer Graphics
ROBOTIC ARM
ASSIGNMENT
CEN 344
EPOKA UNIVERSITY










Prepared by: Accepted by:
Briland Hitaj Asst.Prof. adi Evren eker
Briland Hitaj
ROBOTIC ARM ASSIGNMENT
1

The assignment was to create a robotic arm which would be composed of three parts, three
quadrilaterals. The lower part of it would be static so that it would not move. When the middle quadrilateral
moves at the same time the upper part quadrilateral should move, whereas the upper part, the topmost
quadrilateral will remove without affecting the other quadrilaterals.
In order to solve it, I used the rotation and translation functions of openGl. Firstly, I created the
rectangles to be one above the others as I have shown in the figure below:

Figure 1 View of the Robotic Arm
Then in order to make the rotation work, I use the glTranslateF function of openGl in order to set the rotation
point of the quadrilaterals to wherever I like. For the green quadrilateral I have set the rotation point according
to its left base point and also for the yellow quadrilateral I have set its rotation to its respective left base point.
After this I have applied the ASCII codes for arrow key button in order to perform the movement.

Briland Hitaj
ROBOTIC ARM ASSIGNMENT
2

The ASCII Codes for the arrow buttons are as below and together with them I have set the part of the arm
which they affect:
UP ARROW ASCII CODE: 38 Move the entire robotic arm in the
counterclockwise direction
DOWN ARROW ASCII CODE: 40 Move the entire robotic arm in the
clockwise direction
LEFT ARROW ASCII CODE: 37 Move the upper part of the robotic
arm (the forearm) in the
counterclockwise direction.
RIGHT ARROW ASCII CODE: 39 Move the upper part of the robotic
arm (the forearm) in the clockwise
direction.

I have created the code which is on the main.cpp file on my own and I have made use of the libraries and
samples that we have taken during the lecture hours. I have also inserted comments to the project in order to
explain my work. The code is as below:
main.cpp
/**
* Assignment: Robotic Arm
* Prepared by: Briland Hitaj
* Course: Computer Graphics
* EPOKA UNIVERSITY, 2012
*/
/*******************************************
* ZeusCMD - OpenGL Tutorial 5 : Primitives *
* By Grant James (ZEUS) *
* http://www.zeuscmd.com *
*******************************************/
#include "glutil.h"

OpenGL *opengl;
float wholeArm=0.0, foreArm = 0.0; //initializing two variables one wholeArm and the foreArm
//which will serve for the movement of the robotic arm

bool init()
{
glClearColor(0.85f, 0.85f, 0.85f, 0.0f); //Setting the
background color to Gray
return true;
}

Briland Hitaj
ROBOTIC ARM ASSIGNMENT
3

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity(); //Loading the Identity matrix
//The red quadrilateral which remains static all the time
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(-0.15f, -0.45f, 0.0f);
glVertex3f(0.15f, -0.45f, 0.0f);
glVertex3f(0.15f, -0.15f, 0.0f);
glVertex3f(-0.15f, -0.15f, 0.0f);
glEnd();
//The green quadrilateral which when moves moves the
entire arm of the robot
//so it also moves its forearm.
glColor3f(0.0f, 1.0f, 0.0f);
glTranslatef(-0.08f, -0.15f, 0.0f); //I translate the rotation point of my robotic arm to point (-0.08, -0.15),
which is the point where I want the rotation to occur
glRotatef(wholeArm, 0.0f, 0.0f, 1.0f); //Perform the rotation
glTranslatef(0.08f, 0.15f, 0.0f); //I translate back based on the translation rules learned during the lessons
glBegin(GL_POLYGON); //Creating the green polygon of
my robotic arm
glVertex3f( -0.08f, -0.15f, 0.0f);
glVertex3f( 0.08f, -0.15f, 0.0f);
glVertex3f( 0.08f, 0.45f, 0.0f);
glVertex3f( -0.08f, 0.45f, 0.0f);
glEnd();

//Below I set the forearm of my robotic arm, which I
have colored in yellow in order
//to make the distinction between quadrilaterals
glColor3f(1.0f, 1.0f, 0.0f); //coloring the quadrilateral in
yellow
glTranslatef(-0.08f, 0.45f, 0.0f); //I translate it to the
rotation point of (-0.08, 0.45)
glRotatef(foreArm, 0.0, 0.0, 1.0); //Perform the rotation
glTranslatef(0.08f, -0.45f, 0.0f); //Translate back
glBegin(GL_POLYGON); //creating the yellow
quadrilateral which will serve as forearm of the robotic arm
glVertex3f( -0.08f, 0.45f, 0.0f);
glVertex3f( 0.08f, 0.45f, 0.0f);
glVertex3f(0.08f, 0.65f, 0.0f);
Briland Hitaj
ROBOTIC ARM ASSIGNMENT
4

glVertex3f(-0.08f, 0.65f, 0.0f);
glEnd();

glFlush();
}

void idle()
{
if(opengl->isKeyDown(38)){ //38 stands for pressing the Up Arrow button of the keyboard to move the entire
robotic arm
wholeArm+=0.1; //in counterclockwise direction
}
if(opengl->isKeyDown(40)){ //40 stands for pressing the Down Arrow button of the keyboard to move the
entire robotic arm
wholeArm-=0.1; //in clockwise direction
}
if(opengl->isKeyDown(39)){ //39 stands for pressing the Right Arrow button of the keyboard to move the
forearm of the robotic arm
foreArm-=0.1; //in clockwise direction
}
if(opengl->isKeyDown(37)){ //37 stands for pressing the Left Arrow button of the keyboard to move the
forearm of the robotic arm
foreArm+=0.1; //in counterclockwise direction
}
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
opengl = OpenGL::create();
opengl->setInitFunc(init);
opengl->setDisplayFunc(display);
opengl->setIdleFunc(idle);

if (!opengl->initGL("BRILAND HITAJ ROBOTIC ARM", 500,
500, false, 32))
return 1;

opengl->runMessageLoop();

return 0;
}

Briland Hitaj
ROBOTIC ARM ASSIGNMENT
5

The other files that I have used are the ones that we have taken during the course such as glutil.h and
glutil.cpp.

You might also like