Skip to main content

Sinking Ship (Titanic) Computer graphics project using OpenGL

 #include<stdio.h>

#include<GL/glut.h>
#include<stdlib.h>
#include<GL/freeglut.h>
#include<time.h>
#include<bits/stdc++.h>
#define WIDTH 768
#define HEIGHT 1024
using namespace std;

typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} vec3f;

const vec3f _FONT_SIZE_NORMAL = {0.5f, 0.5f, 1.0f};
const vec3f _FONT_SIZE_BIG = {1.0f, 1.0f, 1.0f};
const vec3f _FONT_SIZE_SMALL = {0.25f, 0.25f, 1.0f};

const vec3f *FONT_SIZE_NORMAL = &_FONT_SIZE_NORMAL;
const vec3f *FONT_SIZE_BIG = &_FONT_SIZE_BIG;
const vec3f *FONT_SIZE_SMALL = &_FONT_SIZE_SMALL;

struct timespec tim, tim2;
void sun();
void ice();
void sky();
void display();
void display0();
void display1();
void display2();
void display3();
void display4();
void ship(int, double);
void rescueShip(int, double);
void drawStickMan();
void water();

vector<pair<int, int> > starpoints;
bool KEY_PRESSED = false;
GLint a=0,b=0,c=120,d=0, z = 1200,e=0,f=0,g=500,h=600,x=0,i=0;
float p = 0, q=0, r=0;

GLfloat theta=0.0;

void initVariables()
{
a=0,b=0,c=120,d=0, p = 0,q = 0, r=0,z = 1200,e=0,f=0,g=500,h=600,x=0,i=0;
}
void normalKeys(unsigned char key, int x, int y) {
switch (key) {
case 27: // ESC key
exit(EXIT_SUCCESS);
case 13: // Enter key
{
initVariables();
KEY_PRESSED = true;
}
break;

default:
break;
}
}

void drawStrokeText(std::string text, int x, int y, int z, const vec3f *fontSize) {

glPushMatrix();

glTranslatef(x, y, z);
glScalef(fontSize->x, fontSize->y, fontSize->z);
glutStrokeString(GLUT_STROKE_ROMAN, (unsigned char const *) text.c_str());

glPopMatrix();
}

void update(int value)
{
a+=20.0;
e-=10;
p-=0.01;
q-=0.01;
glutPostRedisplay();
glutTimerFunc(200,update,0); //speed of ship 200
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

display0();
if(KEY_PRESSED == true)
display1(); //DRAW SHIP IN INITIAL POSITION AND WATER


if(a>950 && KEY_PRESSED == true) //SHIFT TO NEW SCREEN
{
b+=20;
display2();
}
if(b==180 && KEY_PRESSED == true)
{
tim.tv_sec = 1.5; //crash pause time
tim.tv_nsec = 500000000L;
// nanosleep(&tim , &tim2);
}
if(b>180 && KEY_PRESSED == true)
{
c+=10;
display3();

}
if(c>700 && KEY_PRESSED == true)
{
z-=20;
display4();
}
if(z <-100 && KEY_PRESSED == true)
exit(EXIT_SUCCESS);

glFlush();
glutSwapBuffers();
}
void display0() {

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0f,1.0f,1.0f,1.0f);

glLineWidth(3);
glColor3f(0.0,0.0,1.0);
drawStrokeText("SINKING SHIP", WIDTH/3, HEIGHT/2, 0, FONT_SIZE_NORMAL);

glLineWidth(1);
drawStrokeText("PRESS ENTER TO START", WIDTH/2.5, HEIGHT/2.5, 0, FONT_SIZE_SMALL);
drawStrokeText("Press Esc to Quit", WIDTH/2.5, HEIGHT/3.4, 0, FONT_SIZE_SMALL);


}
void display4()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f,0.18f,0.2f,1.0f);
sky();

glPushMatrix();
glTranslated(z,75,0.0);
rescueShip(1, 1); //1 = night
glPopMatrix();
water();
}
void display1()
{


glClearColor(1.0f + q,0.6f + p,0.0f,1.0f);
//startScreen();
glPushMatrix();
glTranslated(0,e,0.0);
sun();
glPopMatrix();
glPushMatrix();
glTranslated(a,75,0.0);
ship(0, 2); //0 = day
glPopMatrix();
water();
}

