0% found this document useful (0 votes)
431 views58 pages

Visvesvaraya Technological University BELGAUM-590014: Walking Robot

its web report
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
431 views58 pages

Visvesvaraya Technological University BELGAUM-590014: Walking Robot

its web report
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELGAUM-590014

A Computer Graphics and Visualization


Mini-Project Report
On
“Walking Robot.”
A Mini-project report submitted in partial fulfilment of the requirements for the award of the
degree of Bachelor of Engineering in Computer Science and Engineering of Visvesvaraya
Technological University, Belgaum.
Submitted by:

Niket Agrawal (1DT19CS095)


AND
Pruthivika v (1DT19CS119)

Under the Guidance of:


Prof.K.Deepa Shree
Asst.Prof.Dept of CSE
Prof.Shalini A
Asst.Prof.Dept of CSE

Department of Computer Science and Engineering


(Accredited by NBA, NAAC A+, New Delhi)
DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND
MANAGEMENT
Kanakapura Road,Udayapura, Bangalore
2021-2022
DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND
MANAGEMENT,
Kanakapura Road,Udayapura, Bangalore

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


(Accredited by NBA, NAAC A+, New Delhi)

CERTIFICATE
This is to certify that the Mini-Project on Computer Graphics and Visualization work entitled
“Walking Robot” has been successfully carried out by NIKET AGRAWAL (1DT19CS095)
and PRUTHIVIKA V (1DT19CS119) a bonafide students of Dayananda Sagar Academy of
Technology and Management in partial fulfilment of the requirements for the award of
degree in Bachelor of Engineering in Computer Science and Engineering of Visvesvaraya
Technological University, Belgaum during academic year 2021-2022. It is certified that
all corrections/suggestions indicated for Internal Assessment have been incorporated in
the report deposited in the departmental library. The mini project report has been approved as it
satisfies the academic requirements in respect of project work for the said degree.

Guide Name Guide Name


Designation Designation

Dr. C. NANDINI
(Vice Principal & HOD, Dept. of CSE)
Examiners: Signature with Date

1:
2:
ABSTRACT
This is an animation to view a walking robot. The robot can be rendered in both a
wireframe view and in shaded view. There are options to manipulate the robot arms,
head and torso.
Requirements for advance animated robot opengl mini projects

• We need to draw a robot which uses the polygons like square,


rectangles, pentagons, triangle.
• Different Part of animated robot should look realistic with a great
precision design.
• To animate robot we need some function to be assigned via keyword
actions or mouse clicks.
• Add rotation and translation effect for the motion in animated robot.
ACKNOWLEDGEMENT

While presenting this Graphics Project on “Walikng Robot”, I feel that it is our duty to
acknowledge the help rendered to us by various persons.

Firstly I thank God for showering his blessings on me. I am grateful to my institution
Dayananda Sagar Academy of Technology for providing me a congenial atmosphere to carry out
the project successfully.

I would like to express my heartfelt gratitude to Dr.B R Lakshmikantha, Principal,


CEC, Bangalore, for extending his support.

I would also like to express my heartfelt gratitude to Dr.C Nandini, Prof. Vice
Principal & HOD, Computer Science and Engineering Department, whose guidance and
support was truly invaluable.

I am very grateful to my guide, Prof.K.Deepa Shree, Asst.Prof.Dept.of CSE and


Prof.Shalini A, Asst.Prof.Dept.of CSE, Department of Computer Science, for his/her
valuable guidance and advice at every stage of my project which helped me in the
successful completion of my project.

I would also indebted to my Parents and Friends for their continued moral and material
support throughout the course of project and helping me in finalize the presentation.

My heartful thanks to all those have contributed bits, bytes and words to accomplish this
Project.
Thanking you all,
Niket Agrawal (1DT19CS095)
Pruthivika v (1DT19CS119)
TABLE OF CONTENTS
CHAPTER NAME PAGE NO.
1. INTRODUCTION ………………………………………1
1.1 Introduction To OpenGL………………………………………….1
1.2 Computer Graphics ………………………..……………………. 1
1.3 A Brief History of OpenGL………………………………………. 2
1.3.1 What is OpenGL…………………………………………...3
1.3.2 Programming using OpenGL: A first Introduction…………..3
1.4 OpenGL(Open Graphics Library)………………………………….4

2. REQUIREMENT SPECIFICATION …………………...5


2. 1 Hardware Requirements ……………………………….………….5
2. 2 Software Requirements ……………………….………………….5

3. SYSTEM DESIGN…………………..………………….6
3.1System Architecture.…………………………………………..……...6

4. IMPLEMENTATION…………………….……………7
4.1Implementation of OpenGL Built in functions used………………...7
4. 2Implementation of User Defined functions………………….…….9

5. SNAPSHOTS……..………………………………………………15
5.1Introduction……….………………………………...…………………15
5.2Menu…………..…………………………………….…………….16
5.3Robot start …………………………………………………………17
5.4How do i……………………………………………………………18
5.5Instruction to move arms…………………………………….……...18
5.6Instructiontomovelegs………………………………………………….19
5.7Refraction_after………………………………….……………………19

6. FUCTURE ENHANCEMENT……….…..………...….20
REFERENCES……………………………………………………….….20
A.1:Source code……………………………………………………….21
Online Examination System

CHAPTER 1

INTRODUCTION
1.1 INTRODUCTION TO OPEN-GL

Computer Graphics is a complex and diversified technology .To technology it is necessary


to subdivide it into manageable Parts. This can be accomplished by considering that the
end product of computer graphics is a picture. The picture may, of course, be used for a
large variety of purposes; e.g., it may be an engineering drawing, an exploded parts
illustration for a service manual, a business graph, an architectural rendering for a
proposed construction or design project, an advertising illustration, or a single frame
from an animated movie. The picture is the c2 fundamental cohesive concept in computer
graphics.

Consider how: Pictures are represented in computer graphics.


• Pictures are prepared for presentation.
• Previously prepared pictures are presented.
• Interaction with the picture is accomplished.
Here “picture” is used in its broadest sense to mean any collection of lines, points, text,
etc. displayed on a graphics device.

1.2 Computer Graphics

The totality of computer graphics software encompasses the concepts from data
structures, from data base design and management, from the psychology, ergonometric of the
man-machine interface, from programming languages and operating system.
Numerous computer graphics standards can be grouped following categories.
z
• First is the graphics application interface, where ideas are translated into a form that is
understandable by a computer system. Current representative standards are the GKS,

CSE,DSATM 2021-2022 Page | 1


Online Examination System

GKS-3D, and the Programmer’s Hierarchical Interactive Graphics Standards (PHIGS).

• The Second is concerned with the storage and transmission of data between graphics
manufacturing systems. The current standard in this area is the Initial Graphics Exchange
Specification (IGES).
A computer graphics system is a computer system with all the components of the general
purpose computer system. There are five major elements in system: input devices, processor,
memory, frame buffer, output devices.

Fig. 1.1: A graphics system

1.3 A Brief History Of OpenGl


OpenGL was developed by Silicon Graphics and is popular in the video games industry where it
competes with Direct3D on Microsoft Windows IrisGL, a propietary graphics API, is the
precursor of OpenGL. It is developed by Silicon Graphics Inc. (SGI). IrisGL was used as the
starting point of an open standard for computer graphics that would save time porting applications
by avoiding direct hardware access. After SGI cleaned up IrisGL and opened up the standard to
other companies, OpenGL was born.

In 1992 the OpenGL Architectural Review Board (OpenGL ARB) was established. The OpenGL
ARB is a group of companies that maintain and update the OpenGL standard.

CSE,DSATM 2021-2022 Page | 2


Online Examination System

