23
#include<stdafx.h> #include<stdio.h> #include<string.h> #include<glut.h> #include<math.h> /*-----Phenomena of Total Internal Reflection------------------*/ /*------------DECLARATIONS----------------*/ //SLIDE 1 float welcomex=180,welcomeflag=0,cc=0,cc1,welx=240; void text(char *c,int x,int y); //SLIDE 2 float pcol1=0,pcol2=0.5,pcol3=1.0; float x8=20,x1=20,y2=21,x2=21.5,y3=38,x4=20,y4=20,x5=33.2,y5=38,x6=20,y6=21,x7=25; int flagtir1=0,flagtir2=0,flagtir3=0; float xray=150,xray1=200,xray2=233,xray3=300,xray4=334,yray=125,yray1=146,yray2=112,yray3=148,yray4=112,nextray=1; float xray5=390,yray5=147,rayt=1,xray0=150; int transmit=0,flag=0,flag1=0; void textt(char *c,int x,int y); void text(char *c,int x,int y); void texttt(char *c,int x,int y); float xp=30,yp=450,ss=0; int slide=1,c=0,c1=0,s2flag=0; void box(); void text(char *c,int x,int y); void texttt(char *c,int x,int y); void screen(); /*-----------Project Code-----------------*/ //SLIDE 1 void animate1() { if(slide==1)

seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

  • Upload
    dobao

  • View
    235

  • Download
    0

Embed Size (px)

Citation preview

Page 1: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

#include<stdafx.h>#include<stdio.h>#include<string.h>#include<glut.h>#include<math.h>

/*-----Phenomena of Total Internal Reflection------------------*//*------------DECLARATIONS----------------*///SLIDE 1float welcomex=180,welcomeflag=0,cc=0,cc1,welx=240;void text(char *c,int x,int y);//SLIDE 2float pcol1=0,pcol2=0.5,pcol3=1.0;float x8=20,x1=20,y2=21,x2=21.5,y3=38,x4=20,y4=20,x5=33.2,y5=38,x6=20,y6=21,x7=25;int flagtir1=0,flagtir2=0,flagtir3=0;float xray=150,xray1=200,xray2=233,xray3=300,xray4=334,yray=125,yray1=146,yray2=112,yray3=148,yray4=112,nextray=1;float xray5=390,yray5=147,rayt=1,xray0=150;int transmit=0,flag=0,flag1=0;void textt(char *c,int x,int y);void text(char *c,int x,int y);void texttt(char *c,int x,int y);float xp=30,yp=450,ss=0;int slide=1,c=0,c1=0,s2flag=0;void box();void text(char *c,int x,int y);void texttt(char *c,int x,int y);void screen();

/*-----------Project Code-----------------*///SLIDE 1void animate1(){

if(slide==1){if(welcomex<240) welcomex=welcomex+0.5; //THE INTIAL WELCOME ACROSS THE SCREEN FROM LEFT}else{

welcomex=180,welcomeflag=0,cc=0,cc1,welx=240;

Page 2: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

}glutPostRedisplay();

}

