IMPLEMENTATION
1. Main function
This main function is capable of handling the
arguments given in the argument list at the command prompt as we have used variable
‘argc’ for total number of arguments and ‘argv’ for the array of argument list.
Main function initializes the Display Mode, Window
Size and position. Then it invokes the display function within glutDisplayFunc()
as the call back function.
void main(int argc, char* argv[])
{
glutInit(&argc,
argv);
glutInitDisplayMode(GLUT_DOUBLE
| GLUT_RGB);
glutInitWindowSize(1346,728);
glutInitWindowPosition(0,0);
glutCreateWindow("Traffic
signal");
glutDisplayFunc(mydisplay);
/*call
back functions*/
glutKeyboardFunc(myKeyboard);
glutMouseFunc(myMouse);
myinit();
glutMainLoop();
}
2.
Keyboard function
This
Interactive function is invoked at the main program within glutKeyboardFunc()
and it is repeatedly called during the execution of the program and hence
handles the keyboard interrupts from the users.
When a key is
been pressed the ASCII code of the key and the position of the screen pointer
at the time of interruption will be sent to the function.
void myKeyboard(
unsigned char key, int x, int y )
{
switch(key)
{
case 13:
if(flag==1)
{
flag=2;
mydisplay();
}
if(flag==0) //Ascii of 'enter' key is 13
{
flag=1;
mydisplay();
} break;
case 'l': control_keyl=key;
p=0;q=0;r=1;break;
case 'r': control_keyr=key;
p=0;q=0;r=1;break;
case 's': mydisplay();break;
case 'h': flag=1;mydisplay(); break;
default: break;
}
}
3.
Mouse function
This
Interactive function is invoked at the main program within glutMoseFunc() and
it is repeatedly called during the execution of the program and hence handles
the Mouse interrupts from the users.
When a button
is been pressed the identity of the button and the state of the button and the
position of the screen pointer at the time of interruption will be sent to the
mouse function.
void
myMouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
traffic_regulator=0;
p=1;q=0;r=0;}
if(button==GLUT_RIGHT_BUTTON &&
state==GLUT_DOWN)
{
traffic_regulator=0;
p=0;q=1;r=0;
}
if(button==GLUT_RIGHT_BUTTON && state==GLUT_UP)
{
traffic_regulator=1;
p=0;q=0;r=1;
}
glutPostRedisplay();
}
4.
Displaying text on the screen
The setFont() function is used to set the type of the font we are using.
The drawstring() function takes the position of the string to be displayed on
the screen in X Y Z coordinates and the string to display.
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,0.0,0.0);
glutBitmapCharacter(currentfont,*c);
}
}
void
frontscreen(void)
{
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glClearColor(0.15,0.1,0.01,0);/*background
for cover page*/
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
drawstring(450.0,700.0,0.0,"BEARYS
INSTITUTE OF TECHNOLOGY ");
glFLush();
}
5. Display functions
We have used three display functions in this program
the first one that is the myDisplay function is called in the main program
using glutDisplayFunc() call back function. The mydisplay function controls the
displaying of the front screen, help screen or the display function.
The second display function that is display() calls
the objects like road(),car() etc. According to the order that we have written
hence it indirectly handles the depth information.
void
mydisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
if(flag==0)
frontscreen
();
if(flag==1)
helpscreen();
if(flag==2)
display();
glutSwapBuffers();
}
glutPostRedisplay();
}
void
display(void)
{
if(traffic_regulator)
glutTimerFunc(50,update,0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(red,green,blue,0);/*back
ground for sky*/
road();
bus();
signal();
car();
car2();
glFlush();
}
Update function is used for the transformation of the objects this function is invoked in display function inside glutTimerFunc(50,update,0). This function calls the update every 50 mille seconds hence the variable ‘a’, ’b’ are all modified then when we translate the object with this points we will see the animation effect.
void update(int
value)
{
a=a-6;
b=b+6;
control();
/*making
day to night*/
if(blue!=0&&green!=0)
{
blue-=.004;green-=.004;
}
please send me the source code at
ReplyDeleteananna.rahman92@gmail.com
ananna..whether they have send the code to you??please tell me..
DeleteCan you please send me the source code of "dispersion of light" to
ReplyDeletekarunasathish1995@gmail.com
Please please please
Hi
ReplyDeleteI loved the great work of development from your side. I want to have this source code for this projects if you want me to charge for it that's also ok kindly share the source code to anusha558899@gmail.com or shoot a email for amount you want me to paid for it.
You can visit luxury apartments in sarjapur road Bangalore, HM Scottsville - the upcoming premium apartment from the top developers and builders in Bangalore.
pls share me the source code at devik.cs@gmail.com
ReplyDeletepls share me the source code at devik.cs@gmail.com
ReplyDeleteplz share code at abhishekabhi260@yahoo.com
ReplyDeletecan you get me the PPT for this ?? kazriyasudheen@gmail.com
ReplyDeletehave you got the code??if you have means can you please send the code for me??? please help me..
Deletecan you please send the code for me..plzzzz help me..email::spadhu96@gmail.com
ReplyDeleteAbhishek abhi is selling your source code and project report to people in 250rs for source code and 100rs for reports. I had taken the same report from him in 100rs.And now he is not refunding me.
ReplyDeletecan you please send me this source code.....please please please
ReplyDeleteatharvspathak@gmail.com