In 2003 the first OpenGL (Exchange Specification) ES specification was released. OpenGL ES is
a subset of OpenGL designed for mobile phones, embedded devices and video game systems.

In 2004 the OpenGL 2.0 specification was released, including the GLSL (OpenGL Shading

1.3.1 What is Open-GL?


• OpenGL is a Software Interface to Graphics Hardware
• OpenGL is designed as a streamlined, hardware-independent interface to be implemented
on many different hardware platforms
• It Consists of about 250 Distinct Commands.
• It is Hardware-independent Interface
• No command for windows or user input handling
• Does not include low-level I/O management
• It is developed primarily by SGI
• It consists of 2D/3D graphics, lower-level primitives (polygons)
• It is Basis for higher-level libraries/toolkits
What does it do?
• Main purpose is to render two and three dimensional objects into a frame buffer. These
objects are described as sequences of vertices (which define geometric objects) or pixels
(which define images).

1.3.2 Programming using OpenGL: A first Introduction


OpenGL is an API …

• Application programmers’ interface: link between

• low-level: graphics hardware

• high-level: application program you write


OpenGL is a …

Library for 2D and 3D graphics programming

CSE,DSATM 2021-2022 Page | 3


Online Examination System

• 200+ functions for building application programs

• Portable to many platforms (Win, Mac, Unix, Linux)

• Callable from many programming languages (C, Java,Perl, Python)

Operations

• Specify geometric primitives (lines, pixels, polygons ...)


• Apply geometric transformations
• Specify camera, light, color, texture information, etc.

• No windowing or (platform-specific) input/interaction

• functions— these are the jobs of GLUT

1.4 OpenGL-Related Libraries

OpenGL provides a powerful but primitive set of rendering commands, and all higher-level
drawing must be done in terms of these commands. Also, OpenGL programs have to use the
underlying mechanisms of the windowing system. A number of libraries exist to allow you to
simplify your programming tasks, including the following:

• The OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL
commands to perform such tasks as setting up matrices for specific viewing orientations and
projections, performing polygon tessellation, and rendering surfaces. GLU routines use the
prefix glu.
• The OpenGL Utility Toolkit (GLUT) is a window system-independent toolkit, written by
Mark Kilgard, to hide the complexities of differing window system APIs. GLUT is the
subject of the next section, and it’s described in more detail in Mark Kilgard’s book
OpenGL Programming for the X Window System (ISBN 0-201-48359-9). GLUT routines
use the prefix glut. "How to Obtain the Sample Code" in the Preface describes how to
obtain the source code for GLUT, using ftp.

CSE,DSATM 2021-2022 Page | 4


Online Examination System

CHAPTER 2

REQUIREMENTS SPECIFICATION

2.1 Hardware Requirements:


• Intel® Pentium 4 CPU or higher versions
• 128 MB or more RAM.

• A standard keyboard, and Microsoft compatible mouse


• VGA monitor.

2.2 Software requirements:


• The graphics package has been designed for OpenGL; hence the machine must
Have code blocks

• Software installed preferably 6.0 or later versions with mouse driver installed.
• GLUT libraries, Glut utility toolkit must be available.

• Operating System: Windows

• Version of Operating System: Windows XP, Windows NT and Higher


• Language: C
• Code::Blocks: cross-platform Integrated Development Environment (IDE)

2.3 MISCELLANEOUS REQUIREMENTS:


All the required library and header files should be available in the include directories. The files
associated with this editor should be placed in either the same folder or in a specified folder.

2.4 LANGUAGE USED IN CODING:


C/C++ and OpenGL as an API.

CSE,DSATM 2021-2022 Page | 5


Online Examination System

CHAPTER 3
SYSTEM DESIGN
Design of any software depends on the architecture of the machine on which that software
runs, for which the designer needs to know the system architecture. Design process involves
design of suitable algorithms, modules, subsystems, interfaces etc.

3.1 System Architecture

CONTROL FLOW DIAGRAM

Fig. 3.1: System Control flow diagram

CHAPTER 4

CSE,DSATM 2021-2022 Page | 6


Online Examination System

IMPLEMENTATION
The implementation stage of this model involves the following phases.

• Implementation of OpenGL built in functions.


• User defined function Implementation.

4.1 Implementation of OpenGL Built In Functions used:


1.glutInit():
glutInit is used to initialize the GLUT library.
Usage:void glutInit(int *argcp, char **argv);
Description:glutInit will initialize the GLUT library and negotiate a session with the window
system.

2.glutInitDisplayMode():
glutInitDisplayMode sets the initial display mode.
Usage:void glutInitDisplayMode (unsigned int mode);
Mode-Display mode, normally the bitwise OR-ing of GLUT display mode bit masks.
Description:The initial display mode is used when creating top-level windows, sub windows,
and overlays to determine the OpenGL display mode for the to-be-created window or overlay.

3.glutCreateWindow(): glutCreateWindow
creates a top-level window.
Usage:intglutCreateWindow(char *name);
Name - ASCII character string for use as window name.
Description:glutCreateWindow creates a top-level window. The name will be provided to the
window system as the window's name. The intent is that thewindow system will label the
window with the name. Implicitly, the currentwindowis set to thenewly created window. Each
created window has a unique associated OpenGL context.

CSE,DSATM 2021-2022 Page | 7


Online Examination System

4.glutDisplayFunc():
glutDisplayFunc sets the display callback for the current window.

Usage:void glutDisplayFunc(void (*func)(void));


Func- The new display callback function.
Description:glutDisplayFunc sets the display callback for the current window. When GLUT
determines that the normal plane for the window needs to be redisplayed, the display callback for
the window is called. Before the callback, the current window is set to the window needing to be
redisplayed and the layer in use is set to the normal plane. The display callback is called with no
parameters. The entire normal plane region should be redisplayed in response to the callback.

5.glutMainLoop():
glutMainLoop enters the GLUT event processing loop.
Usage:void glutMainLoop(void);
Description: glutMainLoop enters the GLUT event processing loop. This routine should be
called at most once in a GLUT program. Once called, this routine will never return. It will call as
necessary any callbacks that have been registered.

6.glMatrixMode( ):
The two most important matrices are the model-view and projection matrix. At any time, the
state includes values for both of these matrices, which are initially set to identity matrices. There
is only a single set of functions that can be applied to any type of matrix. Select the matrix to
which the operations apply by first set in the matrix mode, a variable that is set to one type of
matrix and is also part of the state.

7.glutTimerFunc();
glutTimerFunc registers a timer callback to be triggered in a specified number of milliseconds.

Usage:voidglutTimerFunc(unsigned intmsecs,void (*func)(int value), value);

CSE,DSATM 2021-2022 Page | 8


Online Examination System

Description:glutTimerFunc registers the timer callback func to be triggered in at least msecs


milliseconds. The value parameter to the timer callback will be the value of the value parameter
to glutTimerFunc. Multiple timer callbacks at same or differing times may be registered

simultaneously. The number of milliseconds is a lower bound on the time before the callback is
generated. GLUT attempts to deliver the timer callback as soon as possible after the expiration of
the callback's time interval. There is no support for canceling a registered callback. Instead,
ignore a callback based on its value parameter when it is triggered.

4.2 Implementation of User Defined Functions:


1.void myInit(void):
Here the initialization function init() is used to set the OpenGL state variables dealing with
viewing and attributes-parameters that is prefered to set once, independently of the display
function.
2.void Heel1Subtract(void):
This is the start of the body motion function.
This function is used to subtract heel

3.void Heel2Add(void):
This is the start of the body motion function.
This function is used to add heel

3.void RotateAdd():

This function can rotate the robot in 360 degree.

4.void TurnLeft()

This function is used to turn robot towards left direction.

5.void DrawTextXY():

CSE,DSATM 2021-2022 Page | 9


Online Examination System

This function is used to write text

6.void line1(),void line2():


This functions is used to draw incident and refracted ray respectively rays are drawn using
glBegin(GL_LINES) and the rays are moved using mathametical function.

7.void Cloud1(), void Cloud2(), void Cloud3():

This functions is used to draw the cloud using combinations of circle() function and is moved
using glTranslate() function.

9.fish1(),fish2(),fish3():

This functions is used to draw the fishes using the combination of gl(QUADS) and
gl(TRIANGLES), and gl(POINTS) is used to draw the eyes for the fish.

10.DrawTrees():

This function is used to draw the tree in the water, the trees is drawn using
glBegin(GL_POLYGON);

11.void bitmap(int x, int y, char *string,void *font):


This function takes the following parameters ‘x’ and ‘y’ co-ordinate pixel position , the string
which has to displayed in the screen and the font size of the string which has to be displayed on
the screen. glRasterPos2f(x,y); is used to do display the string.

12.void fonts():
This function contains one dimensional array the content of the array is the various font styles, in
which we have specified the various font styles used to display the Strings on the screen.

13.void menu():
This function is used to display the menu content using bitmap() function.

CSE,DSATM 2021-2022 Page | 10


Online Examination System

14.void discription():

This function is used to display the Snell’s law definition using bitmap() function.

15.void incident_Display(), void refraction_Display() :

This functions specify incident and refraction display respectively in this function we have called
the used defined functions based up on the requirement.

16.void menuset():

This function is used in the Display() function to diplay the content for each frame on the screen
based up on the key pressed in the keyboard using glMatrixMode(GL_PROJECTION); and
glMatrixMode(GL_MODELVIEW); .

17.Display():

In this function we have used the flag and depending on the flag the corresponding frame is
displayed on the screen.

18.void keyboardFunc( unsigned char key, int x, int y ):

This function has following parameters char which represents the the character on the keyboard
depending up the character we have pressed the corresponding flag bit is enabled and the content
is displayed accordingly x and y are the pixel position.

19.void TimeEvent(int values):


This function is used to move the ray of light.This function uses “glutTimerFunc()” that calls
back this function once timer ellapses.

20. void mouse(int btn, int state, int x, int y):


This function is used to get the x and y co-ordinate value which was helpful while drawing an
objects.

CSE,DSATM 2021-2022 Page | 11


Online Examination System

21. int main(argc, char ** argv):

This is the function from where the execution of the program begins.

In this function we have certain “gl” functions used to initialize the basic glut window with
desired properties. After initialization the display function is called with respect to the window
and finally the last statement of this section is the glutMainLoop(). Which is an event processing
function that enters into an infinite loop.

CSE,DSATM 2021-2022 Page | 12


Online Examination System

CHAPTER 5
SNAPSHOTS

Fig. 5.1: Walking robot

Explanation of the figure


This figure shows the Walking robot.

CSE,DSATM 2021-2022 Page | 13


Online Examination System

Fig. 5.2: Menu

Explanation of the figure


The figure shows 5 options:

• Start Walk

• Stop Walk

• Toggle Wireframe

• How do I..(certain instructions)

• Quit

CSE,DSATM 2021-2022 Page | 14


Online Examination System

Fig. 5.3: Robot start to walk

CSE,DSATM 2021-2022 Page | 15


Online Examination System

Fig. 5.4: How do I

Fig 5.5:Instructions to move arms at the shoulder

CSE,DSATM 2021-2022 Page | 16


Online Examination System

Fig. 5.6: Instructions to move legs

CSE,DSATM 2021-2022 Page | 17


Online Examination System

CHAPTER 6

FUTURE ENHANCEMENT

We have implemented the essential features of the ray bending up on incident on surface of water to
our best knowledge. Even still, we would like to enhance the quality and appearance of the snell’s
law in the following ways:

• 3D View
• Enhanced appearance
• Lighting and shading
• Implementation of night mode

CSE,DSATM 2021-2022 Page | 18


Online Examination System

REFERENCES

Books:
1. Computer Graphics with OpenGL Version,3rd Edition, Donald Hearn & Pauline Baker
2.Interactive Computer Graphics-A Top Down approach with OpenGL,5 rd Edition,Edward Angel

Websites:
1. http://www.amazon.in/Computer-Graphics-Multimedia-Udit-
Agarwal/dp/935014316X?tag=googinhydr18418-21
2. http://en.wikipedia.org/wiki/Computer_graphics
3. http://stackoverflow.com/questionsquickly
4. http://www.opengl-tutorial.org/intermediate-tutorials/
5. http://www.opengl-tutorial.org/
6. https://open.gl/
7. http://www.cs.uccs.edu/~ssemwal/indexGLTutorial.html
8. http://www.videotutorialsrock.com/
9. http://ogldev.atspace.co.uk/
10. https://www.opengl.org/sdk/docs/tutorials/
11. http://learnopengl.com/
12. http://lazyfoo.net/tutorials/OpenGL/
13. http://en.wikibooks.org/wiki/OpenGL_Programming

CSE,DSATM 2021-2022 Page | 19


Online Examination System

A.1 Source code


#define SPHERE
#define COLOR
#define LIGHT
#define TORSO
#define HIP
#define SHOULDER
#define UPPER_ARM
#define LOWER_ARM
#define ROCKET_POD
#define UPPER_LEG
#define LOWER_LEG
#define NO_NORM
#define ANIMATION
#define DRAW_MECH
#define DRAW_ENVIRO
#define MOVE_LIGHT
#include <stdlib.h>
#include <math.h>
#define GLUT
#define GLUT_KEY
#define GLUT_SPEC
#include <GL/glut.h>
#define TEXTID 19
void DrawTextXY(double,double,double,double,char *);
#define SOLID_MECH_TORSO 1
#define SOLID_MECH_HIP 2
#define SOLID_MECH_SHOULDER 3
#define SOLID_MECH_UPPER_ARM 4
#define SOLID_MECH_FOREARM 5
#define SOLID_MECH_UPPER_LEG 6
#define SOLID_MECH_FOOT 7
#define SOLID_MECH_ROCKET 8
#define SOLID_MECH_VULCAN 9
#define SOLID_ENVIRO 10
#ifndef M_PI
#define M_PI 3.14
#endif
GLUquadricObj *qobj;
char leg = 0;
int shoulder1 = 0, shoulder2 = 0, shoulder3 = 0, shoulder4 = 0, lat1 =
20, lat2 = 20,
elbow1 = 0, elbow2 = 0, pivot = 0, tilt = 10, ankle1 = 0, ankle2 = 0,

CSE,DSATM 2021-2022 Page | 20


Online Examination System

heel1 = 0,
heel2 = 0, hip11 = 0, hip12 = 10, hip21 = 0, hip22 = 10, fire = 0,
solid_part = 0, anim = 0, turn = 0, turn1 = 0, lightturn = 0, lightturn1
= 0;
float elevation = 0.0, distance = 0.0, frame = 3.0
#ifdef LIGHT
GLfloat mat_specular[] = {0.0, 0.0, 1.0, 1.0};
GLfloat mat_ambient[] ={0.0, 0.0, 1.0, 1.0};
GLfloat mat_diffuse[] ={0.0, 0.0, 1.0, 1.0};
GLfloat mat_shininess[] ={128.0 * 0.4};
GLfloat mat_specular2[] ={0.508273, 0.508273, 0.508373};
GLfloat mat_ambient2[] ={0.19225, 0.19225, 0.19225};
GLfloat mat_diffuse2[] ={0.50754, 0.50754, 0.50754};
GLfloat mat_shininess2[] ={128.0 * 0.6};
GLfloat mat_specular3[] = {1.0, 1.0, 0.0};
GLfloat mat_ambient3[] ={1.0, 1.0, 0.0};
GLfloat mat_diffuse3[] ={1.0, 1.0, 0.0};
GLfloat mat_shininess3[] ={0.0 * 0.0};
GLfloat mat_specular4[] = {0.633, 0.727811, 0.633};
GLfloat mat_ambient4[] = {0.0215, 0.1745, 0.0215};
GLfloat mat_diffuse4[] = {0.07568, 0.61424, 0.07568};
GLfloat mat_shininess4[] = {128 * 0.6};
GLfloat mat_specular5[] ={0.60, 0.60, 0.50};
GLfloat mat_ambient5[] {0.0, 0.0, 0.0};
GLfloat mat_diffuse5[] ={0.5, 0.5, 0.0};
GLfloat mat_shininess5[] ={128.0 * 0.25};
#endif
void Heel1Add(void)
{
heel1 = (heel1 + 3) % 360;
}
void Heel1Subtract(void)
{
heel1 = (heel1 - 3) % 360;
}
void Heel2Add(void)
{
heel2 = (heel2 + 3) % 360;
}
void Heel2Subtract(void)
{
heel2 = (heel2 - 3) % 360;
}
void Ankle1Add(void)
{
ankle1 = (ankle1 + 3) % 360;
}
void Ankle1Subtract(void)
{

CSE,DSATM 2021-2022 Page | 21


Online Examination System

ankle1 = (ankle1 - 3) % 360;


}
void Ankle2Add(void)
{
ankle2 = (ankle2 + 3) % 360;
}
void Ankle2Subtract(void)
{
ankle2 = (ankle2 - 3) % 360;
}
void RotateAdd(void)
{
pivot = (pivot + 3) % 360;
}
void RotateSubtract(void)
{
pivot = (pivot - 10) % 360;
}
void MechTiltSubtract(void)
{
tilt = (tilt - 10) % 360;
}
void MechTiltAdd(void)
{
tilt = (tilt + 10) % 360;
}
void elbow1Add(void)
{
elbow1 = (elbow1 + 2) % 360;
}
void elbow1Subtract(void)
{
elbow1 = (elbow1 - 2) % 360;
}
void elbow2Add(void)
{
elbow2 = (elbow2 + 2) % 360;
}
void elbow2Subtract(void)
{
elbow2 = (elbow2 - 2) % 360;
}
void shoulder1Add(void)
{
shoulder1 = (shoulder1 + 5) % 360;
}
void shoulder1Subtract(void)
{
shoulder1 = (shoulder1 - 5) % 360;

CSE,DSATM 2021-2022 Page | 22


Online Examination System

}
void shoulder2Add(void)
{
shoulder2 = (shoulder2 + 5) % 360;
}
void shoulder2Subtract(void)
{
shoulder2 = (shoulder2 - 5) % 360;
}
void shoulder3Add(void)
{
shoulder3 = (shoulder3 + 5) % 360;
}
void shoulder3Subtract(void)
{
shoulder3 = (shoulder3 - 5) % 360;
}
void shoulder4Add(void)
{
shoulder4 = (shoulder4 + 5) % 360;
}
void shoulder4Subtract(void)
{
shoulder4 = (shoulder4 - 5) % 360;
}
void lat1Raise(void)
{
lat1 = (lat1 + 5) % 360;
}
void lat1Lower(void)
{
lat1 = (lat1 - 5) % 360;
}
void lat2Raise(void)
{
lat2 = (lat2 + 5) % 360;
}
void lat2Lower(void)
{
lat2 = (lat2 - 5) % 360;
}
void FireCannon(void)
{
fire = (fire + 20) % 360;
}
void RaiseLeg1Forward(void)
{
hip11 = (hip11 + 3) % 360;
}

CSE,DSATM 2021-2022 Page | 23


Online Examination System

void LowerLeg1Backwards(void)
{
hip11 = (hip11 - 3) % 360;
}
void RaiseLeg1Outwards(void)
{
hip12 = (hip12 + 10) % 360;
}
void LowerLeg1Inwards(void)
{
hip12 = (hip12 - 10) % 360;
}
void RaiseLeg2Forward(void)
{
hip21 = (hip21 + 3) % 360;
}
void LowerLeg2Backwards(void)
{
hip21 = (hip21 - 3) % 360;
}
void RaiseLeg2Outwards(void)
{
hip22 = (hip22 + 10) % 360;
}
void LowerLeg2Inwards(void)
{
hip22 = (hip22 - 10) % 360;
}
void TurnRight(void)
{
turn = (turn - 10) % 360;
}
void TurnLeft(void)
{
turn = (turn + 10) % 360;
}
void TurnForwards(void{
turn1 = (turn1 - 10) % 360;}
void TurnBackwards(void)
{
turn1 = (turn1 + 10) % 360;
}
void LightTurnRight(void)
{
lightturn = (lightturn + 10) % 360;
}

void LightTurnLeft(void)
{

CSE,DSATM 2021-2022 Page | 24


Online Examination System

lightturn = (lightturn - 10) % 360;


}

void LightForwards(void)
{
lightturn1 = (lightturn1 + 10) % 360;
}

void LightBackwards(void)
{
lightturn1 = (lightturn1 - 10) % 360;
}
void DrawTextXY(double x,double y,double z,double scale,char *s)
{
int i;

glPushMatrix();
glTranslatef(x,y,z);
glScalef(scale,scale,scale);
for (i=0;i<strlen(s);i++)
glutStrokeCharacter(GLUT_STROKE_ROMAN,s[i]);
glPopMatrix();
}
void Box(float width, float height, float depth, char solid)
{
char i, j = 0;
float x = width / 2.0, y = height / 2.0, z = depth / 2.0;
for (i = 0; i < 4; i++) {
glRotatef(90.0, 0.0, 0.0, 1.0);
if (j) {
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-x, y, z);
glVertex3f(-x, -y, z);
glVertex3f(-x, -y, -z);
glVertex3f(-x, y, -z);
glEnd();
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-x, y, z);
glVertex3f(-x, -y, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-x, -y, -z);

CSE,DSATM 2021-2022 Page | 25


Online Examination System

glVertex3f(-x, y, -z);
glEnd();
}
j = 0;
} else {
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-y, x, z);
glVertex3f(-y, -x, z);
glVertex3f(-y, -x, -z);
glVertex3f(-y, x, -z);
glEnd();
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-y, x, z);
glVertex3f(-y, -x, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-y, -x, -z);
glVertex3f(-y, x, -z);
glEnd();
}
j = 1;
}
}
}

