
#include
#include
#include
#include
#include
#include
static double x=0.0,x1=-3.0,x2=3.0,y1=0.0,y2=0;
static double x8=-4.0,x9=4.0,y8=1.0,y9=1;
static double move=-60;
static bool pca2pcb=false,pca2rt=false,rt2pca=false, pcb2pca=false, local=false,
dubai=false;
void P();
void d();
void *font;
void *currentfont;
void setFont(void *font)
{
currentfont=font;
}
void drawstring(float x,float y,float z,char *string)
{
char *c;
glRasterPos3f(x,y,z);
for(c=string;*c!='\0';c++)
{ glColor3f(0.0,1.0,1.0);
glutBitmapCharacter(currentfont,*c);
}
}
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();
DATA COMMUNICATION over INTERNET
11 Dept. of Computer Science & Engineering.
glTranslatef(-2.5, y, 0);
glScaled(0.003, 0.005, 0.005);
for (p = buffer; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
}
//Windows
void window(float x4, float y4)
{
glLoadIdentity();
glColor3f(1.0,1.5,0.5);
glTranslatef(0.0f,0.0f,-11.0f);
for(float j=-2;j=-5 && x9=4){
DATA COMMUNICATION over INTERNET
15 Dept. of Computer Science & Engineering.
pcb2pca=true;
pca2pcb=false;
} }
//Ack
if(pcb2pca){
glPushMatrix();
glTranslatef(x8,y8,-2.0);
glScaled(0.1,0.1,0.1);
glColor3f(x8,0,1);
glutSolidCube(1);
glPopMatrix();
}
if(pca2rt)
{
glPushMatrix();
glTranslatef(x8,y8,-2.0);
glScaled(0.1,0.1,0.1);
glColor3f(x8,0,1);
glutSolidCube(1);
glPopMatrix();
}
// move the packet out of LAN
if(pca2rt && rt2pca==false && y8>=6)
{
glutIdleFunc(P);
}
//switch
glPushMatrix();
glColor3f(0.5,0.5,1.5);
glTranslatef(0.0,0,1.0);
glRotatef(15,1.0f,0.0f,0.0f);
glScaled(1.2,0.2,1.0);
glutSolidCube(1);
glPopMatrix();
pc(-5,1,0);
cpu(-3.5,7,1.5);
DATA COMMUNICATION over INTERNET
16 Dept. of Computer Science & Engineering.
pc(5,1,0);
cpu(3.5,7,1.5);
pc(0,20,2);
cpu(0,105,1.5);
glFlush();
glutSwapBuffers();
}
// Draw Network
void network(double ang,double x1,double x2,double y1,double y2)
{
glClearColor(0.0,0.85,1,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glBegin(GL_POLYGON);
glColor3f(0.0,1.8,0.0);
glVertex2f(-10,0);
glVertex2f(10,0);
glVertex2f(-10,-10);
glVertex2f(-10,10);
glEnd();
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-4.2,2.65,0.0,"LOCAL BUILDING");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1.5,3.2,0.0,"EARTH Connected with Fibric Wires");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(2.5,2.65,0.0,"DUBAI BUILDING");
//Earth
glPushMatrix();
glColor3f(0.5,0.5,1.5);
glScaled(0.8,1,0.8);
glTranslatef(0.0,2.2,0.0);
glRotatef(ang,0.0f,-1.0f,0.0f);
DATA COMMUNICATION over INTERNET
17 Dept. of Computer Science & Engineering.
glutSolidSphere(1,20,20);
glPopMatrix();
//Building A
glLoadIdentity();
glTranslatef(0.0f,0.0f,-12.0f);
glPushMatrix();
glTranslatef(-3,-0.5,0.0);
glScaled(0.8,2.2,0.8);
glutSolidCube(1.8);
glPopMatrix();
window(-2.6, 1);
//Building B
glLoadIdentity();
glTranslatef(0.0f,0.0f,-12.0f);
glPushMatrix();
glTranslatef(3,-0.5,0.0);
glScaled(0.8,2.2,0.8);
glutSolidCube(1.8);
glPopMatrix();
window1(3.3, 1);
// Line 1
glPushMatrix();
glTranslatef(-3.0,1.0,-2.0);
glScaled(0.1,3.0,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(-1.45,2.4,-2.0);
glScaled(3.0,0.2,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
//Line 2
glPushMatrix();
DATA COMMUNICATION over INTERNET
18 Dept. of Computer Science & Engineering.
glTranslatef(3.0,1.0,-2.0);
glScaled(0.1,3.0,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(1.45,2.4,-2.0);
glScaled(3.0,0.2,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
// Transmission of Datapackets
glPushMatrix();
// Send Packets
if(local){
if(x1==-3 && y1=2.38 && x1=3 && y1>=0)
glTranslatef(3,y1,-2.0);
if(x1>=3 && y1=3 && y2=2.38 && x2>=-3)
glTranslatef(x2,2.38,-2.0);
if(x2=0.0)
glTranslatef(-3,y2,-2.0);
if(x2=2.38 && x1=3 && y1>=0.0){
y1-=0.01;
}
x+= .07;
network(x,x1,x2,y1,y2);
}
//Dubai to local
if(dubai)
{
if(x2>=3 && y2=2.38 && x2>=-3)
x2-=0.01;
if(x2=0.0)
y2-=0.01;
x+= .07;
network(x,x1,x2,y1,y2);
} }
DATA COMMUNICATION over INTERNET
22 Dept. of Computer Science & Engineering.
void d()
{
if(pca2pcb)
{ if(x8>=-4 && x8=-4){
x9-=0.01;
}
lan(x9,0);
}
// To Dubai
if(pca2rt & rt2pca==false)
{
if(x8>=-4 && y8=0 && y8=0)
{y8-=0.01;
}
if(x8>=-4 && y8 Start");
stroke_output(-2.0, -1.75, "A --> About");
stroke_output(-2.0, -3,"q --> Quit");
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,5.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
}
void menu(int id)
{
switch(id)
{
case 1:glutIdleFunc(about);
DATA COMMUNICATION over INTERNET
25 Dept. of Computer Science & Engineering.
break;
case 2:glutIdleFunc(s);
break;
case 3:glutIdleFunc(d);
break;
case 4:glutIdleFunc(P);
break;
case 5:glutIdleFunc(n);
break;
case 6:
pca2pcb=true;
x8=-4;
glutIdleFunc(d);
break;
case 7:
local=true;
dubai=false;
pca2rt=true;
x8=-4.0;x9=4.0;y8=0.0; y9=0;
pca2pcb=false;
pcb2pca=false;
glutIdleFunc(d);
break;
case 8: pca2rt=false;
pca2pcb=false;
x8=-4.0;x9=4.0;y8=1.0; y9=0;
x=0.0;x1=-3.0;x2=3.0;y1=0.0;y2=2.38;
pca2pcb=false;pca2rt=false; pcb2pca=false;
glutIdleFunc(s);
break;
case 9:exit(0);
break;
}
glFlush();
glutSwapBuffers();
glutPostRedisplay();
DATA COMMUNICATION over INTERNET
26 Dept. of Computer Science & Engineering.
}
void mykey(unsigned char key,int x,int y)
{
if(key=='s')
{
glutIdleFunc(s);
}
if(key=='n')
{
glutIdleFunc(n);
}
if(key=='P')
{
glutIdleFunc(P);
}
if(key=='A')
{
glutIdleFunc(about);
}
if(key=='q'||key=='Q')
{
exit(0);
}
}
void main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(1000,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Data Communication in Network");
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
DATA COMMUNICATION over INTERNET
27 Dept. of Computer Science & Engineering.
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("About Project 'A'",1);
glutAddMenuEntry("Local Area Network(LAN) 's'",2);
glutAddMenuEntry("Local Area Network(LAN) 'n'",3);
glutAddMenuEntry("Wide Area Network(WAN) 'P'",5);
glutAddMenuEntry("Transfer data from PC-A to PC-B '1'",6);
glutAddMenuEntry("Transfer data from PC-A to Company B -->'2'",7);
glutAddMenuEntry("Reset 'r'",8);
glutAddMenuEntry("Quit 'q'",9);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
}
1>