Rocket Launch
CONTENTS
SL.NO particulars PAGE.NO
1 Abstract 2
2 System Specifications 3
3 Introduction to openGL 4
5 Implementation 7
6 Interaction 9
7 Source Code 10
8 Output 27
9 Conclusion 29
10 Bibliography 30
1 Dept. of Computer Science & Engineering.
Rocket Launch
Abstract
Main aim of this Mini Project is to show the simulation of a rocket
launch.
illustrate the concepts and usage of pre-built functions in OpenGL.
When the rocket has completely exhausted is fuel from adjoining
tanks, then the extra weight is lost by disconnecting them.
When the final capsule reached the orbiting location the last part is
also disconnected and the satellite is placed in orbit.
We have used input device keyboard to interact with the program
System specifications
SOFTWARE REQUIREMENTS :
2 Dept. of Computer Science & Engineering.
Rocket Launch
MICROSOFT VISUAL C++
OPENGL
HARDWARE REQUIREMENT :
GRAPHICS SYSTEM,
Pentium P4 with 256 of Ram(Min)
Introduction to openGL
As a software interface for graphics hardware, OpenGL's main purpose is to
render two- and three-dimensional objects into a frame buffer.
These objects are described as sequences of vertices or pixels.
OpenGL performs several processing steps on this data to convert it to pixels to
form the final desired image in the frame buffer.
3 Dept. of Computer Science & Engineering.
Rocket Launch
OpenGL Fundamentals
This section explains some of the concepts inherent in OpenGL.
Primitives and Commands
OpenGL draws primitives—points, line segments, or polygons—subject to several
selectable modes.
You can control modes independently of each other; that is, setting one mode
doesn't affect whether other modes are set .Primitives are specified, modes are
set, and other OpenGL operations are described by issuing commands in the form
of function calls.
Primitives are defined by a group of one or more vertices. A vertex defines a
point, an endpoint of a line, or a corner of a polygon where two edges meet. Data
is associated with a vertex, and each vertex and its associated data are processed
independently, in order, and in the same way. The type of clipping depends on
which primitive the group of vertices represents.
Commands are always processed in the order in which they are received,
although there may be an indeterminate delay before a command takes effect.
This means that each primitive is drawn completely before any subsequent
command takes effect. It also means that state-querying commands return data
that's consistent with complete execution of all previously issued OpenGL
commands.
Basic OpenGL Operation
The figure shown below gives an abstract, high-level block diagram of how
OpenGL processes data. In the diagram, commands enter from the left and
proceed through what can be thought of as a processing pipeline. Some
commands specify geometric objects to be drawn, and others control how the
objects are handled during the various processing stages.
Figure . OpenGL Block Diagram
4 Dept. of Computer Science & Engineering.
Rocket Launch
As shown by the first block in the diagram, rather than having all commands
proceed immediately through the pipeline, you can choose to accumulate some
of them in a display list for processing at a later time.
Rasterization produces a series of frame buffer addresses and associated values
using a two-dimensional description of a point, line segment, or polygon.
Each fragment so produced is fed into the last stage,
per-fragment operations, which performs the final operations on the data before
it's stored as pixels in the frame buffer. These operations include conditional
updates to the frame buffer based on incoming and previously stored z-value s
(for z-buffering) and blending of incoming pixel colors with stored colors, as well
as masking and other logical operations on pixel values.
All elements of OpenGL state, including the contents of the texture memory and
even of the frame buffer, can be obtained by an OpenGL application.
5 Dept. of Computer Science & Engineering.
Rocket Launch
Implementation
This program is implemented using various openGL functions which are
shown below.
Various functions used in this program.
glutInit() : interaction between the windowing system and OPENGL is
initiated
glutInitDisplayMode() : used when double buffering is required and depth
information is required
6 Dept. of Computer Science & Engineering.
Rocket Launch
glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window
glutInitWindowSize() : specifies the size of the window
glutInitWindowPosition() : specifies the position of the window in screen
co-ordinates
glutKeyboardFunc() : handles normal ascii symbols
glutSpecialFunc() : handles special keyboard keys
glutReshapeFunc() : sets up the callback function for reshaping the window
glutIdleFunc() : this handles the processing of the background
glutDisplayFunc() : this handles redrawing of the window
glutMainLoop() : this starts the main loop, it never returns
glViewport() : used to set up the viewport
glVertex3fv() : used to set up the points or vertices in three dimensions
glColor3fv() : used to render color to faces
7 Dept. of Computer Science & Engineering.
Rocket Launch
glFlush() : used to flush the pipeline
glutPostRedisplay() : used to trigger an automatic redrawal of the object
glMatrixMode() : used to set up the required mode of the matrix
glLoadIdentity() : used to load or initialize to the identity matrix
glTranslatef() : used to translate or move the rotation centre from one
point to another in three dimensions
glRotatef() : used to rotate an object through a specified rotation angle
Interaction with program
This program includes interaction through keyboard.
S Start the Project
Use keys A,D,W,S to control the moment of PacMan.
Q-> Quit
8 Dept. of Computer Science & Engineering.
Rocket Launch
Source Code
#include <windows.h>
#include<string.h>
#include<stdarg.h>
#include<stdio.h>
#include <glut.h>
9 Dept. of Computer Science & Engineering.
Rocket Launch
static double x=0.0,x1=0.0,y1=0.1,z1=0.0,a1=0,y2=0,z2=0;
static double move=-60;
static bool seperate=false;
void
stroke_output(GLfloat x, GLfloat y, char *format,...)
va_list args;
char buffer[200], *p;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glPushMatrix();
glTranslatef(-2.5, y, 0);
glScaled(0.003, 0.005, 0.005);
for (p = buffer; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
10 Dept. of Computer Science & Engineering.
Rocket Launch
void satellite(){
glPushMatrix();
//Core
glPushMatrix();
glColor3f(1,1,0);
glTranslatef(0,2,0);
glScaled(0.3,1,0.3);
glRotatef(90,1,0,0);
if(x<=6)
glutSolidTorus(0.5,1,30,30);
else
glutSolidCube(1);
glPopMatrix();
// Solar Panel
11 Dept. of Computer Science & Engineering.
Rocket Launch
glPushMatrix();
glColor3f(0.2,0.2,0.2);
glTranslatef(1,2,0);
if(x>=6){
glScaled(4,1.5,0.1);
else
glScaled(0,0,0);
glRotatef(-20,1,0,0);
glutSolidCube(0.5);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.2,0.2);
glTranslatef(-1,2,0);
if(x>=6){
glScaled(4,1.5,0.1);
12 Dept. of Computer Science & Engineering.
Rocket Launch
else
glScaled(0,0,0);
glRotatef(-20,1,0,0);
glutSolidCube(0.5);
glPopMatrix();
glPopMatrix();
void rocket(){
// Main top cone
glPushMatrix();
if(x>=5.5){
glTranslatef(z2,-z2,z2);
glRotatef(a1,0,1,1);
13 Dept. of Computer Science & Engineering.
Rocket Launch
glPushMatrix();
glTranslatef(0,2.5,0);
glColor3f(0,0,1);
glScaled(2.2 ,1.5,2.2);
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
glPopMatrix();
// Satelitte container
glPushMatrix();
if(x>=6.8){
glTranslatef(2,0,0);
glRotatef(x*40,0,1,0);
satellite();
14 Dept. of Computer Science & Engineering.
Rocket Launch
glPopMatrix();
glPushMatrix();
if(x>=5){
glTranslatef(0,y2,y2);
glRotatef(a1,0,1,1);
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(0,0.0,0);
glScaled(0.3,4.3,0.3);
glRotatef(90,1,0,0);
glutSolidTorus(0.5,1,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(0,-2.2,0);
glColor3f(0,0,1);
glScaled(3,1.5,3);
15 Dept. of Computer Science & Engineering.
Rocket Launch
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
glPopMatrix();
// RightSide rocket
glPushMatrix();
glTranslatef(x1,-y1,z1);
glRotatef(a1,0,1,1);
glPushMatrix();
glTranslatef(0.7,1,0);
glColor3f(0,0,1);
glScaled(1.5 ,1,1.5);
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
16 Dept. of Computer Science & Engineering.
Rocket Launch
glPushMatrix();
glTranslatef(0.7,-0.2,0);
glColor3f(0,1,1);
glScaled(0.2,6.5,0.2);
glRotatef(90,1,0,0);
glutSolidTorus(0.2,1,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(0.7,-2.0,0);
glColor3f(0,0,1);
glScaled(1.5,1,1.5);
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
glPopMatrix();
17 Dept. of Computer Science & Engineering.
Rocket Launch
// LeftSide rocket
glPushMatrix();
glTranslatef(-x1,-y1,-z1);
glRotatef(-a1,0,1,1);
glPushMatrix();
glTranslatef(-0.7,1,0);
glColor3f(0,0,1);
glScaled(1.5 ,1,1.5);
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.7,-0.2,0);
glColor3f(0,1,1);
glScaled(0.2,6.5,0.2);
glRotatef(90,1,0,0);
glutSolidTorus(0.2,1,30,30);
18 Dept. of Computer Science & Engineering.
Rocket Launch
glPopMatrix();
glPushMatrix();
glTranslatef(-0.7,-2.0,0);
glColor3f(0,0,1);
glScaled(1.5,1,1.5);
glRotatef(270,1,0,0);
glutSolidCone(0.2,1,30,30);
glPopMatrix();
//booster
/*
glPushMatrix();
glTranslatef(2,0,0);
glColor3f(1,1,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
19 Dept. of Computer Science & Engineering.
Rocket Launch
glVertex3f(0.8,-1,0);
glVertex3f(0,0,0);
glEnd();
glPopMatrix();
*/
glPopMatrix();
void stars(){
for(float s1=5;s1<=100; s1+=0.4){
for(float s2=-6;s2<=6;s2+=0.5){
20 Dept. of Computer Science & Engineering.
Rocket Launch
glPushMatrix();
glBegin(GL_POINTS);
glVertex3f(s2,s1,0);
glEnd();
glPopMatrix();
for(float s3=5.2;s3<=100; s3+=0.3){
for(float s4=-6.2;s4<=6;s4+=0.3){
glPushMatrix();
glBegin(GL_POINTS);
glVertex3f(s4,s3,0);
glEnd();
glPopMatrix();
21 Dept. of Computer Science & Engineering.
Rocket Launch
// Draw rocket
void rocket(double ang)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
//glRotatef(ang,0.0f,1.0f,0.0f);
22 Dept. of Computer Science & Engineering.
Rocket Launch
glPushMatrix();
if(ang<=2){
glRotatef(ang*30,1,0,0);
glTranslatef(0,-2+ang,0);
else{
glRotatef(60,1,0,0);
glTranslatef(0,0,0);
glScaled(0.5,0.5,0.5);
rocket();
glPopMatrix();
//Earth
glPushMatrix();
23 Dept. of Computer Science & Engineering.
Rocket Launch
glColor3f(0,0,1);
if(x>=6.5){
glTranslatef(0,-18,-95);
glRotatef(10*x,0,1,0);
}else{
glTranslatef(0,-10-x,-10-15*x);
glutSolidSphere(10,100,100);
glPopMatrix();
// Create Stars
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(0,-ang,0);
stars();
glPopMatrix();
24 Dept. of Computer Science & Engineering.
Rocket Launch
glFlush();
glutSwapBuffers();
void p()
x+=0.01;
if(x>=3){
x1+=0.1;
y1+=0.1;
z1+=0.01;
a1+=3;
if(x>5){
25 Dept. of Computer Science & Engineering.
Rocket Launch
y2-=0.1;
if(x>5.5){
z2+=0.1;
rocket(x);
void doInit()
/* Background and foreground color */
glClearColor(0.0,0.0,0.0,0);
glViewport(0,0,640,480);
26 Dept. of Computer Science & Engineering.
Rocket Launch
/* Select the projection matrix and reset it then
setup our view perspective */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);
/* Select the modelview matrix, which we alter with rotatef() */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
void display()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
27 Dept. of Computer Science & Engineering.
Rocket Launch
stroke_output(-2.0, 1.7, "p/P-->Launch the` Rocket");
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position3[]={0.0f,5.0f,0.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
28 Dept. of Computer Science & Engineering.
Rocket Launch
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
void menu(int id)
switch(id)
case 2:glutIdleFunc(p);
break;
case 5:exit(0);
break;
glFlush();
glutSwapBuffers();
29 Dept. of Computer Science & Engineering.
Rocket Launch
glutPostRedisplay();
void mykey(unsigned char key,int x,int y)
if(key=='p')
glutIdleFunc(p);
if(key=='q'||key=='Q')
exit(0);
int main(int argc, char *argv[])
30 Dept. of Computer Science & Engineering.
Rocket Launch
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(1000,480);
glutInitWindowPosition(0,0);
glutCreateWindow("rocket");
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("Launch 'p'",1);
glutAddMenuEntry("Quit 'q'",5);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
31 Dept. of Computer Science & Engineering.
Rocket Launch
return 0;
32 Dept. of Computer Science & Engineering.
Rocket Launch
OUTPUT OF THE PROGRAM
33 Dept. of Computer Science & Engineering.
Rocket Launch
34 Dept. of Computer Science & Engineering.
Rocket Launch
Conclusions
The project “Rocket Launch” clearly demonstrates the Simulation of a Rocket
launch and putting the satellite in orbit.
Finally we conclude that this program clearly illustrate the Rocket launch by using
OpenGL and pre-built objects and has been completed successfully and is ready to
be demonstrated.
Bibliography
35 Dept. of Computer Science & Engineering.
Rocket Launch
WE HAVE OBTAINED INFORMATION FROM MANY RESOURCES TO DESIGN AND
IMPLEMENT OUR PROJECT SUCCESSIVELY. WE HAVE ACQUIRED MOST OF THE
KNOWLEDGE FROM RELATED WEBSITES. THE FOLLOWING ARE SOME OF THE
RESOURCES :
TEXT BOOKS :
INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH
-By Edward Angel.
COMPUTER GRAPHICS,PRINCIPLES & PRACTICES
- Foley van dam
- Feiner hughes
WEB REFERENCES:
http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson3.php
http://google.com
http://opengl.org
36 Dept. of Computer Science & Engineering.