void Octagon(float side, float height, char solid)


{
char j;
float x = sin(0.7) * side, y = side / 2.0, z = height / 2.0, c;

c = x + y;
for (j = 0; j < 8; j++) {
glTranslatef(-c, 0.0, 0.0);
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(0.0, -y, z);
glVertex3f(0.0, y, z);
glVertex3f(0.0, y, -z);
glVertex3f(0.0, -y, -z);

CSE,DSATM 2021-2022 Page | 26


Online Examination System

glEnd();
glTranslatef(c, 0.0, 0.0);
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-c, -y, z);
glVertex3f(-c, y, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-c, y, -z);
glVertex3f(-c, -y, -z);
glEnd();
}
glRotatef(45.0, 0.0, 0.0, 1.0);
}
}
#ifdef NORM
void Normalize(float v[3])
{
GLfloat d = sqrt(v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);

if (d == 0.0) {
printf("zero length vector");
return;
}
v[1] /= d;
v[2] /= d;
v[3] /= d;
}

void NormXprod(float v1[3], float v2[3], float v[3], float out[3])


{
GLint i, j;
GLfloat length;

out[0] = v1[1] * v2[2] - v1[2] * v2[1];


out[1] = v1[2] * v2[0] - v1[0] * v2[2];
out[2] = v1[0] * v2[1] - v1[1] * v2[0];
Normalize(out);
}

