You are on page 1of 20

Plane Simulation

1. INTRODUCTION

1.1. COMPUTER GRAPHICS

The term computer graphics includes almost everything on computers that is not
text or sound. Today nearly all computers use some graphics and users expect to control
their computer through icons and pictures rather than just by typing. The term Computer
Graphics has several meanings.

 The representation and manipulation of pictorial data by a computer


 The various technologies used to create and manipulate such pictorial data
 The images so produced, and
 The sub-field of computer science which studies methods for digitally
synthesizing and manipulating visual content see study of computer graphics.

Today computers and computer-generated images touch many aspects of our daily
life. Computer imagery is found on television, in newspapers, in weather reports, and
during surgical procedures. A well-constructed graph can present complex statistics in
a form that is easier to understand and interpret. Such graphs are used to illustrate
papers, reports, theses, and other presentation material. A range of tools and facilities
are available to enable users to visualize their data, and computer graphics are used in
many disciplines.

1.2. VISUALIZATION

Visualization is any technique for creating images, diagrams, or animations to


communicate a message.Visualization through visual imagery have been an effective way
to communicate both abstract and concrete ideas since the dawn of man. Examples from
history include Egyptian hieroglyphs, Greek geometry, and Leonardo da Vinci’s
revolutionary methods of technical drawing for engineering and scientific purposes.

Visualization today has ever-expanding applications in science, education,


engineering (e.g. product visualization),interactive multimedia, medicine, etc. Typical of
a visualization application is the field of computer graphics.The invention of computer
graphics may be the most important development in visualization since the invention of
central perspective in the Renaissance period. The development of animation also helped
advance visualization.

Dept. of CSE , EWIT 2018-2019 Page 1


Plane Simulation

Models and frameworks for building visualizations include the data flow models
popularized by systems such as AVS,IRIS Explorer, and VTK toolkit, and data state
models in spreadsheet systems such as the spreadsheet for Visualization and Spreadsheet
for images.

Simplified version of the graphics pipeline process;excludes a number of features like


blending, VBOs and logc ops.

2. OVERVIEW OF OPENGL API

OpenGL (Open Graphics Library) is a standard specification defining a cross


language, cross-platform API for writing applications that produce 2D and 3D computer
graphics. The interface consists of over 250 different function calls which can be used to
draw complex three-dimensional scenes from simple primitives. OpenGL was developed
by Silicon Graphics Inc. (SGI) in 1992 and is widely used in CAD, virtual reality,
scientific visualization, information visualization, and flight simulation. It is also used in
video games, where it competes with Direct3D on Microsoft Windows platforms.
OpenGL is managed by the non-profit technology consortium, the Khronos Group.

2.1. SPECIFICATION:

At its most basic level OpenGL is specification, meaning it is simply a document that
describes a set of functions and the precise behaviors that they must perform, from this
specification, hardware vendors create implementations---libraries of functions created to
match the functions stated in the OpenGL specification, making use of hardware
acceleration where possible. Hardware vendors have to meet specific tests to be able to
qualify their implementation as an OpenGL implementation.

Dept. of CSE , EWIT 2018-2019 Page 2


Plane Simulation

Efficient vendor-supplied implementations of OpenGL (making use of graphics


acceleration hardware to a greater or lesser extent) exist for MAC OS, Microsoft
Windows, Linux and many UNIX platforms. Various software implementations exist,
bringing OpenGL to a variety of platforms that do not have vendor support. Notably, the
free software/open source library Mesa 3D is a fully software-based graphics API which
is code-compatible with OpenGL

2.2 OVERVIEW:

OpenGL (Open Graphics Library) is a standard specification defining a cross-


language, cross-platform API for writing applications that produce 2D and 3D computer
graphics. The interface consists of over 250 different function calls which can be used to
draw complex three-dimensional scenes from simple primitives. OpenGL was developed
by Silicon Graphics Inc. (SGI) in 1992and is widely used in CAD, virtual reality,
scientific visualization, information visualization, and flight simulation. It is also used in
video games, where it competes with Direct3D on Microsoft Windows platforms.
OpenGL is managed by the non-profit technology consortium, the Khronos Group.
OpenGL serves two main purposes:

 To hide the complexities of interfacing with different 3D accelerators, by


presenting the programmer with a single, uniform API.
 To hide the differing capabilities of hardware platforms, by requiring that all
implementations support the full OpenGL feature set (using software emulation if
necessary).

OpenGL's basic operation is to accept primitives such as points, lines and