void display2()
{

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f,0.18f,0.2f,1.0f);
sky();

ice();
glPushMatrix();
glTranslated(b,75,0.0);
ship(1, 2); //1 = night
glPopMatrix();
water();

}

void display3()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f,0.18f,0.2f,1.0f);
x-=1; //slope of sinking ship

//stars();
sky();
ice();
glPushMatrix();
glTranslated(c,100+x*5,0.0); //sinking ship axis
glRotated(-15,0,0,1);
ship(1,2);
glPopMatrix();
water();


}

/* DRAW WATER */
void water()
{

glColor3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(1000,0);
glVertex2f(1000,100);
glVertex2f(0,100);
glEnd();
}

void drawRailing(vector<double> xx, vector<double> yy, double inc, double col)
{
glColor3f(col, col, col);
glBegin(GL_LINE_LOOP);
for(int i=0;i<6;i++)
{
glVertex2f(xx[i] + inc, yy[i]);
}

glEnd();
}

void drawStickMan()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glColor3f( 0.0f, 0.0f, 0.0f);
int cx1 = 6, cy1 = 11, r1 = 1, num_segments=1000;
for (int ii = 0; ii < num_segments; ii++)
{
float alpha = 2.0f * 3.1415926f * float(ii) / float(num_segments); ///get the current angle
float x = r1 * cosf(alpha); ///calculate the x component
float y = r1 * sinf(alpha); ///calculate the y component
glVertex2f(x + cx1, y + cy1); ///output vertex
}
glEnd();
/// Player's Face Boundary
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glColor3f( 0.96f, 0.80f, 0.69f);
cx1 = 6, cy1 = 11, r1 = 1, num_segments=1000;
for (int ii = 0; ii < num_segments; ii++)
{
float alpha = 2.0f * 3.1415926f * float(ii) / float(num_segments); ///get the current angle
float x = (r1-0.1) * cosf(alpha); ///calculate the x component
float y = (r1-0.1) * sinf(alpha); ///calculate the y component
glVertex2f(x + cx1, y + cy1); ///output vertex
}
glEnd();

glColor3f(0.0,0.0,0.0);
/// Player's Hand
glBegin(GL_LINES);
glVertex2f(5,8);
glVertex2f(6,10);
glEnd();

glBegin(GL_LINES);
glVertex2f(6,10);
glVertex2f(7,8);
glEnd();
//playerbody
glBegin(GL_LINES);
glVertex2f(6,10);
glVertex2f(6,6.5);
glEnd();

//playerrightleg
glBegin(GL_LINES);
glVertex2f(5,5.5);
glVertex2f(6,6.5);
glEnd();

glBegin(GL_LINES);
glVertex2f(6,6.5);
glVertex2f(7,5.5);
glEnd();

}
void drawWindows(vector<double> xx, vector<double> yy, double inc, int flag)
{
if(flag == 0)
{
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0);
}
else
{
glColor3f(1,1,0);
glBegin(GL_POLYGON);
}
for(int i=0;i<4;i++)
{
glVertex2f(xx[i] + inc, yy[i]);
}

glEnd();
}