#endif

void SetMaterial(GLfloat spec[], GLfloat amb[], GLfloat diff[],


GLfloat shin[])
{

glMaterialfv(GL_FRONT, GL_SPECULAR, spec);

CSE,DSATM 2021-2022 Page | 27


Online Examination System

glMaterialfv(GL_FRONT, GL_SHININESS, shin);


glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
}

void MechTorso(char solid)


{
glNewList(SOLID_MECH_TORSO, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 0.0, 0.0);//torso red color
Box(1.0, 1.0, 3.0, solid);
glTranslatef(0.75, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 0.0, 1.0);//torso blue color
Box(0.5, 0.6, 2.0, solid);
glTranslatef(-1.5, 0.0, 0.0);
Box(0.5, 0.6, 2.0, solid);
glTranslatef(0.75, 0.0, 0.0);
glEndList();
}

void MechHip(char solid)


{
int i;

glNewList(SOLID_MECH_HIP, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 0.0);//hip lines form green
Octagon(0.7, 0.5, solid);
#ifdef SPHERE
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 1.0, 0.0);//hip line form green
if (!solid)

CSE,DSATM 2021-2022 Page | 28


Online Examination System

gluQuadricDrawStyle(qobj, GLU_LINE);
gluSphere(qobj, 0.2, 16, 16);
glTranslatef(-1.0, 0.0, 0.0);
}
glScalef(-1.0, 1.0, 1.0);
#endif
glEndList();
}

