0% found this document useful (0 votes)
32 views5 pages

Fishing by Man

open gl mini project

Uploaded by

sandy_767
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

Fishing by Man

open gl mini project

Uploaded by

sandy_767
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<GL/glut.

h>
#include<stdio.h>
#include<math.h>
#define M_PI 3.14
GLfloat x=0.0,d=0.0,y=1.0,dg=0.0,dr=0.0,db=0.0, dy=1, an=0;
GLfloat a[6]={-5, -12, 3, 9, 15, 19}, b[6]={9, 12, 16, 10, 0, 13.8};
void semi()
{
int i;
GLfloat k=0, j=3.14/180;
glRotatef(40, 0, 0, 1);
k=2*j;
glBegin(GL_POLYGON);
for(i=2; i<110; i++)
{
glVertex2f(5*cos(k), 5*sin(k));
k+=j;
}
glEnd();
glRotatef(-40, 0, 0, 1);
glRotatef(180, 1, 0, 0);
glTranslatef(-13.1, -13.9, 0);
glBegin(GL_POLYGON);
glVertex2f(10, 10);
glVertex2f(8.5, 8.5);
glVertex2f(9, 11);
glEnd();
}
void fish()
{
int i;
semi();
glRotatef(25, 1, 0, 0);
glTranslatef(13.1, 8.5, 0);
semi();
glTranslatef(15.6, 11.3, 0);
glColor3f(0, 0, 0);
glBegin(GL_POLYGON);
for(i=0; i<360; i++)
glVertex2f(0.2*cos(i), 0.2*sin(i));
glEnd();
}
void sun()
{
int i;
GLfloat a[30][3],theta=0,delta=2*M_PI/30.0,r=2.0;
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.7,6+y,0);
glColor3f(1.0,0.6,0.0);
for(i=0;i<30;i++)
{
a[i][0]=d+r*cos(theta);
a[i][1]=y+r*sin(theta);
a[i][2]=0;
theta+=delta;

}
glBegin(GL_POLYGON);
for(i=0;i<30;i++)
glVertex3fv(a[i]);
glEnd();
}
void hill()
{
glColor3f(0.5,0.4,0.2);
glBegin(GL_TRIANGLES);
glVertex3f(-15,6,0);
glVertex3f(-7,12,0);
glVertex3f(1,6,0);
glVertex3f(0,6,0);
glVertex3f(10,12,0);
glVertex3f(15,6,0);
glEnd();
glColor3f(0.4,0.3,0.1);
glBegin(GL_TRIANGLES);
glVertex3f(-10.4,8.5,0);
glVertex3f(-8.5,9.5,0);
glVertex3f(-6.6,8.5,0);
glEnd();
glColor3f(0.8,0.7,0.2);
glBegin(GL_POLYGON);
glVertex3f(-10,6,0);
glVertex3f(-10,8.5,0);
glVertex3f(-7,8.5,0);
glVertex3f(-7,6,0);
glEnd();
glFlush();
}
void sea()
{
glColor4f(0.2, 0.6, 0.8, .7);
glBegin(GL_POLYGON);
glVertex2f(-15,-18);
glVertex2f(-15,6);
glVertex2f(15,6);
glVertex2f(15,-18);
glEnd();
}
void boat()
{
glPushMatrix();
glTranslatef(-11+0.6*x,3,0);
glScalef(0.4,0.5,0.9);
glColor3f(0.6,0.4,0.1);
glBegin(GL_POLYGON);
glVertex2f(-12,-3);
glVertex2f(-20,5);
glVertex2f(19,5);
glVertex2f(10,-3);
glEnd();
glPopMatrix();
}

void circle()
{
int i;
float r=1;
glPushMatrix();
glTranslatef(-10+0.6*x,13,0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
for(i=0;i<360;i++)
{
glVertex3f(r*cos(i),r*sin(i),0);
}
glEnd();
glPopMatrix();
}
void man()
{
//glPushMatrix();
circle();
glTranslatef(0.6*x,0,0);
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(-10,12,0);
glVertex3f(-10,8,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(-10,11,0);
glVertex3f(-13,10,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
glVertex3f(-10,11,0);
glVertex3f(-7,11,0);
glVertex3f(2,-1+dy,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(-10,8,0);
glVertex3f(-11,5.5,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(-10,8,0);
glVertex3f(-9,5.5,0);
glEnd();
// glPopMatrix();
}

void idle()
{
int i;
if(x<10&&b[5]<19.8)

x+=0.01;
if(y<3.5 && d<5)
{y+=0.001;d=1.1*y; dy+=0.001;}
if(y>=3.5&&a[5]>9.7)
a[5]-=0.05;
if(a[5]<=9.7&&b[5]<19.8)
{
if(an>45);
an+=0.03;
dy+=0.01;
a[5]-=0.001;
b[5]+=0.0095;
}
if(b[5]>=19.8)
{
x-=0.01;
a[5]-=0.01*0.6;
}
if(dr<1.0){dr+=0.0006;dg=db=dr;}
for(i=0; i<5; i++)
{
a[i]-=0.05;
if(a[i]<-17)
a[i]=17;
}
glutPostRedisplay();
}
void display()
{
int i, j, rx, ry;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(dr, dg, db, 1);
glLoadIdentity();
sun();
glLoadIdentity();
hill();
for(i=0; i<5; i++)
{
glLoadIdentity();
glColor3f(0.8, 0.3, 0);
glTranslatef(a[i], b[i]-13, 0);
glRotatef(180, 0, 1, 0);
glScalef(0.5, 0.5, 0);
fish();
}
if(y>=3.5)
{
glLoadIdentity();
glColor3f(0.8, 0.3, 0);
glTranslatef(a[5], b[5]-13, 0);
glRotatef(180, 0, 1, 0);
glRotatef(an, 0, 0, 1);
glScalef(0.5, 0.5, 0);
fish();
}

glLoadIdentity();
sea();
glLoadIdentity();
boat();
glLoadIdentity();
man();
glFlush();
glutSwapBuffers();
}
void start(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15.0,15.0,-15*(GLfloat)h/(GLfloat)w,15*(GLfloat)h/(GLfloat)w, -15, 15)
;
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(700,700);
glutInitWindowPosition(200,100);
glutCreateWindow("story");
glutReshapeFunc(start);
glutDisplayFunc(display);
glutIdleFunc(idle);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop();
}

You might also like