void drawDeck(double x, double y)
{
glColor3f(0.69,0,0);
glBegin(GL_POLYGON);
glVertex2f(x,y);
glVertex2f(x,y+1.5);
glVertex2f(x+14,y+1.5);
glVertex2f(x+14,y);
glEnd();
}
void drawChimney(double x, double y)
{
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(x,y);
glVertex2f(x,y+3);
glVertex2f(x+1.5,y+3);
glVertex2f(x + 1.5, y);
glEnd();
glColor3f(0.545, 0.271, 0.075); //brown
glBegin(GL_POLYGON);
glVertex2f(x,y+3);
glVertex2f(x,y+3.5);
glVertex2f(x+1.5,y+3.5);
glVertex2f(x+1.5,y+3);
glEnd();
}
//rescue ship
void rescueShip(int flag, double scale)
{


glScaled(10*scale,10*scale, 0);
//ship base
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(1,5.5);
glVertex2f(4,1);
glVertex2f(19,1);
glVertex2f(21.5,5.5);
glEnd();
//door
glColor3f(0.545, 0.271, 0.075);
glBegin(GL_POLYGON);
glVertex2f(4,5.5);
glVertex2f(4,8);
glVertex2f(5,8);
glVertex2f(5,5.5);
glEnd();
//light
glColor4f(1, 1, 0.0, 0.5);
glBegin(GL_POLYGON);
glVertex2f(4,7.5);
glVertex2f(4,8);
glVertex2f(-7,1);
glVertex2f(-3,1);
glEnd();

drawStickMan();
//railing down
vector<double> xx,yy;
xx.push_back(1.5);
xx.push_back(1.5);
xx.push_back(2);
xx.push_back(3);
xx.push_back(3.5);
xx.push_back(3.5);

yy.push_back(5.5);
yy.push_back(6.5);
yy.push_back(6.2);
yy.push_back(6.2);
yy.push_back(6.5);
yy.push_back(5.5);
for(int i=0;i<10; i++)
{
drawRailing(xx, yy, i*2, 0);
}
}
/* TO DRAW SHIP */
void ship(int flag, double scale)
{


glScaled(10*scale,10*scale, 0);
//ship mid
glColor3f(0.5,0.5,0.5);
glBegin(GL_POLYGON);
glVertex2f(3.5,5.5);
glVertex2f(3.5,8.5);
glVertex2f(19.5,8.5);
glVertex2f(19.5,5.5);
glEnd();
//ship base
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(1,5.5);
glVertex2f(4,1);
glVertex2f(19,1);
glVertex2f(21.5,5.5);
glEnd();
//door
glColor3f(0.545, 0.271, 0.075);
glBegin(GL_POLYGON);
glVertex2f(4,5.5);
glVertex2f(4,8);
glVertex2f(5,8);
glVertex2f(5,5.5);
glEnd();
//upper windows
if(flag == 0)
glColor3f(0.9,0.9,0.9);
else
glColor3f(1, 1, 0);

glBegin(GL_POLYGON);
glVertex2f(7,7.5);
glVertex2f(7,8);
glVertex2f(10,8);
glVertex2f(10,7.5);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(11.5,7.5);
glVertex2f(11.5,8);
glVertex2f(15,8);
glVertex2f(15,7.5);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(16,7.5);
glVertex2f(16,8);
glVertex2f(19,8);
glVertex2f(19,7.5);
glEnd();
//upper deck

drawDeck(4.5, 8.5);

double x = 5.5,y=10;

for(int i=0; i<4; i++)
{
drawChimney(x + i*3, y);
}

//railing down
vector<double> xx,yy;
xx.push_back(1.5);
xx.push_back(1.5);
xx.push_back(2);
xx.push_back(3);
xx.push_back(3.5);
xx.push_back(3.5);

yy.push_back(5.5);
yy.push_back(6.5);
yy.push_back(6.2);
yy.push_back(6.2);
yy.push_back(6.5);
yy.push_back(5.5);
for(int i=0;i<10; i++)
{
drawRailing(xx, yy, i*2, 0);
}
//window coordinates
xx.clear();
yy.clear();
xx.push_back(4.5);
xx.push_back(4.5);
xx.push_back(5.5);
xx.push_back(5.5);

yy.push_back(3.5);
yy.push_back(4.5);
yy.push_back(4.5);
yy.push_back(3.5);

for(int i=0;i<6; i++)
{

drawWindows(xx, yy, i*2.5, flag);
}
//upper railing
xx.clear();
yy.clear();
xx.push_back(5);
xx.push_back(5);
xx.push_back(5.5);
xx.push_back(6.5);
xx.push_back(7);
xx.push_back(7);

yy.push_back(10);
yy.push_back(11);
yy.push_back(10.8);
yy.push_back(10.8);
yy.push_back(11);
yy.push_back(10);
for(int i=0;i<6; i++)
{
drawRailing(xx, yy, i*2, 0.1);
}

}
void sun()
{
glPushMatrix();
glTranslated(700, 500,0.0);
float cx = 100, cy = 100, r = 50;

int num_segments = 100;

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 0);