void Shoulder(char solid)


{
glNewList(SOLID_MECH_SHOULDER, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 0.0);//sholder color green
Box(1.0, 0.5, 0.5, solid);
glTranslatef(0.9, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 1.0, 0.0);// sholder color green
#ifdef SPHERE
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
gluSphere(qobj, 0.6, 16, 16);
#endif
glTranslatef(-0.9, 0.0, 0.0);
glEndList();
}

void UpperArm(char solid)


{
int i;

glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 0.0, 0.0);//arm red
Box(1.0, 2.0, 1.0, solid);
glTranslatef(0.0, -0.95, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);

CSE,DSATM 2021-2022 Page | 29


Online Examination System

#endif
glColor3f(1.0, 0.0, 0.0);//arm red
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
gluCylinder(qobj, 0.4, 0.4, 1.5, 16, 10);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 0.0);// arm joint green
glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(-0.4, -1.85, 0.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
for (i = 0; i < 2; i++) {
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
if (i)
gluCylinder(qobj, 0.5, 0.5, 0.8, 16, 10);
else
gluCylinder(qobj, 0.2, 0.2, 0.8, 16, 10);
}
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
if (i)
glTranslatef(0.0, 0.0, 0.8);
gluDisk(qobj, 0.2, 0.5, 16, 10);
if (i)
glTranslatef(0.0, 0.0, -0.8);
}
glScalef(-1.0, 1.0, 1.0);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(0.4, 2.9, 0.0);
glEndList();
}

void VulcanGun(char solid)


{
int i;

glNewList(SOLID_MECH_VULCAN, GL_COMPILE);

#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 0.0, 1.0);//gun color

CSE,DSATM 2021-2022 Page | 30


Online Examination System

if (!solid) {
gluQuadricDrawStyle(qobj, GLU_LINE);
}
gluCylinder(qobj, 0.5, 0.5, 0.5, 16, 10);

glTranslatef(0.0, 0.0, 0.5);


gluDisk(qobj, 0.0, 0.5, 16, 10);

for (i = 0; i < 5; i++) {

glRotatef(72.0, 0.0, 0.0, 1.0);


glTranslatef(0.0, 0.3, 0.0);

if (!solid) {
gluQuadricDrawStyle(qobj, GLU_LINE);
}
gluCylinder(qobj, 0.15, 0.15, 2.0, 16, 10);
gluCylinder(qobj, 0.06, 0.06, 2.0, 16, 10);
glTranslatef(0.0, 0.0, 2.0);
gluDisk(qobj, 0.1, 0.15, 16, 10);
gluCylinder(qobj, 0.1, 0.1, 0.1, 16, 5);
glTranslatef(0.0, 0.0, 0.1);
gluDisk(qobj, 0.06, 0.1, 16, 5);
glTranslatef(0.0, -0.3, -2.1);
}
glEndList();
}

void ForeArm(char solid)


{
char i;

glNewList(SOLID_MECH_FOREARM, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 1.0);//fore arm light green
for (i = 0; i < 5; i++) {
glTranslatef(0.0, -0.1, -0.15);
Box(0.6, 0.8, 0.2, solid);
glTranslatef(0.0, 0.1, -0.15);
Box(0.4, 0.6, 0.1, solid);
}
glTranslatef(0.0, 0.0, 2.45);
Box(1.0, 1.0, 2.0, solid);
glTranslatef(0.0, 0.0, -1.0);

CSE,DSATM 2021-2022 Page | 31


Online Examination System

glEndList();
}

void UpperLeg(char solid)


{
int i;

glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);//color yellow
if (!solid) {
gluQuadricDrawStyle(qobj, GLU_LINE);
}
glTranslatef(0.0, -1.0, 0.0);
Box(0.4, 1.0, 0.7, solid);
glTranslatef(0.0, -0.65, 0.0);
for (i = 0; i < 5; i++) {
Box(1.2, 0.3, 1.2, solid);
glTranslatef(0.0, -0.2, 0.0);
Box(1.0, 0.1, 1.0, solid);
glTranslatef(0.0, -0.2, 0.0);
}
glTranslatef(0.0, -0.15, -0.4);
Box(2.0, 0.5, 2.0, solid);
glTranslatef(0.0, -0.3, -0.2);
glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);//leg joints grey
gluCylinder(qobj, 0.6, 0.6, 3.0, 16, 10);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 0.0);//above the leg joint n below the fore leg
glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, -1.5, 1.0);
Box(1.5, 3.0, 0.5, solid);
glTranslatef(0.0, -1.75, -0.8);
Box(2.0, 0.5, 2.0, solid);
glTranslatef(0.0, -0.9, -0.85);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);

CSE,DSATM 2021-2022 Page | 32


Online Examination System

#endif
glColor3f(1.0, 0.0, 0.0);//leg joints between fore leg and leg
gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
if (i)
glTranslatef(0.0, 0.0, 1.8);
gluDisk(qobj, 0.0, 0.8, 16, 10);
if (i)
glTranslatef(0.0, 0.0, -1.8);
}
glScalef(-1.0, 1.0, 1.0);
glEndList();
}

void Foot(char solid)


{

glNewList(SOLID_MECH_FOOT, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(1.0, 0.0, 0.0);// color foot
glRotatef(90.0, 1.0, 0.0, 0.0);
Octagon(1.5, 0.6, solid);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glEndList();
}

void LowerLeg(char solid)


{
float k, l;

#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 0.0, 0.0);//leg joint
for (k = 0.0; k < 2.0; k++) {
for (l = 0.0; l < 2.0; l++) {
glPushMatrix();
glTranslatef(k, 0.0, l);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);

CSE,DSATM 2021-2022 Page | 33


Online Examination System

#endif
glColor3f(1.0, 0.0, 0.0);//red
Box(1.0, 0.5, 1.0, solid);
glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(1.0, 0.0, 0.0);
#ifdef SPHERE
if (!solid)
glutWireSphere(0.2, 16, 10);
else
glutSolidSphere(0.2, 16, 10);
#endif
if (leg)
glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);
/* glTranslatef(0.0, -0.2, 0.0); */
glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 0.0, 0.0);//color of the below leg( pillers)
Box(0.25, 3.0, 0.25, solid);
glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 0.0, 1.0);//joints
#ifdef SPHERE
if (!solid)
glutWireSphere(0.2, 16, 10);
else
glutSolidSphere(0.2, 16, 10);
#endif
if (leg)
glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);
glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(0.0, 1.0, 0.0);// leg n foot joints color