polygons, and convert them into pixels. This is done by a graphics pipeline known as
the OpenGL state machine. Rasterised points, lines and polygons as basic primitives.

2.3 GLUT

GLUT is a complete API written by Mark Kilgard which lets you create windows
and handle the messages. It exists for several platforms that means that a program which
uses GLUT can be compiled on many platforms without (or at least with very few)
changes in the code.

Dept. of CSE , EWIT 2018-2019 Page 3


Plane Simulation

3.SYSTEM REQUIREMENTS

Functional Requirements

Functional Requirements defines a function of a software system or its


component.

Non Functional Requirements

Non Functional Requirements are qualities or standards that the system under
development must have or comply with, but which are not tasks that will be automated by
the system

3.1 SOFTWARE REQUIREMENTS

 Operating System: Ubuntu


 Tool:OpenGL

3.2 HARDWARE REQUIREMENTS

 Processor: Intel(R) Core™i3-60060U CPU@ 2.00 GHz 2.00 GHz


 Memory(RAM): 4.00 GB
 System Type: 64-bit Operating System,x64-based processor.

Dept. of CSE , EWIT 2018-2019 Page 4


Plane Simulation

3.3 FLOWCHART
START

Interrup
Yes t
No
Z z
keyboa Airplane is
rd not moved
Rotate Rotate
clockwise anticlockwise
a c
keyboa
rd

animate Move
camera

1 keyboa 2
rd

ULF
UF

3 4
keyboa
rd

URF LF
5 6

keyboa
rd
F RF

7 keyboa 8
rd
D---- Down
DLF DF
9 q U----- Up
keyboa
rd L------- Left
DRF EXIT
R ----- Right

Dept. of CSE , EWIT 2018-2019 Page 5


Plane Simulation

4.IMPLEMENTATION

4.1 MODULES

 draw_airplane()
this function is used to airplane model having different regions
such as nose , tail, body 1/2 , body 2/2 ,left wing , right wing,left
wingtip , right wingtip , left flap , right flap,tailwing,rudder,cockpit
left front,cockpit right front,cockpit left back,cockpit right
back,cockpit top.
 animate()
this function is used to animate the airplane model.
 move_camera()
this function is used to move the airplane in all directions.
 keyboard()
this function deals with normal events originating from keyboard.
 display()

This function is used to draw the actual graphical implementation


of the air-plane model

4.2 SOURCE CODE

/* airplane_gl.c - OpenGL airplane simulator

void draw_airplane (void);

void animate(void);

void move_camera(void);

void display (void) {

/* Clear the display before redrawing it. */

glClearColor (0.0, 0.0, 1.0, 0.0);

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |


GL_STENCIL_BUFFER_BIT);

glEnable (GL_STENCIL_TEST);glPushMatrix ();

Dept. of CSE , EWIT 2018-2019 Page 6


Plane Simulation

glEnable (GL_DEPTH_TEST);

glStencilFunc (GL_ALWAYS, 1, 1);

glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE);

glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

//draw_ground();

glColor3f(1.0,1.5,5.0); //change color of plane

draw_airplane ();

glClearDepth (1.0f);

Depth Buffer Setup

glDepthFunc (GL_LEQUAL);
// The Type Of Depth Testing

glEnable (GL_DEPTH_TEST);

glEnable (GL_LINE_SMOOTH);

glDisable (GL_DEPTH_TEST);

glStencilFunc (GL_EQUAL, 1, 1);

glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);

glLineWidth (2);PolygonMode (GL_FRONT_AND_BACK, GL_LINE);

glColor3f(.01,.01,.01);

draw_airplane (); glPopMatrix ();

glutSwapBuffers ();

void animate ()

glTranslatef(0,0,0.1);

glutPostRedisplay();

Dept. of CSE , EWIT 2018-2019 Page 7


Plane Simulation

void move_camera()

glTranslatef(0,0,-0.1);

glutPostRedisplay();

