Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
184 views7 pages

CS602 2 Assignment Solution

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

Computer Graphics (CS602) Total marks = 20

Assignment # 02 Deadline
th
29 of August, 2022
Spring 2022

Please carefully read the following instructions before attempting the assignment.

RULES FOR MARKING


It should be clear that your assignment would not get any credit if:
 The assignment is submitted after the due date.
 The submitted assignment does not open or the file is corrupt.
 Strict action will be taken if the submitted solution is copied from any other student or the
internet.

You are required to submit your solution through LMS in zip format containing
following files.
 Your Project in zipped form containing both .cpp and .exe file.

The word document (.doc/docx) or any other file format containing code will
not be considered. And rewarded by zero marks.
If the code file or exe file is missing in zip folder, your assignment will be
awarded as zero.
OBJECTIVE
The objective of this assignment is to:
 Learn and practice basic concepts of 2D transformation with drawing shapes using OpenGL
libraries.
 Learn to draw shapes and patterns by using OpenGL libraries functions and transform them.
Instructions:
 You have to do the following steps first in order to perform the task.
 Install Dev-C++ from your LMS.
 Read out the file “How to instal and Program with Glut (OpenGL Utility) Libraires” thoroughly
and follow the instructions in the file properly provided to you on your LMS.

NOTE
No assignment will be accepted after the due date via email in any case (whether it is the case of load
shedding or internet malfunctioning etc.). Hence refrain from uploading assignments in the last hour
of the deadline. It is recommended to upload the solution file at least two days before its closing date.

If you people find any mistake or confusion in the assignment (Question statement), please consult
with your instructor before the deadline. After the deadline, no queries will be entertained in this
regard.
For any query, feel free to email at:
Cs602@vu.edu.pk

Question No 01 Marks (20)


Write a C++ program through Open GL libraries to Draw a Mechanical arm and rotate it to right,
left, up and down by using the arrow keys respectively.

Below images are the different shapes of Mechanical arm and its movements.

Note: You must display your student ID in output window.

Code:
#ifdef _APPLE_CC
#include<GLUT/glut.h>
#else
#include<GL/glut.h>
#include<stdlib.h>
#endif
static int shoulderAngle = 0, elbowAngle = 0;
void special(int key, int, int) {

switch (key) {

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


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

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

case GLUT_KEY_DOWN: (shoulderAngle -= 6)%= 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, float z, char *string) {


glRasterPos3f(x, y, z);
for (char* c = string; *c != '\0';c++) {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
}

void display() {

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(2.2, 0.9, 0.5);

glMatrixMode(GL_MODELVIEW);

glPushMatrix();
drawString(0.2, 2.5, 0.0,"bc210209446");

glRotatef((GLfloat)shoulderAngle, 0.0, 0.0, 1.0); glTranslatef(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("BC190409022");
glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutSpecialFunc(special);

init();
glutMainLoop();

Output:

You might also like