CSE,DSATM 2021-2022 Page | 34


Online Examination System

Box(1.0, 0.5, 1.0, solid);


if (!k && !l) {
int j;

glTranslatef(-0.4, -0.8, 0.5);


if (leg)
glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10);
for (j = 0; j < 2; j++) {
if (!solid)
gluQuadricDrawStyle(qobj, GLU_LINE);
if (j) {
glScalef(-1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, 1.8);
}
gluDisk(qobj, 0.0, 0.8, 16, 10);
if (j)
glTranslatef(0.0, 0.0, -1.8);
}
glScalef(-1.0, 1.0, 1.0);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(0.95, -0.8, 0.0);
glCallList(SOLID_MECH_FOOT);
}
glPopMatrix();
}
}
}

void RocketPod(char solid)


{

int i, j, k = 0;

glNewList(SOLID_MECH_ROCKET, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glColor3f(0.0, 1.0, 0.0);//rocket port color
glScalef(0.4, 0.4, 0.4);
glRotatef(45.0, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
Box(2.0, 0.5, 3.0, solid);

CSE,DSATM 2021-2022 Page | 35


Online Examination System

glTranslatef(1.0, 0.0, 0.0);


glRotatef(45.0, 0.0, 0.0, 1.0);
glTranslatef(0.5, 0.0, 0.0);
Box(1.2, 0.5, 3.0, solid);
glTranslatef(2.1, 0.0, 0.0);
glRotatef(-90.0, 0.0, 0.0, 1.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse,
mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(2.0, 3.0, 4.0, solid);
glTranslatef(-0.5, -1.0, 1.3);
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
if (!solid) {
gluQuadricDrawStyle(qobj, GLU_LINE);
}
glTranslatef(i, j, 0.6);
#ifdef LIGHT
SetMaterial(mat_specular3, mat_ambient3, mat_diffuse3,
mat_shininess3);
#endif
glColor3f(1.0, 1.0, 1.0);
gluCylinder(qobj, 0.4, 0.4, 0.3, 16, 10);
glTranslatef(0.0, 0.0, 0.3);
#ifdef LIGHT
SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4,
mat_shininess4);
#endif
glColor3f(0.0, 1.0, 0.0);
gluCylinder(qobj, 0.4, 0.0, 0.5, 16, 10);
k++;
glTranslatef(-i, -j, -0.9);
}
}
glEndList();
}

void Enviro(char solid)


{

int i, j;

glNewList(SOLID_ENVIRO, GL_COMPILE);
SetMaterial(mat_specular4, mat_ambient4, mat_diffuse4,
mat_shininess4);
glColor3f(1.0, 1.0, 0.0);//out line of the walking path
Box(20.0, 0.5, 30.0, solid);

CSE,DSATM 2021-2022 Page | 36


Online Examination System

SetMaterial(mat_specular4, mat_ambient3, mat_diffuse2,


mat_shininess);
glColor3f(1.0, 0.0, 0.0);//the surrounding area color
glTranslatef(0.0, 0.0, -10.0);
for (j = 0; j < 6; j++) {
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
glTranslatef(10.0, 4.0, 0.0);
Box(4.0, 8.0, 2.0, solid);
glTranslatef(0.0, -1.0, -3.0);
Box(4.0, 6.0, 2.0, solid);
glTranslatef(-10.0, -3.0, 3.0);
}
glScalef(-1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, 5.0);
}
glEndList();
}

void Toggle(void)
{
if (solid_part)
solid_part = 0;
else
solid_part = 1;
}

void disable(void)
{
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_NORMALIZE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

void lighting(void)
{

GLfloat position[] =
{0.0, 0.0, 2.0, 1.0};

#ifdef MOVE_LIGHT
glRotatef((GLfloat) lightturn1, 1.0, 0.0, 0.0);
glRotatef((GLfloat) lightturn, 0.0, 1.0, 0.0);
glRotatef(0.0, 1.0, 0.0, 0.0);
#endif
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

CSE,DSATM 2021-2022 Page | 37


Online Examination System

glEnable(GL_NORMALIZE);
glDepthFunc(GL_LESS);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

glLightfv(GL_LIGHT0, GL_POSITION, position);


glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 80.0);

glTranslatef(0.0, 0.0, 2.0);


glDisable(GL_LIGHTING);
Box(0.1, 0.1, 0.1, 0);
glEnable(GL_LIGHTING);
}

void DrawMech(void)
{
int i, j;

glScalef(0.5, 0.5, 0.5);


glPushMatrix();
glTranslatef(0.0, -0.75, 0.0);
glRotatef((GLfloat) tilt, 1.0, 0.0, 0.0);

glRotatef(90.0, 1.0, 0.0, 0.0);


#ifdef HIP
glCallList(SOLID_MECH_HIP);
#endif
glRotatef(-90.0, 1.0, 0.0, 0.0);

glTranslatef(0.0, 0.75, 0.0);


glPushMatrix();
glRotatef((GLfloat) pivot, 0.0, 1.0, 0.0);
glPushMatrix();
#ifdef TORSO
glCallList(SOLID_MECH_TORSO);
#endif
glPopMatrix();
glPushMatrix();
glTranslatef(0.5, 0.5, 0.0);
#ifdef ROCKET_POD
glCallList(SOLID_MECH_ROCKET);
#endif
glPopMatrix();
for (i = 0; i < 2; i++) {
glPushMatrix();
if (i)
glScalef(-1.0, 1.0, 1.0);
glTranslatef(1.5, 0.0, 0.0);
#ifdef SHOULDER
glCallList(SOLID_MECH_SHOULDER);

CSE,DSATM 2021-2022 Page | 38


Online Examination System

#endif
glTranslatef(0.9, 0.0, 0.0);
if (i) {
glRotatef((GLfloat) lat1, 0.0, 0.0, 1.0);
glRotatef((GLfloat) shoulder1, 1.0, 0.0, 0.0);
glRotatef((GLfloat) shoulder3, 0.0, 1.0, 0.0);
} else {
glRotatef((GLfloat) lat2, 0.0, 0.0, 1.0);
glRotatef((GLfloat) shoulder2, 1.0, 0.0, 0.0);
glRotatef((GLfloat) shoulder4, 0.0, 1.0, 0.0);
}
glTranslatef(0.0, -1.4, 0.0);
#ifdef UPPER_ARM
glCallList(SOLID_MECH_UPPER_ARM);
#endif
glTranslatef(0.0, -2.9, 0.0);
if (i)
glRotatef((GLfloat) elbow1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) elbow2, 1.0, 0.0, 0.0);
glTranslatef(0.0, -0.9, -0.2);
#ifdef LOWER_ARM
glCallList(SOLID_MECH_FOREARM);
glPushMatrix();
glTranslatef(0.0, 0.0, 2.0);
glRotatef((GLfloat) fire, 0.0, 0.0, 1.0);
glCallList(SOLID_MECH_VULCAN);
glPopMatrix();
#endif
glPopMatrix();
}
glPopMatrix();

glPopMatrix();