void draw_airplane (void) {

int stencil;

/* Find out current stencil function. */

glGetIntegerv (GL_STENCIL_FUNC, &stencil);

/* Describe airplane using simple concave polygons.

* See `airplane-blueprint' for details. */

glStencilFunc (stencil, 1, 0xf);

glBegin (GL_POLYGON); /*nose*/

glEdgeFlag (1);

glVertex3f (0,-1, 10);

glEdgeFlag (0);

glVertex3f (2, 0, 4);

glEdgeFlag (1);

glVertex3f (-2, 0, 4);

glEnd (); glStencilFunc (stencil, 2, 0xf);

glBegin (GL_POLYGON); /*tail*/

glEdgeFlag (1);

glVertex3f ( 1, 0, -3);

Dept. of CSE , EWIT 2018-2019 Page 8


Plane Simulation

glVertex3f ( 3, 0, -4);

glVertex3f ( 3, 0, -5);

glVertex3f (-3, 0, -5);

glVertex3f (-3, 0, -4);

glEdgeFlag (0);

glVertex3f (-1, 0, -3);

glEnd ();

glBegin (GL_POLYGON); /*body 1/2*/

glEdgeFlag (0);

glVertex3f ( 2, 0, 4);

glEdgeFlag (1);

glVertex3f ( 2, 0, -.5);

glVertex3f ( 2, 0, -1);

glEdgeFlag (0);

glVertex3f ( 1, 0, -1);

glEdgeFlag (1);

glVertex3f (-1, 0, -1);

glVertex3f (-2, 0, -1);

glEdgeFlag (0);

glVertex3f (-2, 0, -.5);

glVertex3f (-2, 0, 4);

glEnd (); glBegin (GL_POLYGON); /*body 2/2*/

glEdgeFlag (1);

glVertex3f ( 1, 0, -1);

Dept. of CSE , EWIT 2018-2019 Page 9


Plane Simulation

glEdgeFlag (0);

glVertex3f ( 1, 0, -3);

glEdgeFlag (1);

glVertex3f (-1, 0, -3);

glEdgeFlag (0);

glVertex3f (-1, 0, -1);

glEnd ();

void reshape (int width, int height)

if (height==0) // Prevent A Divide By Zero By

height=1; // Making Height Equal One

} glViewport (0, 0, (GLsizei) width, (GLsizei) height);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix

glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

gluLookAt (0,10,-25, 0,0,0, 0,1,0);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

glLoadIdentity(); // Reset The Modelview Matrix

int main (int argc, char *argv[])

/* Re-set the world transformation. */

Dept. of CSE , EWIT 2018-2019 Page 10


Plane Simulation

//glLoadIdentity ();

//glRotatef (-45, 0, 1, 0);

printf("\nControls\n");

printf("\nD-DOWN U-UP L-LEFT R-RIGHT\n");

printf("-------------------------------------------");

printf("\n 7(D L F) 8 (D F) 9(D R F) \n ");

printf("\n 4(L F) 5(F) 6(R F)\n");

printf("\n 1(U L F) 2(U F) 3(U R F)\n");

printf("-------------------------------------------");

printf("\n*******************************************");

printf("\n Extra Functions for simulation purpose only\n");

printf("-------------------------------------------");

printf("\n c-Move Camera a-Animate\n");

printf("\n Z-Rotate Clockwise z-Rotate Anticlockwise\n");

printf("-------------------------------------------");

printf("\n*******************************************");

printf("\nPress any key to continue......");

char dummy;

scanf("%c",&dummy);

/* Initialize the window. */

glutInit (&argc, argv);

glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH |


GLUT_STENCIL);

glutInitWindowSize (800, 800);

glutCreateWindow (argv[0]);

Dept. of CSE , EWIT 2018-2019 Page 11


Plane Simulation

glutDisplayFunc (display);

glutReshapeFunc (reshape);

glutKeyboardFunc (keyboard);

if(animation)glutIdleFunc(animate);

if(mvcam)glutIdleFunc(move_camera);

glutFullScreen();

glutMainLoop ();

return EXIT

Dept. of CSE , EWIT 2018-2019 Page 12


Plane Simulation

4.3 OpenGL FUNCTIONS USED

 glColor3f()
o Sets the current color.
o Syntax: glColor3f(GLfloatred,GLfloatgreen,GLfloat blue);

 glutBitmapCharacter()
o glutBitmapCharacter renders a bitmap character using OpenGL.
o Syntax: void glutBitmapCharacter(void *font, int character);
 glClearColor()
o The glClearColor function specifies clear values for the color
buffers.
o Syntax: glClearColor(GLclampf red, GLclampf green, GLclampf
blue,GLclampf alpha);

 glClear()
o The glClear function clears buffers to preset values.
o Syntax: glClear(GLbitfield mask);
 glFlush()
o The glFlush function forces execution of OpenGL functions in
finite time.
o Syntax: glFlush(void);

 glutPostRedisplay()
o glutPostRedisplay marks the current window as needing to be
redisplayed.
o Syntax: glutPostRedisplay(void);

 glutSwapBuffers()