void laptops(){

/* laptop screen*/ glColor3f(0.0,0.0,0.0);

glBegin(GL_POLYGON);glVertex3f(600.0,500.0,0);glVertex3f(600.0,710.0,0);glVertex3f(800.0,710.0,0);glVertex3f(800.0,500.0,0);glEnd(); glColor3f(0.70,0.70,0.70); glBegin(GL_LINE_LOOP);glVertex3f(600.0,500.0,0);glVertex3f(600.0,710.0,0);glVertex3f(800.0,710.0,0);glVertex3f(800.0,500.0,0);glEnd();

/* slant screen*/glColor3f(0.0,0.0,0.0);glBegin(GL_POLYGON);glVertex3f(520.0,400.0,0);glVertex3f(600.0,500.0,0);glVertex3f(800.0,500.0,0);glVertex3f(720.0,400.0,0);glEnd();/*slant bottom edge*/glColor3f(0.3,0.3,0.3);glBegin(GL_POLYGON);glVertex3f(520.0,380.0,0);glVertex3f(520.0,400.0,0);glVertex3f(720.0,400.0,0);glVertex3f(720.0,380.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(520.0,380.0,0);

Page 3: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glVertex3f(520.0,400.0,0);glVertex3f(720.0,400.0,0);glVertex3f(720.0,380.0,0);glEnd();

/*slant side edge*/glColor3f(0.3,0.3,0.3);glBegin(GL_POLYGON);glVertex3f(720.0,380.0,0);glVertex3f(720.0,400.0,0);glVertex3f(800.0,500.0,0);glVertex3f(800.0,480.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(720.0,380.0,0);glVertex3f(720.0,400.0,0);glVertex3f(800.0,500.0,0);glVertex3f(800.0,480.0,0);glEnd();/* keypad*/

glColor3f(0.70,0.70,0.70);glBegin(GL_POLYGON);glVertex3f(555.0,435.0,0);glVertex3f(600.0,495.0,0);glVertex3f(790.0,495.0,0);glVertex3f(740.0,435.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(555.0,435.0,0);glVertex3f(600.0,495.0,0);glVertex3f(790.0,495.0,0);glVertex3f(740.0,435.0,0);glEnd();//glLineWidth(2);glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(585.0,475.0,0);

Page 4: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glVertex3f(775.0,475.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(570.0,455.0,0);glVertex3f(755.0,455.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(585.0,435.0,0);glVertex3f(630.0,495.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(625.0,435.0,0);glVertex3f(670.0,495.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(665.0,435.0,0);glVertex3f(710.0,495.0,0);glEnd();glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_LOOP);glVertex3f(705.0,435.0,0);glVertex3f(750.0,495.0,0);glEnd();

/* touch screen*/glColor3f(0.5,0.5,0.5);

glBegin(GL_POLYGON);glVertex3f(590.0,405.0,0);glVertex3f(610.0,430.0,0);glVertex3f(680.0,430.0,0);glVertex3f(660.0,405.0,0);glEnd();

/*inner first screen*/

Page 5: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glColor3f(0.5,0.5,0.5);glBegin(GL_POLYGON);glVertex3f(110.0,510.0,0);glVertex3f(110.0,695.0,0);glVertex3f(290.0,695.0,0);glVertex3f(290.0,510.0,0);glEnd();

/* inner screen*/glColor3f(0.5,0.5,0.5);glBegin(GL_POLYGON);glVertex3f(610.0,510.0,0);glVertex3f(610.0,695.0,0);glVertex3f(790.0,695.0,0);glVertex3f(790.0,510.0,0);glEnd();

}void slide1(){

glClear(GL_COLOR_BUFFER_BIT);glClearColor(0.2,0.4,1,0);

glutIdleFunc(animate1);//TableglPushMatrix();glTranslatef(300,135,0);glScalef(6,2,2);glRotatef(45,-1,0,0);glRotatef(3,0,1,0);glColor4f(.234,.097,0,.7);glutSolidCube(100);

// glutSolidCone(30,40,50,100);glPopMatrix();

glPushMatrix();glTranslatef(-770,-500,0);glScalef(1.5,1.5,1.5); /*POSITIONING AND SCALING THE LAPTOP APPROPRIATELY*/laptops();glPopMatrix();

Page 6: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glPushMatrix();glTranslatef(0,150,0); /*SCALING AND POSITIONING THE ENTIRE WELCOME,LOGIN BOX WRT THE LAPTOP*/glScalef(0.8,0.8,0.8);glPushMatrix();

glPopMatrix();if(welcomex>=140 && welx<480){

welx=welx+1;}if(welx==480){

if(cc1<150){ //DELAY FOR WELCOME TO APPEARcc1=cc1+0.73;if(cc1>5){

text("TOTAL INTERNAL REFLECTION ",200,340);}}

if(cc1>=150){

textt("Computer Graphics Project",200,450);textt("______________________",200,449);text("Project Description:",200,400);text(" _______________",200,397);text("Phenomenon Of Total Internal Reflection",280,370);textt("Developed By",390,280);textt("SRINIVASA T K",387,257);textt("VINAY KUMAR T S",387,230);texttt("Click the mouse pad to continue viewing the Project",200,170);

}}glPopMatrix();glFlush();glutSwapBuffers();

Page 7: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

}//SLIDE TOTAL INTERNAL REFLECTION//SLIDE 2void animate2(){

if(x8<60)x8+=.1;

if(flagtir1==0 && flagtir2==0 && y2<38.0){

x1+=.01;y2+=.1;

x4+=.08;y4+=.105;

x6+=.03;y6+=.1;

}if(y2>38){

flagtir1=1;flagtir2=1;flagtir3=1;

}

if(flagtir1==1){if(x2<50)

x2+=.1;if(y3<66.5)y3+=.1;

}

if(flagtir2==1 && y5>25){x5+=.1;y5-=.1;

}if(flagtir3==1 && x7<63)

x7+=.1;// }}void box()

Page 8: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

{//FrontglColor3f(pcol1,pcol2,pcol3);glBegin(GL_POLYGON);glColor3f(1.0,1.0,1.0);glVertex3f(60,38,-50);glColor3f(1.0,1.0,1.0);glVertex3f(10,38,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(10,18,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(60,18,-50);glEnd();

//BackglBegin(GL_POLYGON);glColor3f(1.0,1.0,1.0);glVertex3f(60,40,0);glColor3f(1.0,1.0,1.0);glVertex3f(10,40,0);glColor3f(pcol1,pcol2,pcol3);glVertex3f(10,20,0);glColor3f(pcol1,pcol2,pcol3);glVertex3f(60,20,0);glEnd();

//leftglBegin(GL_POLYGON);glColor3f(1.0,1.0,1.0);glVertex3f(60,40,0);glColor3f(1.0,1.0,1.0);glVertex3f(60,38,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(60,18,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(60,20,0);glEnd();//rightglBegin(GL_POLYGON);glColor3f(1.0,1.0,1.0);

Page 9: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glVertex3f(10,40,0);glColor3f(1.0,1.0,1.0);glVertex3f(10,38,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(10,18,-50);glColor3f(pcol1,pcol2,pcol3);glVertex3f(10,20,0);glEnd();

//FrontglLineWidth(3);glBegin(GL_LINE_LOOP);glColor3f(0.0,0.0,0.0);glVertex3f(60,40,0);glVertex3f(10,40,0);glVertex3f(10,38,-50);glVertex3f(60,38,-50);glEnd();

//bottomglBegin(GL_LINE_LOOP);glVertex3f(10,18,-50);glVertex3f(10,20,0);glVertex3f(60,20,0);glVertex3f(60,18,-50);glEnd();

//Front

glBegin(GL_LINE_LOOP);glVertex3f(60,38,-50);glVertex3f(10,38,-50);glVertex3f(10,18,-50);glVertex3f(60,18,-50);glEnd();

//BackglBegin(GL_LINE_LOOP);

Page 10: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glVertex3f(60,40,0);glVertex3f(10,40,0);glVertex3f(10,20,0);glVertex3f(60,20,0);glEnd();

//leftglBegin(GL_LINE_LOOP);glVertex3f(60,40,0);glVertex3f(60,38,-50);glVertex3f(60,18,-50);glVertex3f(60,20,0);glEnd();//rightglBegin(GL_LINE_LOOP);glVertex3f(10,40,0);glVertex3f(10,38,-50);glVertex3f(10,18,-50);glVertex3f(10,20,0);glEnd();

//topglBegin(GL_POLYGON);glColor3f(1.0,1.0,1.0);glVertex3f(60,40,0);glVertex3f(10,40,0);glVertex3f(10,38,-50);glVertex3f(60,38,-50);glEnd();

//bottomglColor3f(pcol1,pcol2,pcol3);glBegin(GL_POLYGON);glVertex3f(10,18,-50);glVertex3f(10,20,0);glVertex3f(60,20,0);glVertex3f(60,18,-50);glEnd();

//Normal

Page 11: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glColor3f(0,0,0);glEnable(GL_LINE_STIPPLE);glLineStipple (5, 0xAAAA);glBegin(GL_LINES);glVertex3f(24.3,48,-50);glVertex3f(24.3,8,-50);glEnd();glDisable(GL_LINE_STIPPLE);glLineWidth(1);

}

void box_line(){

//restglLineWidth(3);glColor3f(0,0,0);glBegin(GL_LINES);glVertex3f(10,38,-50);glVertex3f(10,18,-50);glEnd();

glLineWidth(3);glBegin(GL_LINE_LOOP);glColor3f(0.0,0.0,0.0);glVertex3f(60,40,0);glVertex3f(10,40,0);glVertex3f(10,38,-50);glVertex3f(60,38,-50);glEnd();

//bottom//glBegin(GL_LINE_LOOP);//glVertex3f(10,18,-50);//glVertex3f(10,20,0);//glVertex3f(60,20,0);//glVertex3f(60,18,-50);//glEnd();

//Front

Page 12: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glBegin(GL_LINE_LOOP);glVertex3f(60,38,-50);glVertex3f(10,38,-50);glVertex3f(10,18,-50);glVertex3f(60,18,-50);glEnd();

//BackglBegin(GL_LINE_LOOP);glVertex3f(60,40,0);glVertex3f(10,40,0);glVertex3f(10,20,0);glVertex3f(60,20,0);glEnd();

//leftglBegin(GL_LINE_LOOP);glVertex3f(60,40,0);glVertex3f(60,38,-50);glVertex3f(60,18,-50);glVertex3f(60,20,0);glEnd();//rightglBegin(GL_LINE_LOOP);glVertex3f(10,40,0);glVertex3f(10,38,-50);glVertex3f(10,18,-50);glVertex3f(10,20,0);glEnd();glLineWidth(1);

}void ray(){

glLineWidth(10);glColor3f(1,1,0);glBegin(GL_LINES);glVertex3f(20,21,-20);glVertex3f(20,x8,-20);glEnd();glBegin(GL_LINES);

Page 13: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glVertex3f(20,21,-20);glVertex3f(x1,y2,-20);glEnd();glBegin(GL_LINES);glVertex3f(20,21,-20);glVertex3f(x4,y4,-20);glEnd();glBegin(GL_LINES);glVertex3f(20,21,-20);glVertex3f(x6,y6,-20);glEnd();if(flagtir1==1){

glBegin(GL_LINES);glVertex3f(21.5,38,-20);glVertex3f(x2,y3,-20);glEnd();

}

if(flagtir2==1){

glBegin(GL_LINES);glVertex3f(33.5,38,-20);glVertex3f(x5,y5,-20);glEnd();

}

if(flagtir3==1){

glBegin(GL_LINES);glVertex3f(25,38,-20);glVertex3f(x7,38,-20);glEnd();

}glColor3f(1,.5,0);glPointSize(25);glBegin(GL_POINTS);glVertex3f(20,21,-20);glEnd();glPointSize(1);

}

Page 14: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

void wall(){//Back Wall

glColor3f(1,1,.5);glBegin(GL_QUADS);glVertex3f(30,30,0);glVertex3f(30,600,0);glVertex3f(600,600,0);glVertex3f(600,30,0);glEnd();glLineWidth(5);// WallsglColor3f(1,0.4,.4);glBegin(GL_QUADS);glVertex3f(0,0,0);glVertex3f(0,600,0);glVertex3f(600,600,0);glVertex3f(600,0,0);glEnd();//Wall BoundryglLineWidth(50);glColor3f(0,0,0);glBegin(GL_LINES);glVertex3f(50,50,0);glVertex3f(50,600,0);glVertex3f(550,50,0);glVertex3f(550,600,0);glEnd();glLineWidth(1);

//FloorglColor3f(0,0,0.3);glBegin(GL_QUADS);glVertex3f(0,0,0);glVertex3f(50,60,0);glVertex3f(550,60,0);glVertex3f(600,0,0);

glEnd();

Page 15: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glLineWidth(5);}void legs(){

glColor3f(0,0,0);glBegin(GL_QUADS);glVertex3f(0,50,-50);glVertex3f(3,50,-50);glVertex3f(3,0,-50);glVertex3f(0,0,-50);glEnd();glColor3f(.86,.59,.402);glBegin(GL_LINE_LOOP);glVertex3f(0,50,-50);glVertex3f(3,50,-50);glVertex3f(3,0,-50);glVertex3f(0,0,-50);glEnd();

}void slide2(){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glClearColor(1,1,1,0);glutIdleFunc(animate2);

// screen();wall();glPushMatrix();glTranslatef(55,-190,0);

//LegsglLineWidth(3);glPushMatrix();glScalef(1,2,0);glTranslatef(120,110,0);legs();glTranslatef(300,0,0);legs();glTranslatef(-20,10,0);

Page 16: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

glScalef(1,.8,1);legs();glTranslatef(-300,0,0);legs();glPopMatrix();

//TableglPushMatrix();glTranslatef(260,325,0);glScalef(7,0.35,5);glRotatef(45,1,0,0);glRotatef(3,0,1,0);glColor4f(.234,.097,0,.7);glutSolidCube(50);

// glutSolidCone(30,40,50,100);glPopMatrix();

glPushMatrix();glTranslatef(100,250,0);glRotatef(-17,0,1,0);glScalef(4,4,4);

box();ray();box_line();

glPopMatrix();glPopMatrix();text("Total Internal Reflection",250,550);

// texttt("Slide 1",0,580);texttt("DENSER MEDIUM(e.g Glass)",350,200);texttt("LESS DENSE MEDIUM(e.g air)",350,250);texttt("Normal",310,170);text("Rays formed due to",140,400);textt("1)Angle of incidence normal to the object",105,380);textt("2)Angle of incidence < Critical angle",105,360);textt("3)Angle of incidence = Critical angle",105,340);textt("4)Angle of incidence > Critical angle",105,320);glutPostRedisplay();glutSwapBuffers();

}

Page 17: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

//GENERAL FUNCTIONS TO ALL SLIDESvoid mainmenu(int id){

switch(id){case 1: slide++;

break;case 2:slide--;

break;case 3:exit(0);}glutPostRedisplay();

}void slideshow(){

if(slide==1)slide1();

if(slide==2)slide2();

if(slide==3)exit(0);

glFlush();}//Text Funtionsvoid text(char *c,int x,int y){

glColor3f(1,0,0);int len=strlen(c);glRasterPos2f(x,y);for(int i=0;i<len;i++)

glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,c[i]);

}void textt(char *c,int x,int y){

glColor3f(0,0.5,0.5);int len=strlen(c);glRasterPos2f(x,y);for(int i=0;i<len;i++)

glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,c[i]);

Page 18: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

}void texttt(char *c,int x,int y){

glColor3f(0.5,0,0);int len=strlen(c);glRasterPos2f(x,y);for(int i=0;i<len;i++)

glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,c[i]);

}//INITIALIZATIONGLdouble ox=0.0,oy=0.0,oz=0.0;GLint viewport[4];GLdouble modelview[16],projection[16];GLfloat wx,wy,wz;void Mouse(int button,int state,int x,int y){

wx=x; if(state!=GLUT_DOWN) return; glGetIntegerv(GL_VIEWPORT,viewport); y=viewport[3]-y; wy=y; glGetDoublev(GL_MODELVIEW_MATRIX,modelview); glGetDoublev(GL_PROJECTION_MATRIX,projection); glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&wz); gluUnProject(wx,wy,wz,modelview,projection,viewport,&ox,&oy,&oz); printf(" %f,%f",wx,wy); if(wx>=45 && wx<=215 && wy<=190 && wy>=145 && slide==1)

slide++; //Condition to move from slide 1 to slide 2 from touchpad. if(wx>0 && wx<280 &&wy>100 &&wy<250 && slide==3) {

rayt=1; //Condition to transmit ray for Multimode

transmit=2; } if(wx>0 && wx<60 &&wy>464 &&wy<576 && slide==3) {

Page 19: seenubabueducom.files.wordpress.com€¦ · Web view#include #include #include #include #include /*-----Phenomena

rayt=1; transmit=1; //Condition to transmit ray

for single mode}if(wx>1245 && wx<1345 &&wy>15 &&wy<35 && slide==5)

{ exit(0); //Condition to exit from

last slide.}

glutPostRedisplay();}void init(){

glOrtho(0.0,600.0,0.0,600.0,-200,200);}//MAIN FUNCTIONvoid main(int argc,char **argv){

glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(1440,800);glutInitWindowPosition(0,0);glutCreateWindow("Creating");glutDisplayFunc(slideshow);

// glutFullScreen();glutCreateMenu(mainmenu);glutAddMenuEntry("Next",1);glutAddMenuEntry("Back",2);glutAddMenuEntry("Quit",3);glutAttachMenu(GLUT_RIGHT_BUTTON);glutMouseFunc(Mouse);init();glutMainLoop();

}