for (j = 0; j < 2; j++) {


glPushMatrix();
if (j) {
glScalef(-0.5, 0.5, 0.5);
leg = 1;
} else {
glScalef(0.5, 0.5, 0.5);
leg = 0;
}
glTranslatef(2.0, -1.5, 0.0);
if (j) {
glRotatef((GLfloat) hip11, 1.0, 0.0, 0.0);
glRotatef((GLfloat) hip12, 0.0, 0.0, 1.0);
} else {

CSE,DSATM 2021-2022 Page | 39


Online Examination System

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


glRotatef((GLfloat) hip22, 0.0, 0.0, 1.0);
}
glTranslatef(0.0, 0.3, 0.0);
#ifdef UPPER_LEG
glPushMatrix();
glCallList(SOLID_MECH_UPPER_LEG);
glPopMatrix();
#endif
glTranslatef(0.0, -8.3, -0.4);
if (j)
glRotatef((GLfloat) - hip12, 0.0, 0.0, 1.0);
else
glRotatef((GLfloat) - hip22, 0.0, 0.0, 1.0);
glTranslatef(-0.5, -0.85, -0.5);
#ifdef LOWER_LEG
LowerLeg(1);
#endif
glPopMatrix();
}
}

void display(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
//glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glRotatef((GLfloat) turn, 0.0, 1.0, 0.0);
glRotatef((GLfloat) turn1, 1.0, 0.0, 0.0);
#ifdef LIGHT
if (solid_part) {
glPushMatrix();
lighting();
glPopMatrix();
} else
disable();
#endif
#ifdef DRAW_MECH
glPushMatrix();
glTranslatef(0.0, elevation, 0.0);
DrawMech();
glPopMatrix();
#endif
#ifdef DRAW_ENVIRO
glPushMatrix();
if (distance >= 20.136)

CSE,DSATM 2021-2022 Page | 40


Online Examination System

distance = 0.0;
glTranslatef(0.0, -5.0, -distance);
glCallList(SOLID_ENVIRO);
glTranslatef(0.0, 0.0, 10.0);
glCallList(SOLID_ENVIRO);
glPopMatrix();
#endif
glPopMatrix();

glLoadName(TEXTID);
glColor3f(1,1,0);
DrawTextXY(-2.5,0.2,2.0,0.0015,"1ce09cs009");
DrawTextXY(-2.5,0.5,2.0,0.0015,"ARMUGAM(AARU)");
DrawTextXY(2.5,2.2,-2.0,0.0025,"1ce09cs002");
DrawTextXY(2.5,2.7,-2.0,0.0030,"ABDUL");
glFlush();
glutSwapBuffers();

void myinit(void)
{
char i = 1;

qobj = gluNewQuadric();
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2,
mat_shininess2);
#endif
glEnable(GL_DEPTH_TEST);
MechTorso(i);
MechHip(i);
Shoulder(i);
RocketPod(i);
UpperArm(i);
ForeArm(i);
UpperLeg(i);
Foot(i);
VulcanGun(i);
Enviro(i);
}

void myReshape(int w, int h)


{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 1.0, 20.0);

CSE,DSATM 2021-2022 Page | 41


Online Examination System

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 1.2, -5.5); /* viewing transform */
}

#ifdef ANIMATION
void animation_walk(void)

{
float angle;
static int step;

if (step == 0 || step == 2) {

if (frame >= 0.0 && frame <= 21.0) {


if (frame == 0.0)
frame = 3.0;
angle = (180 / M_PI) * (acos(((cos((M_PI / 180) * frame) *
2.043) + 1.1625) / 3.2059));
if (frame > 0) {
elevation = -(3.2055 - (cos((M_PI / 180) * angle) * 3.2055));
} else
elevation = 0.0;
if (step == 0) {
hip11 = -(frame * 1.7);
if (1.7 * frame > 15)
heel1 = frame * 1.7;
heel2 = 0;
ankle1 = frame * 1.7;
if (frame > 0)
hip21 = angle;
else
hip21 = 0;
ankle2 = -hip21;
shoulder1 = frame * 1.5;
shoulder2 = -frame * 1.5;
elbow1 = frame;
elbow2 = -frame;
} else {
hip21 = -(frame * 1.7);
if (1.7 * frame > 15)
heel2 = frame * 1.7;
heel1 = 0;
ankle2 = frame * 1.7;
if (frame > 0)
hip11 = angle;
else
hip11 = 0;
ankle1 = -hip11;

CSE,DSATM 2021-2022 Page | 42


Online Examination System

shoulder1 = -frame * 1.5;


shoulder2 = frame * 1.5;
elbow1 = -frame;
elbow2 = frame;
}
if (frame == 21)
step++;
if (frame < 21)
frame = frame + 3.0;
}
}
if (step == 1 || step == 3) {

if (frame <= 21.0 && frame >= 0.0) {


angle = (180 / M_PI) * (acos(((cos((M_PI / 180) * frame) *
2.043) + 1.1625) / 3.2029));
if (frame > 0)
elevation = -(3.2055 - (cos((M_PI / 180) * angle) * 3.2055));
else
elevation = 0.0;
if (step == 1) {
elbow2 = hip11 = -frame;
elbow1 = heel1 = frame;
heel2 = 15;
ankle1 = frame;
if (frame > 0)
hip21 = angle;
else
hip21 = 0;
ankle2 = -hip21;
shoulder1 = 1.5 * frame;
shoulder2 = -frame * 1.5;
} else {
elbow1 = hip21 = -frame;
elbow2 = heel2 = frame;
heel1 = 15;
ankle2 = frame;
if (frame > 0)
hip11 = angle;
else
hip11 = 0;
ankle1 = -hip11;
shoulder1 = -frame * 1.5;
shoulder2 = frame * 1.5;
}
if (frame == 0.0)
step++;
if (frame > 0)
frame = frame - 3.0;

CSE,DSATM 2021-2022 Page | 43


Online Examination System

}
}
if (step == 4)
step = 0;
distance += 0.1678;
glutPostRedisplay();
}

void animation(void)
{
animation_walk();
}

#endif