o glutSwapBuffers swaps the buffers of the current window if double
buffered.
o Syntax: glutSwapBuffers(void);

Dept. of CSE , EWIT 2018-2019 Page 13


Plane Simulation

 glPushMatrix()
o Used to push the current matrix onto stack
o Syntax: glPushMatrix(void);

 glScaled()
o The glScaled function multiplies the current matrix by a general
scaling matrix.
o Syntax: glScaled(GLfloatx,GLfloaty,GLfloat z);

 glBegin()
o The glBegin function delimits the beginning of vertices of a
primitive or a group of like primitives
o Syntax: glBegin(GLenum mode);

 glVertex2f()
o Specifies a vertex on the screen
o Syntax: glVertex2f(GLfloatx,GLfloat y);
 .glEnd()
o The glend function delimits the end of vertices of a primitive or a
group of like primitives
o Syntax: glEnd(void);

 glPopMatrix()
o Pop the current matrix from the stack.
o Syntax: glPopMatrix(void);

 glTranslated()
o The glTranslated function multiplies the current matrix by a
translation matrix.
o Syntax: glTranslated(GLfloatx,GLfloaty,GLfloat z);

Dept. of CSE , EWIT 2018-2019 Page 14


Plane Simulation

5.TESTING

I modeled the scene using wings 3d; I used a flat rectangular surface. The models for the
scene and the plane were loaded as .obj files. To move the plane I used openGL
transformations namely glTranslatef(), the use of these transformations allowed
movement of the aircraft through the scene with respect to the x, y, and z axis there by
simulating plane.

To change the point of view of the camera when looking at the scene I used the
gluLookAt() function, this in a sense allowed for the positioning of the scene camera at
different points.

One camera was positioned directly above the scene and this was the global camera
which showed the entire scene and was static. Another point of view was also above the
scene, this camera was not static but moved with the plane. I also incorporated a first
person point of view that simulates the view from the cockpit of the plane. The last point
of view I implemented is of various views of the plane as it flies. I also added some
functionality that allows users to control the movement of the plane and the various points
view.

Dept. of CSE , EWIT 2018-2019 Page 15


Plane Simulation

Table 5.1: Test case for menu option

Sl Test case Expected Result Actual Result


no. description R
e
m
a
r
k
s
1. Click the keys to Menu with Menu with
display on the
 Animate ‘a’  Animate ‘a’
screen
 Move Camera ‘c’  Move
 ULF1 Camera ‘c’ P
 UF2  ULF1 a
 URF3  UF2 s
 LF4  URF3 s
 F 5  LF4
 RF6  F 5
 DLF7  RF6
 DF8  DLF7
 DRF9  DF8
 q Exit  DRF9
 q Exit
Should be displayed.
Is displayed.

2. Click on key ‘a’ Plane move forward Should Plane move forward Is P
be displayed. displayed. a
s
s

3. Click on key ‘c’ Plane move backward Plane move backward Is P


Should be displayed. displayed. a
s
s
Plane Rotates in AntiClock Plane Rotates in P
4. Click on key ‘z’ a
Wise direction Should be AntiClock Wise
displayed. direction Is displayed. s
s
P
5. Click on key ‘Z’ Plane Rotates in Clock Wise Plane Rotates in Clock a
direction Should be Wise direction s

Dept. of CSE , EWIT 2018-2019 Page 16


Plane Simulation

displayed. Is displayed. s

6. Click the key 1 Plane moves in upper Plane moves in upper


forward left direction should forward left direction Is
be displayed. displayed.
P
a
Plane moves in upper Plane moves in upper s
Click the key 3 forward right direction forward right direction s
should be displayed. Is displayed

Movement of plane should Movement of plane Is


7. Click the key ‘q’ be terminate. terminated.
P
a
s
s

Dept. of CSE , EWIT 2018-2019 Page 17


Plane Simulation

6.SNAPSHOTS:

Fig 6.1 An air-plane model which is static.

Fig 6.2 Air-plane rotating in anti-clockwise direction by pressing ‘z’

Dept. of CSE , EWIT 2018-2019 Page 18


Plane Simulation

Fig 6.3 Airplane rotating in clockwise direction by pressing ‘Z’.

Fig 6.4 Airplane moving in forward direction ‘a’.

Dept. of CSE , EWIT 2018-2019 Page 19


Plane Simulation

Dept. of CSE , EWIT 2018-2019 Page 20

You might also like