cs 602 assignment 2 spring 2022 solution



 

#ifdef_APPLE_cc__

#include<GLUT/glut.h>

#else

#include<GL/glut.h>

#include<stdlib.h>

 

#endif

static int shoulderAngle=0, elbowAngle=0;

 

voidspecial(int key, int, int)

{

                switch(key)

                {

                                case GLUT_KEY_LEFT: (elbowAngle +=5) %=360; break;

                               

                               

                                case GLUT_KEY_RIGHT: (elbowAngle -=5) %=360; break;

                               

                               

                                case GLUT_KEY_UP: (shoulderAngle +=5) %=360; break;

                               

                               

                                case GLUT_KEY_DOWN: (shoulderAngle -=5) %=360; break;

                               

                               

                                default: return;

 

                }

                glutPostRedisplay();

}

 

 

 

void wireBox(GLdouble width,GLdouble height,GLdouble depth)

{

                glPushMatrix();

               

               

                glScalef(width,height,depth);

               

               

                glutWireCube(1.0);

               

               

                glPopMatrix();

}

 

 

void drawString(float x,float y,floatz,char *string)

 

 

{

                glRasterPos3f(x,y,z);

               

                for (char*c=string; *c!='\0'; c++)

{

                glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *C);

               

}

 

}

 

void display(){

               

                glClear(GL_COLOR_BUFFER_BIT);

               

               

                glColor3f(.2,.6,1.5);

               

                glMatrixMode(GL_MODELVIEW);

               

               

               

                glpushMatrix();

               

               

               

                drawString(0.9, 3.0, 1.0, "VIRTUAL GURU");

               

               

               

               

                drawString(0.2, 3.7,0.0, "BC16043773");

 

 

 

glRotatef((GLfloat)shoulderAngle, 0.0, 0.0, 1.0);

 

 

 

glTranslate(1.0, 0.0, 0.0);

 

 

 

 

wireBox(2.0, 0.4, 1.0);

 

 

glTranslatef(1.0, 0.0, 0.0);

 

 

 

glRotatef(GLfloat)elbowAngle,0.0, 0.0, 1.0);

 

 

 

glTranslatef(1.0, 0.0, 0.0);

 

 

 

 

wireBox(2.0, 0.4, 1.0);

 

glPopMatrix();

 

 

 

glFlush();

}

 

 

void reshape(GLint w, GLint h)

{

                glViewport(0, 0, w, h);

 

 

 

                glMatrixMode(GL_PROJECTION);

 

 

 

                glLoadIdentity();

 

 

 

 

                gluPerspective(65.0, GLfloat(w)/GLfloat(h), 1.0, 20.0);

               

}

 

 

void init()

{

                glShadeModel(GL_FLAT);

               

               

               

               

                glMatrixMode(GL_MODELVIEW);

               

               

               

                glLoadIdentity();

               

               

               

                gluLookAt(1,2,8, 0,0,0 0,1,0);

               

}

 

int main(int argc, char**argv)

{

                glutInit(&argc, argv);

               

               

               

                glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

               

               

               

               

               

                glutInitWindowPosition(80, 80);

               

               

               

               

               

                glutInitWindowSize(800, 600);

               

               

               

               

                glutCreateWindow("Robot Arm");

               

               

               

               

               

                glutDisplayFunc(display);

               

               

               

                glutReshapeFunc(reshape);

               

               

               

               

               

               

                glutSpecialFunc(Special);

               

                int();

}

 

 

 

}

 

 

}

 

  //solution file Available contact on given number 0311-4120810

Post a Comment

Previous Post Next Post