#ifdef GLUT
#ifdef GLUT_KEY
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{

int i = 0;
if (key == 27) exit (0);
switch (key) {
/* start arm control functions */
case 'q':{
shoulder2Subtract();
i++;
i++;
}
break;
case 'a':{
shoulder2Add();
i++;
}
break;
case 'w':{
shoulder1Subtract();
i++;
}
break;
case 's':{
shoulder1Add();
i++;
}
break;
case '2':{
shoulder3Add();
i++;

CSE,DSATM 2021-2022 Page | 44


Online Examination System

}
break;
case '1':{
shoulder4Add();
i++;
}
break;
case '4':{
shoulder3Subtract();
i++;
}
break;
case '3':{
shoulder4Subtract();
i++;
}
break;

case 'z':{
lat2Raise();
i++;
}
break;
case 'Z':{
lat2Lower();
i++;
}
break;
case 'x':{
lat1Raise();
i++;
}
break;
case 'X':{
lat1Lower();
i++;
}
break;

case 'A':{
elbow2Add();
i++;
}
break;
case 'Q':{
elbow2Subtract();
i++;
}
break;

CSE,DSATM 2021-2022 Page | 45


Online Examination System

case 'S':{
elbow1Add();
i++;
}
break;
case 'W':{
elbow1Subtract();
i++;
}
break;
/* end of arm control functions */

/* start of torso control functions */


case 'd':{
RotateAdd();
i++;
}
break;
case 'g':{
RotateSubtract();
i++;
}
break;
case 'r':{
MechTiltAdd();
i++;
}
break;
case 'f':{
MechTiltSubtract();
i++;
}
break;
/* end of torso control functions */

/* start of leg control functions */


case 'h':{
RaiseLeg2Forward();
i++;
}
break;
case 'y':{
LowerLeg2Backwards();
i++;
}
break;
case 'Y':{
RaiseLeg2Outwards();
i++;

CSE,DSATM 2021-2022 Page | 46


Online Examination System

}
break;
case 'H':{
LowerLeg2Inwards();
i++;
}
break;

case 'j':{
RaiseLeg1Forward();
i++;
}
break;
case 'u':{
LowerLeg1Backwards();
i++;
}
break;
case 'U':{
RaiseLeg1Outwards();
i++;
}
break;
case 'J':{
LowerLeg1Inwards();
i++;
}
break;

case 'N':{
Heel2Add();
i++;
}
break;
case 'n':{
Heel2Subtract();
i++;
}
break;
case 'M':{
Heel1Add();
i++;
}
break;
case 'm':{
Heel1Subtract();
i++;
}
break;

CSE,DSATM 2021-2022 Page | 47


Online Examination System

case 'k':{
Ankle2Add();
i++;
}
break;
case 'K':{
Ankle2Subtract();
i++;
}
break;
case 'l':{
Ankle1Add();
i++;
}
break;
case 'L':{
Ankle1Subtract();
i++;
}
break;
/* end of leg control functions */

/* start of light source position functions */


case 'p':{
LightTurnRight();
i++;
}
break;
case 'i':{
LightTurnLeft();
i++;
}
break;
case 'o':{
LightForwards();
i++;
}
break;
case '9':{
LightBackwards();
i++;
}
break;

/* end of light source position functions */


}
if (i)
glutPostRedisplay();

CSE,DSATM 2021-2022 Page | 48


Online Examination System

#endif

#ifdef GLUT_SPEC
/* ARGSUSED1 */
void special(int key, int x, int y)
{

int i = 0;

switch (key) {
/* start of view position functions */
case GLUT_KEY_RIGHT:{
TurnRight();
i++;
}
break;
case GLUT_KEY_LEFT:{
TurnLeft();
i++;
}
break;
case GLUT_KEY_DOWN:{
TurnForwards();
i++;
}
break;
case GLUT_KEY_UP:{
TurnBackwards();
i++;
}
break;
/* end of view postions functions */
/* start of miseclleneous functions */
case GLUT_KEY_PAGE_UP:{
FireCannon();
i++;
}
break;
/* end of miscelleneous functions */

}
if (i)
glutPostRedisplay();
}

#endif
#endif

CSE,DSATM 2021-2022 Page | 49


Online Examination System

void menu_select(int mode)


{
switch (mode) {
#ifdef ANIMATION
case 1:
glutIdleFunc(animation);
break;
#endif
case 2:
glutIdleFunc(NULL);
break;
case 3:
Toggle();
glutPostRedisplay();
break;
case 4:
exit(EXIT_SUCCESS);

}
}

/* ARGSUSED */
void null_select(int mode)
{
}

void glutMenu(void)
{

int glut_menu[13];

glut_menu[5] = glutCreateMenu(null_select);
glutAddMenuEntry("forward : q,w", 0);
glutAddMenuEntry("backwards : a,s", 0);
glutAddMenuEntry("outwards : z,x", 0);
glutAddMenuEntry("inwards : Z,X", 0);

glut_menu[6] = glutCreateMenu(null_select);
glutAddMenuEntry("upwards : Q,W", 0);
glutAddMenuEntry("downwards : A,S", 0);
glutAddMenuEntry("outwards : 1,2", 0);
glutAddMenuEntry("inwards : 3,4", 0);

glut_menu[1] = glutCreateMenu(null_select);
glutAddMenuEntry(" : Page_up", 0);

glut_menu[8] = glutCreateMenu(null_select);
glutAddMenuEntry("forward : y,u", 0);
glutAddMenuEntry("backwards : h.j", 0);

CSE,DSATM 2021-2022 Page | 50


Online Examination System

glutAddMenuEntry("outwards : Y,U", 0);


glutAddMenuEntry("inwards : H,J", 0);

glut_menu[9] = glutCreateMenu(null_select);
glutAddMenuEntry("forward : n,m", 0);
glutAddMenuEntry("backwards : N,M", 0);

glut_menu[10] = glutCreateMenu(null_select);
glutAddMenuEntry("toes up : K,L", 0);
glutAddMenuEntry("toes down : k,l", 0);

glut_menu[11] = glutCreateMenu(null_select);
glutAddMenuEntry("right : right arrow", 0);
glutAddMenuEntry("left : left arrow", 0);
glutAddMenuEntry("down : up arrow", 0);
glutAddMenuEntry("up : down arrow", 0);

glut_menu[12] = glutCreateMenu(null_select);
glutAddMenuEntry("right : p", 0);
glutAddMenuEntry("left : i", 0);
glutAddMenuEntry("up : 9", 0);
glutAddMenuEntry("down : o", 0);

glut_menu[4] = glutCreateMenu(NULL);
glutAddSubMenu("at the shoulders? ", glut_menu[5]);
glutAddSubMenu("at the elbows?", glut_menu[6]);

glut_menu[7] = glutCreateMenu(NULL);
glutAddSubMenu("at the bottompart? ", glut_menu[8]);
glutAddSubMenu("at the knees?", glut_menu[9]);
glutAddSubMenu("at the ankles? ", glut_menu[10]);

glut_menu[2] = glutCreateMenu(null_select);
glutAddMenuEntry("turn left : d", 0);
glutAddMenuEntry("turn right : g", 0);
glutAddMenuEntry("Rocketpod : v", 0);

glut_menu[3] = glutCreateMenu(null_select);
glutAddMenuEntry("tilt backwards : f", 0);
glutAddMenuEntry("tilt forwards : r", 0);

glut_menu[0] = glutCreateMenu(NULL);
glutAddSubMenu("move the arms.. ", glut_menu[4]);
glutAddSubMenu("fire the vulcan guns?", glut_menu[1]);
glutAddSubMenu("move the legs.. ", glut_menu[7]);
glutAddSubMenu("move the torso?", glut_menu[2]);
glutAddSubMenu("move the upper portion?", glut_menu[3]);
glutAddSubMenu("rotate the scene..", glut_menu[11]);

CSE,DSATM 2021-2022 Page | 51


Online Examination System

#ifdef MOVE_LIGHT
glutAddSubMenu("rotate the light source..", glut_menu[12]);
#endif

glutCreateMenu(menu_select);
#ifdef ANIMATION
glutAddMenuEntry("Start Walk", 1);
glutAddMenuEntry("Stop Walk", 2);
#endif
glutAddMenuEntry("Toggle Wireframe", 3);
glutAddSubMenu("How do I ..", glut_menu[0]);
glutAddMenuEntry("Quit", 4);
glutAttachMenu(GLUT_LEFT_BUTTON);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}

int main(int argc, char **argv)


{
#ifdef GLUT
/* start of glut windowing and control functions */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA |
GLUT_DEPTH);
glutInitWindowSize(1000, 1000);
glutCreateWindow("glutmech: Vulcan Gunner");
myinit();
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
#ifdef GLUT_KEY
glutKeyboardFunc(keyboard);
#endif
#ifdef GLUT_SPEC
glutSpecialFunc(special);
#endif
glutMenu();
glPointSize(2.0);
glutMainLoop();
/* end of glut windowing and control functions */
#endif
return 0; /* ANSI C requires main to return int. */
}

CSE,DSATM 2021-2022 Page | 52


Online Examination System

A.2 User Manual


Enter any key on the visualizer window, you will be asked for four options

1. Description
2. Incident a ray of light
3. See the refraction
4. Quit
Depending on the selection the corresponding output will be displayed.

Make sure that the folder ‘Snells’Law’ is copied to the C:\ drive ONLY

A.3 Personal Details

NAME: NIKET AGRAWAL


USN: 1DT19CS095
SEMESTER AND SECTION: 6TH SEM, B SEC
DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING
EMAIL ID: [email protected]

NAME: PRUTHIVIKA V
USN: 1DT19CS119
SEMESTER AND SECTION: 6TH SEM, B SEC
DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING
EMAIL ID: [email protected]

CSE,DSATM 2021-2022 Page | 53

You might also like