OpenGL Projects: Internal combustion engine – IC engine


In this post we are going to referring to a project that involves computer graphics related to an internal combustion (IC) engine in particular petrol engine.We are going to focus on the design of engine components, simulations of the engine cycle and will going to show visualizations of how the internal combustion (IC) engine works.

An internal combustion engine (IC Engine) is a type of heat engine that generates power by burning (using oxidizer usually air) fuel (typically gasoline(petrol), diesel, or natural gas etc) inside a combustion chamber. IC engines are used in many vehicles, including cars, motorcycles, trucks, and airplanes. Below is Figure of an Typical  IC engine.

The cycle repeats continuously, with pistons moving up and down, creating the power needed to drive a vehicle or perform work. There are two common types of internal combustion engines:

//Simple Program:

#include

#include

#include

void *font = GLUT_BITMAP_TIMES_ROMAN_24; char buff[10]; void *fonts[] = { GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, GLUT_BITMAP_TIMES_ROMAN_24 }; int cc=25,cb=65,s=0,speed=30,status=1; float pointer=25; typedef struct { GLfloat x,y;} Pt; Pt q1, q2,q3,q4; GLfloat colors[][3] = {{0.5,0.5,0.5},{0.5,0.5,0.5},{0.8,0.8,0.8},{0.8,0.8,0.8},{0.8,0.8,0.8},{0.4,0.4,0.4}}; void init() { glClearColor(0.0,0,0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,499.0,0.0,499.0); glutPostRedisplay(); } void DrawLine(Pt n1, Pt n2) { glBegin(GL_LINES); for (int i=0;i=75 && cc=0 && cc25 && cc=25 && ii=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii=25 && ii=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii=0 && cc=25 && cc75 && cc=cb && ii=80 && ii=25 && cc50 && cc=0 && cc=75 && cc=27 && cc=75 && cc=0 && ii=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii=0 && ii=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii=25 && ii25 && cc75 && cc=0 && cc=25 && cc=0.95) rr=0.95; glColor3f(1-(rr*0.1),0+rr,0+rr); } if( cc>75 && cc=0 && ccl;j--) { glVertex2f(i-43,j); glVertex2f(i+44,j); } glEnd(); } } void board(float x,float y){ //glColor3f(0.0,1.0,1.0); glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-450,y-250); glVertex2f(x+450,y-250); glVertex2f(x+450,y+450); glVertex2f(x-450,y+450); glEnd(); //glColor3f(0.85,1,1); glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-400,y-200); glVertex2f(x+400,y-200); glVertex2f(x+400,y+400); glVertex2f(x-400,y+400); glEnd(); } void smallboard(float x,float y){ //glColor3f(0.0,1.0,1.0); glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-200,y-200); glVertex2f(x+200,y-200); glVertex2f(x+200,y+200); glVertex2f(x-200,y+200); glEnd(); //glColor3f(0.85,1,1); glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-160,y-160); glVertex2f(x+160,y-160); glVertex2f(x+160,y+160); glVertex2f(x-160,y+160); glEnd(); } /*void board(float x,float y){ glColor3f(0.3,0.3,0.3); //glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-550,y-250); glVertex2f(x+550,y-250); glVertex2f(x+550,y+450); glVertex2f(x-550,y+450); glEnd(); glColor3f(1.0,1.0,1.0); //glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-500,y-200); glVertex2f(x+500,y-200); glVertex2f(x+500,y+400); glVertex2f(x-500,y+400); glEnd(); }*/ void text(int x, int y, char *string,int j) { int len, i; glRasterPos2f(x, y); len = (int) strlen(string); for (i = 0; i =h && ii=22 && cc=25 ) spark(x+1,y-2); // title glColor3f(0.0,0.0,1.0); text(x-115,y+415,"IC Petrol Engine",2); y+=150; smallboard(x+700,y); glColor3f(0.3,0.3,0.3); Circle(x+700, y, 145, 100,0); glColor3f(0.9,0.95,0.95); indicator(x+700, y, 140, 100,0); //exhaust glColor3f(0.0,0.5,1.0); indicator(x+700, y, 140, 100,25); //suction glColor3f(0.8,0.5,0.5); indicator(x+700, y, 140, 100,50);//compression glColor3f(0.9,1.0,0.5); indicator(x+700, y, 140, 100,75);// working glColor3f(0.3,0.3,0.3); Circle(x+700, y, 15, 100,0); //glColor3f(0.0,0.0,0.0); tip(x+700, y, 100, 100); glColor3f(0.0,0.0,1.0); text(x+600,y+170,"Stroke Indicator",2); //lables glColor3f(0.0,0.5,1.0); point(x+520,y-240); glColor3f(0.5,0.9,1.0); text(x+540,y-245,"Suction Stroke",0); glColor3f(0.8,0.5,0.5); point(x+520,y-260); glColor3f(0.5,0.9,1.0); text(x+540,y-265,"Compression Stroke",0); glColor3f(0.9,1.0,0.5); point(x+520,y-280); glColor3f(0.5,0.9,1.0); text(x+540,y-285,"Working Stroke",0); glColor3f(0.9,0.95,0.95); point(x+520,y-300); glColor3f(0.5,0.9,1.0); text(x+540,y-305,"Exhaust Stroke",0); text(x-510,y-450,"Press 'space' to start/stop Press '+' to speedup engine Press '-' to slowdown engine",0); glFlush(); //quad(); } void start(){ if(status==1) { cb++; cc++; pointer+=0.5; } if(cc==100) { cc=0; } if(pointer==100) { pointer=0; } if(cb==100) cb=0; display(); //Game title if(cc==25){ if(s==0) s=1; else s=0; } Sleep(speed); } void keypress(unsigned char key, int x,int y){ if (key=='+') {speed--; if(speed=500) speed=500;} if(key==' ') {if(status==0) status=1; else status=0; }} void myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); glMatrixMode(GL_PROJECTION); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize (600, 600); glutCreateWindow("Introduction to Open GL"); glutReshapeFunc(myReshape); glutKeyboardFunc(keypress); glutDisplayFunc(display); glutIdleFunc(start); init(); glutMainLoop();

}

We will be happy to hear your thoughts

Leave a reply

Som2ny Network
Logo
Compare items
  • Total (0)
Compare
0