glBegin(GL_TRIANGLE_FAN);

for(int ii = 0; ii < num_segments; ii++)

{

float theta = 2.0f * 3.1415926f * float(ii) /

float(num_segments);//get the current angle

float x = r * cosf(theta);//calculate the x

float y = r * sinf(theta);//calculate the y
glVertex2f(x + cx, y + cy);//output vertex

}
glEnd();

glPopMatrix();

}
void sky()
{
glClear(GL_COLOR_BUFFER_BIT);
//moon
glPushMatrix();
glTranslated(700, 500,0.0);
float cx = 100, cy = 100, r = 50;

int num_segments = 100;

//glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 1.0);

glBegin(GL_TRIANGLE_FAN);

for(int ii = 0; ii < num_segments; ii++)

{

float theta = 2.0f * 3.1415926f * float(ii) /

float(num_segments);//get the current angle

float x = r * cosf(theta);//calculate the x

float y = r * sinf(theta);//calculate the y
glVertex2f(x + cx, y + cy);//output vertex

}
glEnd();

glPopMatrix();



//stars
for(int i=0;i<10;i++) {

float tx = (rand()%950) + 10, ty = 450 + rand()%400, R = 2;

glColor3f(1.0, 1.0, 1.0);

glBegin(GL_TRIANGLE_FAN);

for(int ii = 0; ii < num_segments; ii++)

{

float theta2 = 2.0f * 3.1415926f * float(ii) /

float(num_segments);//get the current angle

float x = R * cosf(theta2);//calculate the x

float y = R * sinf(theta2);//calculate the y
glVertex2f(x + tx, y + ty);//output vertex


}
glEnd();
//glPopMatrix();

}


}

/* TO DRAW ICEBERG */
void ice()
{
glPushMatrix();
glTranslated(450,50,0.0);
glScaled(10,10,0);
glColor3f(0.0,1.0,1.0);
if(c>120)
{
//ice after crash
glPushMatrix();
glTranslated(0,x,0); //sinking iceberg

glPushMatrix();
glTranslated(7,2,0.0); //translate + rotate - translate about base of iceberg
glRotated(-x,0,0,1);
glTranslated(-7,-2,0.0);
glBegin(GL_POLYGON);
glVertex2f(7,2);
glVertex2f(8,3);
glVertex2f(11,18);
glVertex2f(12,19);
glVertex2f(12,3);
glEnd();
glPopMatrix();

glPushMatrix();
glTranslated(12,3,0.0);
glRotated(x,0,0,1);
glTranslated(-12,-3,0.0);
glBegin(GL_POLYGON);
glVertex2f(12,3);
glVertex2f(12,19);
glVertex2f(17,18);
glVertex2f(18,3);
glVertex2f(19,3);
glEnd();
glPopMatrix();

glPopMatrix();
}
else
{
//iceberg before crash
glBegin(GL_POLYGON);
glVertex2f(7,2);
glVertex2f(8,3);
glVertex2f(11,18);
glVertex2f(12,19);
glVertex2f(12,3);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(12,3);
glVertex2f(12,19);
glVertex2f(17,18);
glVertex2f(18,3);
glVertex2f(19,3);
glEnd();
}


glPopMatrix();

}



void myinit()
{
glClearColor(1,1,1,1);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
glutKeyboardFunc(normalKeys);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,999.0,0.0,799.0);
}

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

{
int key=0;

printf("Sinking Ship Project Using OpenGL");
printf("Press 1 to Start\nPress 0 to Quit\n");
scanf("%d",&key);
if(key==0) return 0;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1024.0,768.0);

glutInitWindowPosition(0,0);
glutCreateWindow("Sinking Ship");
glutDisplayFunc(display);
myinit();
glutTimerFunc(100,update,0);
glutMainLoop();
return 0;
}

Comments

