Spotline By Airoplane To Car in Opengl Project Using C

Spotline By Airoplane To Car in Opengl Project Using C

#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<stdio.h>
#include<unistd.h>
#include<math.h>

int i=0,k=0,f=0,j=0;
void redisplay()
{
usleep(100);
glutPostRedisplay();
}
void display()
{
int z;
glClear(GL_COLOR_BUFFER_BIT);
// Draw chopper
glBegin(GL_LINES); //left line
glColor3f(0,1,1);
glVertex2f(i,400);
glVertex2f(i+30,400);
glEnd();
glBegin(GL_LINES); //left side line
glColor3f(0,1,1);
glVertex2f(i,430);
glVertex2f(i,370);
glEnd();

glBegin(GL_LINES);  //left upper line
  glColor3f(0,1,1);
glVertex2f(i+50,430);
glVertex2f(i+30,400);
glEnd();
glBegin(GL_LINES); //upper line
 glColor3f(0,1,1);
glVertex2f(i+50,430);
glVertex2f(i+80,430);
glEnd();
glBegin(GL_LINES);  //upper right
glColor3f(0,1,1);
glVertex2f(i+80,430);
glVertex2f(i+100,400);
glEnd();
glBegin(GL_LINES);  //down right
glColor3f(0,1,1);
glVertex2f(i+80,370);
glVertex2f(i+100,400);
glEnd();
glBegin(GL_LINES);  //down
glColor3f(0,1,1);
glVertex2f(i+80,370);
glVertex2f(i+50,370);
glEnd();
glBegin(GL_LINES);  //down left
glColor3f(0,1,1);
glVertex2f(i+30,400);
glVertex2f(i+50,370);
glEnd();
glBegin(GL_LINES);  //upper vertical line
glColor3f(0,1,1);
glVertex2f(i+65,430);
glVertex2f(i+65,460);
glEnd();
glBegin(GL_LINES);  //upper vertical line
glColor3f(0,1,1);
glVertex2f(i+40,460);
glVertex2f(i+90,460);
glEnd();


//Draw zeep
glBegin(GL_LINES);
glColor3f(1,1,0);  //left
glVertex2f(j,40);
glVertex2f(j,100);
glEnd();
glBegin(GL_LINES);  //right
glColor3f(1,1,0);
glVertex2f(j+100,70);
glVertex2f(j+100,40);
glEnd();
glBegin(GL_LINES); //upper right
glColor3f(1,1,0);
glVertex2f(j+80,70);
glVertex2f(j+100,70);
glEnd();
glBegin(GL_LINES);  //upper right corner
glColor3f(1,1,0);
glVertex2f(j+80,70);
glVertex2f(j+50,100);
glEnd();
glBegin(GL_LINES);  //down
glColor3f(1,1,0);
glVertex2f(j,40);
glVertex2f(j+100,40);
glEnd();
glBegin(GL_LINES);  //down
glColor3f(1,1,0);
glVertex2f(j,100);
glVertex2f(j+50,100);
glEnd();

//Draw Troli
glBegin(GL_LINES);  //up
glColor3f(1,1,0);
glVertex2f(j-60,70);
glVertex2f(j,70);
glEnd();
glBegin(GL_LINES);  //down
glColor3f(1,1,0);
glVertex2f(j-60,40);
glVertex2f(j,40);
glEnd();
glBegin(GL_LINES);  //left
glColor3f(1,1,0);
glVertex2f(j-60,40);
glVertex2f(j-60,70);
glEnd();



//draw ground
glBegin(GL_LINES);
glColor3f(0,1,0);
glVertex2f(0,20);
glVertex2f(500,20);
glEnd();

//draw tires of zeep
glBegin(GL_LINE_LOOP); //draw left tire
for (z=0;z<360;z++)
 {
glColor3f(1,1,0);
  glVertex2d((cos(z*3.14/180)*10)+20+j, (sin(z*3.14/180)*10)+30);
 }
glEnd();

glBegin(GL_LINE_LOOP); //draw right tire
for (z=0;z<360;z++)
 {
glColor3f(1,1,0);
  glVertex2d((cos(z*3.14/180)*10)+85+j, (sin(z*3.14/180)*10)+30);
 }
glEnd();



//Draw Spotlight
glBegin(GL_LINES);  //spotlight line left
glColor3f(1,0,0);
glVertex2f(i+65,370);
glVertex2f(j-60,70);
glEnd();
glBegin(GL_LINES);  //spotlight line right
glColor3f(1,0,0);
glVertex2f(i+65,370);
glVertex2f(j+100,70);
glEnd();
glBegin(GL_LINE_LOOP); //draw spot light
for (z=0;z<360;z++)
 {
glColor3f(1,1,1);
  glVertex2d((cos(z*3.14/180)*95)+20+j, (sin(z*3.14/180)*95)+75);
  }
glEnd();


//Use flag for repeatation and i and j for motion
if(f==0)
{
if(i<390)
{
i++;
f=0;
}
else if(i==390)
{
i--;
f=1;
}
}
else if(f==1)
{
if(i>0)
{
i--;
}
else if(i==0)
{
i++;
f=0;
}
}
if(k==0)
{
if(j<400)
{
j=j+2;
}
else if(j>=400)
{
j=j-2;
k=1;
}
}
else if(k==1)
{
if(j>0)
{
j=j-2;
}
else if(j==0)
{
j=j+2;
k=0;
}
}
glutSwapBuffers();
redisplay();
}





void main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(0,0);
    glutInitWindowSize(500,500);
    glutCreateWindow("spot light");
//glClearColor(0.0, 0.0, 1.0, 1.0);
    glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,500,0,500);
    glutDisplayFunc(display);
    glutMainLoop();
}

Related Posts