Popular posts from this blog

Maxon Cinema 4D Studio R13.058 full Keygen Cracked Version | Mediafire Torrent Download Link

Download Maxon CINEMA 4D Studio Full Version With Keygen -Everything You Need for High-End 3D 32 and 64 bit MAXON CINEMA 4D STUDIO R13.058 (x86/x64) CINEMA 4D Studio is the very best that MAXON has to offer for professional 3D artists. If you want to create advanced 3D graphics but need a helping hand to ensure you create jaw-dropping graphics quickly and easily, then this is the choice for you.                     All You Ever Wanted This is our top-of-the-line product. It not only contains everything the other CINEMA 4D versions offer - it goes far beyond. CINEMA 4D Studio has all the tools you need to tackle even the most complex project. Minimum System Requirements Windows XP, Vista or 7 running on Intel or AMD CPU with SSE2-Support; Mac OS X 10.5.8 or higher running on an Intel-based Mac; 1024 MB free RAM, DVD ROM drive. Standard DVD installation can take up to 4 GB of disk space. Software m...

Minitool Power Data Recovery 6.6 Activation Key

- Technician License: MSMCS3KFS58YUPUYVA3388SVC4PPC4P8 SS45A5MMPAXAU3CXKAA8U88A5CY3SVPU ASAAXUKCVM8UYXMSKVXSU55A5434UKP5 5S8P4UMC8544M8A5K88KAPC8W4CKK8PM 4SSXYAMWUM8SSASKYXSMSY35WCKX5PPK ASK4M3M4MAF3C3MXFWUWSV3MV4PKMCPY SSFF3PM835YK8UUVMPFW4SCSMC3YXAPY 5SXVFYMY8MF333SYKMY8KCPUP4AWYFPU CSVKKSKV45MM58M8MUKWA4KUKCA5AWP5 YS8C88KPFMKFK5P84WUAMSU3CC4U8AP4 CSY54KMVFMY8CU4AS5PPPUYP8CP3F8PM 5S3CMXM38AUKYPYUSWVVW3FPX4VUVCPM CS58YMKC3AVVU4KK8843WSYKKCY8M8P5 MSVKKSMUXMWVF5KU4AMM4AV8Y4A55WPU - Enterprise License: 33M5V84A3V44AMVUWVUFXKWXCCU3SUUC X3PFS54PM5SFCKP5W5YY4VXCS44YPWU3 K3KSKP434MWKASWYUK3PPXVP8CWS3PUX P3A3PM4U8VM4F4SKCCPP845FA48X5CUV U3Y5AK4335SXAYWPC3CA4MK834U8XYUX K3M8SXPS4MUXCAY5X4K4A5A5FCW3UFUS K35KC843YAW4UXFFFWMAX8V8FCYVCWUX K3FAW84CWV3UCY35K5YY4UY33CKSUXUX 83PCFMPXY5PVFKKY8KKFMAV45C4UP4UW 8388PU48AAWVAKCVA5FP4853ACSFVCU3 U3YVYU4SXM834AUXWVWAWV3434WPKSUC F3YSS5PMVAWWWSCYFKCFX85SPCP4WWUA 33MY5S4UXVUS45YCMY5UPKVY4CXV5MUV F3XFK445A55A48CWX4SWM3VSWCVYFPU...

The Man Killing Game: Blue Whale Game

Hi Folks,  Today am gonna share with you some information about the game that went too horrifying. Last day I saw a news, titled a 14-year-old Mumbai, Indian boy died by playing a game.  So, I was wondering how could it is even possible for a game to kill a man, Then I searched over Google to find some mysteries about the game.  The name of the game was "Blue Whale" since its name can mean a game about blue whales!! Guys, you are wrong!. Blue whale game is a Virtual game. It cannot be downloaded like other games you download from playstore or apple store. You cannot find the link to download this game by just searching over the internet. The link of this game is shared so secretly using private chat rooms and forums. This game was developed by a 21-year-old Russian guy named "Phillip Budikin" , he says that he developed this game in order to remove all the wastes from the world. It simply means: He wants everyone to die. So, this game is a death...