begin process at 2012 05 27 13:40:36
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > APPLICATION_LOGICIEL

APPLICATION_LOGICIEL


 Description

Cliquez pour voir la capture en taille normale
catte application intitulée extraction est exploitation de l'information spatiale dans les modéle de séléction d'action,consiste à etudier le comportement d'un humanoide dans un environnement virtuel c'est à dire l'intéraction de cet humain virtuel avec les objets de son environement . alors on parle ici d'aspet sémantique

Source

  • //---------------------------------------------------------------------------
  • #include <vcl.h>
  • #pragma hdrstop
  • #include "projet.h"
  • #include "evrm.h"
  • #define NORD 0
  • #define SUD 1
  • #define EST 2
  • #define OUEST 3
  • #define TDN 4
  • #define TGN 5
  • #define TDS 6
  • #define TGS 7
  • #define TDE 8
  • #define TGE 9
  • #define TGO 10
  • #define TDO 11
  • #define confrontation 0
  • #define perpendicularite 1
  • #define blocage 2
  • #define move 0
  • #define arrest 1
  • const int nbcelI=40;
  • const nbcelJ=60;
  • const int D=0;
  • const int HV=1;
  • coordonne pospi[30],pospj[30];
  • int posi,posj,nbcel,indicef,indicev,indice;
  • int maxcar=0,nbmaxind=0,maxlamp=0,maxarb=0;
  • bool but1=false,decoupage1=false,off=true,first=false;
  • cellule chemin[44*80];bool aller=false,vs=false,draw=false,pre=false,creer_obs=false,pre_ob=true,creer_ind=false,pre_ind=true,creer_but=false,pre_but=true;
  • bool start=false,go=true,pause=false;
  • bool one=false,twoo=false,three=false,four=false,choisir=false;
  • cellule elem1;
  • //---------------------------------------------------------------------------
  • #pragma package(smart_init)
  • #pragma resource "*.dfm"
  • TFormMain *FormMain;
  • int submenid,menid;
  • static int primitive = 0;
  • evrm *e;
  • //agent *a;
  • GLuint tex[21];
  • point pt ;
  • int c,cc;
  • float xx,yy=10;
  • bool geni =false;
  • bool arret=false;
  • bool agt_dess=false;
  • bool cam=false;
  • bool agt=false;
  • bool v2d=true,v3d=false;
  • //int nbmaxind=0;
  • const float piover180 = 0.0174532925f;
  • float heading;
  • float xpos=0;
  • float zpos=18;
  • int Xpos,Ypos;//position de l'agent
  • bool But1=false;
  • GLfloat yrot; // Y Rotation
  • GLfloat walkbias = 0;
  • GLfloat walkbiasangle = 0;
  • GLfloat lookupdown = 0.0f;
  • GLfloat z = 0.0f;
  • //---------------------------------------------------------------------------
  • __fastcall TFormMain::TFormMain(TComponent* Owner)
  • : TForm(Owner)
  • {
  • Application->OnIdle = IdleLoop;
  • size = 50.0f;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::IdleLoop(TObject*, bool& done)
  • {
  • done = false;
  • RenderGLScene();
  • SwapBuffers(hdc);
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::FormCreate(TObject *Sender)
  • {
  • hdc = GetDC(Panel1->Handle);
  • SetPixelFormatDescriptor();
  • hrc = wglCreateContext(hdc);
  • if(hrc == NULL)
  • ShowMessage(":-)~ hrc == NULL");
  • if(wglMakeCurrent(hdc, hrc) == false)
  • ShowMessage("Could not MakeCurrent");
  • w = ClientWidth;
  • h = ClientHeight;
  • glEnable(GL_DEPTH_TEST);
  • glEnable(GL_CULL_FACE);
  • //LoadGLTextures(tex); // Jump to texture loading routine ( NEW )
  • texturage(tex);
  • // SetupLighting();
  • //glClearColor(0.623f, 0.623f,1.0f, 1.0f);
  • //glClearColor(0.733333f, 0.733333f,1.0f, 1.0f);
  • //glClearColor(1.0f,1.0f,1.0f, 1.0f);
  • glClearColor(0.792157f,0.894118f,1.0f, 1.0f);
  • //glClearColor(0.823529f,0.909804f,0.968627f, 1.0f);
  • V2D->Checked=true;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::SetPixelFormatDescriptor()
  • {
  • PIXELFORMATDESCRIPTOR pfd = {
  • sizeof(PIXELFORMATDESCRIPTOR),
  • 1,
  • PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
  • PFD_TYPE_RGBA,
  • 24,
  • 0,0,0,0,0,0,
  • 0,0,
  • 0,0,0,0,0,
  • 32,
  • 0,
  • 0,
  • PFD_MAIN_PLANE,
  • 0,
  • 0,0,
  • };
  • PixelFormat = ChoosePixelFormat(hdc, &pfd);
  • SetPixelFormat(hdc, PixelFormat, &pfd);
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::FormResize(TObject *Sender)
  • {
  • GLfloat nRange = 10.0;
  • w = Panel1->Width;
  • h = Panel1->Height;
  • glViewport ( 0, 0, w, h );
  • glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
  • glLoadIdentity ( ); // Reset The Projection Matrix
  • if (w <= h)
  • glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
  • else
  • glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
  • glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
  • glLoadIdentity ( ); // Reset The Model View Matrix
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::RenderGLScene()
  • {
  • GLfloat nRange = 10.0;
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
  • glLoadIdentity ( ); // Reset The Projection Matrix
  • if(v3d) gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
  • if(v2d) glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
  • glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
  • glLoadIdentity();
  • if (v2d)
  • gluLookAt(0.0,1.0,0.0,0.0,0.0,0.0 ,0.0,0.0,-1.0);
  • if (v3d)
  • {
  • if (cam==true )
  • { GLfloat x_m, y_m, z_m, u_m, v_m;
  • GLfloat xtrans = -xpos;
  • GLfloat ztrans = -zpos;
  • GLfloat ytrans = -walkbias-0.25f;
  • GLfloat sceneroty = 360.0f - yrot;
  • int numtriangles;
  • glRotatef(lookupdown,1.0f,0,0);
  • glRotatef(sceneroty,0,1.0f,0);
  • glTranslatef(xtrans, ytrans, ztrans);
  • }
  • else
  • gluLookAt(xx,yy+2,12.0,0.0,0.0,0.0 ,0.0,0.0,-1.0);
  • }
  • DrawObjects();
  • glFlush();
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::DrawObjects()
  • {
  • if(Scene->Checked==true)
  • Draw_maison();
  • if(agt==true)
  • {
  • //aff_individus();
  • Draw_agent();
  • //aff_but();
  • }
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::FormPaint(TObject *Sender)
  • {
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • // glClearColor(1.0f,1.0f,1.0f, 0.0f);
  • // glClearColor(0.623f, 0.623f,1.0f, 1.0f);
  • //glClearColor(0.733333f, 0.733333f,1.0f, 1.0f);
  • glClearColor(0.1f,0.3f,0.8f, 1.0f);
  • //glClearColor(0.792157f,0.894118f,1.0f, 1.0f);
  • //glClearColor(0.823529f,0.909804f,0.968627f, 1.0f);
  • DrawObjects();
  • glFlush();
  • }
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • //--------------------------------------------------------------------------*/
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Draw_maison()
  • {
  • maison ma_scene;
  • ma_scene.Dessiner(tex,e);
  • creat(e);
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Draw_agent()
  • {point p;
  • glPushMatrix();
  • glTranslatef(-(e->col)/4,0.0,-(e->lig)/4);
  • aff_individus();
  • glPopMatrix();
  • creat(e);
  • glPushMatrix();
  • glTranslatef(-(e->col)/4,0.0,-(e->lig)/4);
  • aff_but();
  • glPopMatrix();
  • creat(e);
  • }
  • ///////////////////////////////////:
  • void TFormMain::set_centre(point p)
  • {
  • set_point(&pt,p.x,p.y,p.z);
  • }
  • /////////////////////////////
  • void TFormMain::set_point(point *p,GLfloat x,GLfloat y,GLfloat z)
  • {p->x=x;
  • p->y=y;
  • p->z=z;
  • }
  • /////////////////////////////////
  • /////////////dessiner individus////
  • void TFormMain::aff_individus()
  • {
  • GLfloat h_p=1.5,h_v=(2*h_p)/3,h_m=h_v,h_c=h_v/6,rad_v=0.4,rad_p=rad_v/2.3,rad_m=rad_p/2,rad_t=(2*rad_v)/3,rad_c=rad_v/3;
  • GLint ang=4;
  • GLUquadricObj *quadratic;
  • quadratic=gluNewQuadric();
  • point pt;
  • float angle=-90;
  • int x,y;
  • int nb=1,i;
  • for(i=1;i<=nbmaxind;i++)
  • { //set_point(&pt,Xpos,-2.0,Ypos);
  • //monde[i].priorite=i;
  • // angle=monde[i].angle;
  • e->init_ag(monde[i].position.I,monde[i].position.J,0.5,0.5);
  • glPushMatrix();
  • // glTranslatef(pt.x+0.25,pt.y,pt.z+0.25);
  • // glTranslatef(pt.x,pt.y,pt.z);
  • // glTranslatef(Xpos,-2,Ypos);
  • /////////////////////////tete ////////////////////////////////////
  • // glColor3f(1.0f,1.0f,1.0f);
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(0.0,h_p+h_v+h_c+rad_t,0.0);
  • // gluSphere(quadratic,rad_t,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • /////////////////////////////cou //////////////////////////
  • //glColor3f(1.0f,1.0f,1.0f);
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(0.0,h_p+h_v+rad_c/2,0.0);
  • //glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • //gluCylinder(quadratic,rad_c,rad_c,h_c,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • ////////////////////////ventre//////////////////////////
  • glColor3f(0.4f,0.21f,0.6f);
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(0.0,h_p,0.0);
  • // glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • //gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • ///////////////////////////////////////////
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(0.0,h_p+h_v,0.0);
  • // glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • //Circle(rad_v);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • /////////////////////////main_g///////////////////////////
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(-(rad_v+rad_m+0.02),h_p,0.0);
  • //glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • glRotatef(ang,0.0,1.0,0.0);
  • //gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • ///////////////////////////main_d //////////////////////////
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(+(rad_v+rad_m+0.02),h_p,0.0);
  • //glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(-ang,0.0,1.0,0.0);
  • //gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • ////////////////////////::::/pied-g ///////////////////////////
  • glColor3f(0.0f,0.0f,0.0f);
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(-(rad_v-rad_p),0.0,0.0);
  • // glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • //gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • /////////////////////:/pied-d/////////////////////////:
  • glColor3f(0.0f,0.0f,0.0f);
  • glPushMatrix();
  • glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
  • glTranslatef(+(rad_v-rad_p),0.0,0.0);
  • //glRotatef(-90,1.0,0.0,0.0);
  • glRotatef(angle,1.0,0.0,0.0);
  • //gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
  • glCallList(nb);nb++;
  • glPopMatrix();
  • glPopMatrix();
  • e->init_ag(pt.x,pt.z,0.5,0.5);
  • //e->new_obs(pt.x,pt.z,0.5,0.5);
  • }
  • }
  • /////////////////////////////////////////////////
  • void TFormMain::individus_creation()
  • {
  • GLfloat h_p=1.4,h_v=(2*h_p)/3,h_m=h_v,h_c=h_v/6,rad_v=0.4,rad_p=rad_v/2.3,rad_m=rad_p/2,rad_t=(2*rad_v)/3,rad_c=rad_v/3;
  • GLUquadricObj *quadObj;
  • GLUquadricObj *quadratic;
  • quadratic=gluNewQuadric();
  • GLint ang=4;
  • int nb=1;
  • //int h_p=1.0, h_v= 0.5,h_m=0.5;
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • monde[i].priorite=i;
  • //************************* tete *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • //glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • glColor3f(1.0f,1.0f,1.0f);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • gluSphere(quadratic,rad_t,32,32);
  • glEndList();
  • //************************* cou *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • //glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • glColor3f(1.0f,1.0f,1.0f);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • gluCylinder(quadratic,rad_c,rad_c,h_c,32,32);
  • glEndList();
  • //************************* vente *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
  • glEndList();
  • /////////////////////////////////////////////////////////////
  • glNewList( nb, GL_COMPILE);nb++;
  • glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • //gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
  • Circle(rad_v);
  • glEndList();
  • //************************* mais_g *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
  • //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • glEndList();
  • //************************* main_d *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
  • //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • glEndList();
  • //************************* pied_g *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • // glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • glColor3f(1.0f,1.0f,1.0f);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
  • // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • glEndList();
  • //************************* pied_d *************************************
  • glNewList( nb, GL_COMPILE);nb++;
  • // glColor3f(monde[i].color.r,monde[i].color.v,0.4);
  • glColor3f(1.0f,1.0f,1.0f);
  • quadObj = gluNewQuadric ();
  • gluQuadricDrawStyle (quadObj, GLU_FILL);
  • gluQuadricNormals (quadObj, GLU_SMOOTH);
  • gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
  • //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
  • glEndList();
  • }
  • }
  • /////////////////
  • //-------------------------------------------------------------------------
  • void TFormMain::aff_but()
  • {
  • int x,y,i,j;
  • for(int t=1;t<=nbmaxind;t++)
  • {
  • glPushMatrix();
  • i=monde[t].goal.I/2;
  • j=monde[t].goal.J/2;
  • x=j;
  • y=i;
  • glColor3f(monde[t].color.r,monde[t].color.v,0.4);
  • glTranslated(x,-1.9,y);
  • glScaled(1,0.1,1);
  • glutSolidCube(1);
  • glPopMatrix();
  • }
  • }
  • //////////////////////////////:::
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
  • TShiftState Shift)
  • {
  • if(Key == VK_UP)
  • {
  • xpos -= (float)sin(heading*piover180) * 0.05f;
  • zpos -= (float)cos(heading*piover180) * 0.05f;
  • if (walkbiasangle >= 359.0f)
  • {
  • walkbiasangle = 0.0f;
  • }
  • else
  • {
  • walkbiasangle+= 30;
  • }
  • walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
  • }
  • if(Key == VK_DOWN)
  • {
  • xpos += (float)sin(heading*piover180) * 0.05f;
  • zpos += (float)cos(heading*piover180) * 0.05f;
  • if (walkbiasangle <= 1.0f)
  • {
  • walkbiasangle = 359.0f;
  • }
  • else
  • {
  • walkbiasangle-= 30;
  • }
  • walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
  • }
  • if(Key == VK_LEFT)
  • {
  • heading +=4.0f;
  • yrot = heading;
  • }
  • if(Key == VK_RIGHT)
  • {
  • heading -= 4.0f;
  • yrot = heading;
  • }
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::SetupLighting()
  • {
  • GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
  • GLfloat MaterialDiffuse[] = {1.0, 1.0, 1.0, 1.0};
  • GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
  • GLfloat MaterialShininess[] = {50.0};
  • GLfloat AmbientLightPosition0[] = {3.0, 6.0, 5.0, 0.0};
  • GLfloat LightAmbient0[] = {1.0, 1.0, 1.0, 1.0};
  • GLfloat AmbientLightPosition1[] = {-3.0, 6.0, 5.0, 0.0};
  • GLfloat LightAmbient1[] = {1.0, 1.0, 1.0, 1.0};
  • GLfloat AmbientLightPosition2[] = {3.0,6.0, -5.0, 0.0};
  • GLfloat LightAmbient2[] = {1.0, 1.0, 1.0, 1.0};
  • GLfloat AmbientLightPosition3[] = {-3.0, 6.0, -5.0, 0.0};
  • GLfloat LightAmbient3[] = {1.0, 1.0, 1.0, 1.0};
  • glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
  • glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
  • glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
  • glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);
  • glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition0);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0);
  • glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition1);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient1);
  • glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition2);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient2);
  • glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition3);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient3);
  • glEnable(GL_LIGHTING);
  • glEnable(GL_LIGHT0);
  • glEnable(GL_LIGHT1);
  • glEnable(GL_LIGHT2);
  • glEnable(GL_LIGHT3);
  • glEnable(GL_COLOR_MATERIAL);
  • glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  • glShadeModel(GL_SMOOTH);
  • }
  • //---------------------------------------------------------------------------
  • ////////////////////////creation de la scene//////////////////
  • //---------------------------------------------------------------------------
  • /////////////////////////
  • //==========================================================================
  • // RECHERCHE DU CHEMIN
  • //===========================================================================
  • //+++++++++++++++++++++++++++++FONCTIONS POUR LES PILES++++++++++++++++++++++
  • void empiler(cellule pile[nbcelI*nbcelJ],cellule element,int *indice)
  • {
  • (*indice)++;
  • pile[*indice]=element;
  • }
  • //------------------------------------------------------------------------
  • cellule depiler(cellule pile[nbcelI*nbcelJ],int *indice)
  • { cellule cel3;
  • cel3=pile[*indice];
  • (*indice)--;
  • return(cel3);
  • }
  • //------------------------------------------------------------------------
  • bool pile_vide(cellule pile[nbcelI*nbcelJ],int indice)
  • {
  • if(indice==-1)
  • return(true);
  • else
  • return(false);
  • }
  • //------------------------------------------------------------------------
  • trier_la_pile_des_visites()
  • { //???????????????????
  • cellule element;
  • for(int i=indicev;i>=0;i--)
  • {
  • if(pile_des_visites[i].F<pile_des_visites[indicev].F)
  • {
  • element=pile_des_visites[indicev];
  • pile_des_visites[indicev]=pile_des_visites[i];
  • pile_des_visites[i]=element;
  • }
  • }
  • }
  • //------------------------------------------------------------------------
  • int exist_dans_pile(cellule pile[nbcelI*nbcelJ],cellule element,int indice)
  • {
  • for(int i=0;i<=indice;i++)
  • if(element.ID.I==pile[i].ID.I&&element.ID.J==pile[i].ID.J)
  • return i; //l'element existe dans la pile et on retourne son emplecement
  • return(-1); //l'element n'existe pas
  • }
  • //+++++++++++++++++++++++++++++CALCULE DES COUTS DES CHEMINS ET TESTS ++++++++++++++++++++++++++++
  • int calcule_de_H(cellule element)
  • { int n;
  • n=(abs(but.ID.I-element.ID.I)+abs(but.ID.J-element.ID.J))*10;
  • return(n);
  • }
  • //---------------------------------------------------------------------------
  • int teste_adjacente(cellule celadj)
  • {
  • int i,j;
  • //cellule elem1,elem2,elem3,elem4;
  • i=celadj.ID.I;
  • j=celadj.ID.J;
  • cellule elem1=matENV[i-1][j];
  • cellule elem2=matENV[i+1][j];
  • cellule elem3=matENV[i][j-1];
  • cellule elem4=matENV[i][j+1];
  • if(elem1.L==1||elem2.L==1)
  • return 0;
  • return 1;
  • }
  • //-----------------------------------------------------------------------------------------
  • bool cellule_limite(cellule celcour)
  • { if(celcour.ID.I==0||celcour.ID.I==nbcelI-1||celcour.ID.J==0||celcour.ID.J==nbcelJ-1) //je doit ajouter le teste si la cellule est en 0,0........
  • return true;
  • else
  • return false;
  • }
  • //------------------------------------------------------------------------------------------
  • traitement_cellule(int type,cellule celadj,cellule celcour)
  • { int pos;
  • if(celadj.L==0)
  • {
  • if(exist_dans_pile(pile_finale,celadj,indicef)==(-1))
  • {
  • if(pos=exist_dans_pile(pile_des_visites,celadj,indicev)==(-1))
  • {
  • celadj.pere=celcour.ID;
  • if(type==D&&teste_adjacente(celadj)==1)
  • //if(teste_adjacente(celadj)==1)
  • {
  • celadj.G=celcour.G+14;
  • celadj.H=calcule_de_H(celadj);
  • celadj.F=celadj.H+celadj.G;
  • empiler(pile_des_visites,celadj,&indicev);
  • }
  • if(type==HV)
  • {
  • celadj.G=celcour.G+10;
  • celadj.H=calcule_de_H(celadj);
  • celadj.F=celadj.H+celadj.G;
  • empiler(pile_des_visites,celadj,&indicev);
  • }
  • }
  • else //l'element existe dans la pile des visité
  • {
  • if(type==HV)
  • {
  • if(celcour.G+10<celadj.G)
  • {
  • celadj.G=celcour.G+10;
  • celadj.F=celadj.G+celadj.H;
  • celadj.pere=celcour.ID;
  • pile_des_visites[pos]=celadj;
  • }
  • }
  • else //type ==D "diagonale"
  • {
  • if(celcour.G+14<celadj.G)
  • {
  • celadj.G=celcour.G+14;
  • celadj.F=celadj.G+celadj.H;
  • celadj.pere=celcour.ID;
  • pile_des_visites[pos]=celadj;
  • }
  • }
  • }
  • }
  • }
  • }
  • //------------------------------------------------------------------------------------------
  • recherch_cases_valide(cellule celcour)
  • { int i=celcour.ID.I;
  • int j=celcour.ID.J;
  • cellule cel1,cel2,cel3;
  • if(!cellule_limite(celcour)) // la cellule n'est une cellule limite
  • { matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • traitement_cellule(HV,matENV[i][j-1],celcour);
  • matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • traitement_cellule(HV,matENV[i][j+1],celcour);
  • matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i-1][j],celcour);
  • matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i+1][j],celcour);
  • matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i+1][j-1],celcour);
  • matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i-1][j-1],celcour);
  • matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i+1][j+1],celcour);
  • matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i-1][j+1],celcour);
  • }
  • else
  • {
  • switch (i)
  • {
  • case 0: matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • traitement_cellule(HV,matENV[i][j-1],celcour);
  • matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • traitement_cellule(HV,matENV[i][j+1],celcour);
  • matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i+1][j],celcour);
  • matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i+1][j-1],celcour);
  • matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i+1][j+1],celcour);
  • break;
  • case nbcelI-1: matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • traitement_cellule(HV,matENV[i][j-1],celcour);
  • matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • traitement_cellule(HV,matENV[i][j+1],celcour);
  • matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i-1][j],celcour);
  • matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i-1][j-1],celcour);
  • matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i-1][j+1],celcour);
  • break;
  • }
  • switch (j)
  • {
  • case 0: matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i-1][j],celcour);
  • matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i+1][j],celcour);
  • matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • traitement_cellule(HV,matENV[i][j+1],celcour);
  • matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i+1][j+1],celcour);
  • matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • traitement_cellule(D,matENV[i-1][j+1],celcour);
  • break;
  • case nbcelJ-1: matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i-1][j],celcour);
  • matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • traitement_cellule(HV,matENV[i+1][j],celcour);
  • matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • traitement_cellule(HV,matENV[i][j-1],celcour);
  • matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i+1][j-1],celcour);
  • matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • traitement_cellule(D,matENV[i-1][j-1],celcour);
  • break;
  • }
  • }
  • }
  • //----------------------------------------------------------------------------------------------
  • bool recherche_chemin(coordonne d,coordonne b)
  • { cellule cel;
  • indicev=indicef=-1;
  • but.ID=b;
  • bool resultat=false;
  • empiler(pile_des_visites,matENV[d.I][d.J],&indicev);
  • while(!resultat)
  • {
  • cel=pile_des_visites[indicev];
  • if(cel.ID.I==b.I&&cel.ID.J==b.J) //la cellule est cel du but
  • {
  • empiler(pile_finale,depiler(pile_des_visites,&indicev),&indicef);
  • resultat=true;
  • return resultat;
  • }
  • else
  • {
  • if(!pile_vide(pile_des_visites,indicev)) //la pile des visite n'est pas vide
  • {
  • empiler(pile_finale,depiler(pile_des_visites,&indicev),&indicef);
  • recherch_cases_valide(cel);
  • trier_la_pile_des_visites();
  • }
  • else
  • return false;
  • }
  • }
  • }
  • //---------------------------------------------------------------------------
  • void back_to_home() //tous les individus cherchent leur chemin
  • {
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • bool found=recherche_chemin(monde[i].start,monde[i].goal);
  • if(found)
  • {
  • extraire_chemin(i);
  • monde[i].butaccessible=true;
  • monde[i].position=monde[i].start;
  • }
  • else
  • monde[i].butaccessible=false;
  • }
  • aller=true;
  • }
  • ////////////////////////////////////////////////////
  • void back_to_home1() //tous les individus cherchent leur chemin
  • {
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • bool found=recherche_chemin(monde[i].start,monde[i].goal);
  • if(found)
  • {
  • extraire_chemin(i);
  • monde[i].butaccessible=true;
  • monde[i].position=monde[i].start;
  • }
  • else
  • monde[i].butaccessible=false;
  • }
  • aller=true;
  • }
  • //---------------------------------------------------------------------------
  • extraire_chemin(int ind)
  • {
  • coordonne inter[3000],interm;
  • cellule element,ident;
  • int pos=0,c=0,i=indicef;
  • bool trouve=false;
  • element=pile_finale[indicef];
  • inter[c++]=pile_finale[indicef].ID;
  • while(!trouve)
  • {
  • ident.ID=element.pere;
  • pos=exist_dans_pile(pile_finale,ident,indicef);
  • element=pile_finale[pos];
  • inter[c++]=element.ID;
  • if(element.ID.I==monde[ind].start.I&&element.ID.J==monde[ind].start.J)
  • trouve=true;
  • nbcel=c;
  • }
  • monde[ind].longueurchemin=c;
  • monde[ind].parser=0;
  • //inverser et copier dans le tableau chemin
  • for(int i=0;i<nbcel;i++)
  • {
  • monde[ind].chemin[i]=inter[--c];
  • }
  • }
  • //---------------------------------------------------------------------------
  • float direction(int i)
  • {
  • int proch=0;
  • switch (monde[i].position.I-monde[i].chemin[i].I)
  • {
  • case 1: if(monde[i].position.J-monde[i].chemin[i].J == 0)proch=3;
  • if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=2;
  • if(monde[i].position.J-monde[i].chemin[i].J ==-1)proch=4;
  • break;
  • case 0:
  • if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=1;
  • else proch=5;
  • break;
  • case -1: if(monde[i].position.J-monde[i].chemin[i].J == 0)proch=7;
  • if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=8;
  • if(monde[i].position.J-monde[i].chemin[i].J == -1)proch=6;
  • break;
  • }
  • return(45 *(proch-monde[i].direction));
  • }
  • //===========================================================================
  • //FIN RECHERCHE DU CHEMIN
  • //===========================================================================
  • //-FONCTION DE DEPLACEMENT D'INDIVIDU------------------------------------------------------
  • void TFormMain::se_deplacer()
  • {
  • //ici d'abord on fait un appel a la procedure de perception
  • for(int i=1;i<=nbmaxind;i++) //tous les individus sont supposé en mouvement sauf s'il y aura une action de bloquer qlq'1
  • {
  • monde[i].action=move;
  • matENV[monde[i].position.I][monde[i].position.J].L=0;
  • // e->matENV[monde[i].position.I][monde[i].position.J].L=0;
  • monde[i].lieu=matENV[monde[i].position.I][monde[i].position.J].lieu;
  • }
  • trouver_zone_securite(); //perception
  • recherche_collision(); //perception decision action
  • //nettoyer la matENV des traces d'individus
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • if(!monde[i].chez_lui&&monde[i].butaccessible&&monde[i].action==move)
  • {
  • if(monde[i].longueurchemin==monde[i].parser+1)
  • monde[i].chez_lui=true;
  • else
  • monde[i].parser++;
  • point p;
  • monde[i].angle=direction(i);
  • matENV[monde[i].position.I][monde[i].position.J].L=2;
  • pospi[i].I= monde[i].position.I;
  • pospj[i].J= monde[i].position.J;
  • e->matENV[monde[i].position.I][monde[i].position.J].L=2;
  • }
  • }
  • }
  • //==============================================================================================
  • //==============================================================================================
  • void trouver_zone_securite()
  • {
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • if(!monde[i].chez_lui&&monde[i].butaccessible)
  • {
  • monde[i].position=monde[i].chemin[monde[i].parser];
  • if(monde[i].parser+1==monde[i].longueurchemin) //but attein
  • {
  • monde[i].zone_securite[0].I=-1;
  • monde[i].zone_securite[0].J=-1;
  • monde[i].zone_securite[1].I=-1;
  • monde[i].zone_securite[1].J=-1;
  • }
  • else
  • {
  • if(monde[i].parser+2==monde[i].longueurchemin)
  • {
  • monde[i].zone_securite[0]=monde[i].chemin[monde[i].parser+1];
  • monde[i].zone_securite[1].I=-1;
  • monde[i].zone_securite[1].J=-1;
  • }
  • else
  • {
  • monde[i].zone_securite[0]=monde[i].chemin[monde[i].parser+1];
  • monde[i].zone_securite[1]=monde[i].chemin[monde[i].parser+2];
  • }
  • }
  • }
  • }
  • }
  • //==========================================================================================
  • //RECHERCHE DES COLLISIONS POSSIBLE
  • //==========================================================================================
  • void recherche_collision()
  • { int num_tab;
  • for(int i=0;i<=nb_tab;i++)
  • tab_pieton_coll[i].taille_tab=0;
  • nb_tab=0;
  • for(int ind1=1;ind1<=nbmaxind;ind1++)
  • {
  • for(int ind2=ind1;ind2<=nbmaxind;ind2++)
  • {
  • if(ind1!=ind2&&!(monde[ind1].chez_lui||monde[ind2].chez_lui)) //j'aurai un pb ici car l'affectation des valeur de chez lui se fait avant cette operation donc" je doit la reviser
  • {
  • bool collision=false;
  • if((monde[ind1].position.I==monde[ind2].zone_securite[0].I&&monde[ind1].position.J==monde[ind2].zone_securite[0].J)||(monde[ind1].position.I==monde[ind2].zone_securite[1].I&&monde[ind1].position.J==monde[ind2].zone_securite[1].J)||(monde[ind1].position.I==monde[ind2].position.I&&monde[ind1].position.J==monde[ind2].position.J))
  • collision=true;
  • if((monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].position.I&&monde[ind1].zone_securite[0].J==monde[ind2].position.J))
  • collision=true;
  • if((monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].position.I&&monde[ind1].zone_securite[1].J==monde[ind2].position.J))
  • collision=true;
  • if(collision) //il ya une collision
  • {
  • //traitement_collision(ind1,ind2);//??????????????????
  • num_tab=recherche_tab_pieton(ind1);
  • if(num_tab!=0)
  • inserer_pietons(ind1,ind2,num_tab);
  • else
  • {
  • num_tab=recherche_tab_pieton(ind2);
  • if(num_tab!=0)
  • inserer_pietons(ind1,ind2,num_tab);
  • else
  • {
  • nb_tab++;
  • num_tab=nb_tab;
  • inserer_pietons(ind1,ind2,num_tab);
  • }
  • }
  • }
  • }
  • }
  • }
  • for(int i=1;i<=nb_tab;i++)
  • {
  • if(tab_pieton_coll[i].taille_tab==1)
  • {
  • traitement_collision(tab_pieton_coll[i].tab_pair_collision[1].pieton1,tab_pieton_coll[i].tab_pair_collision[1].pieton2);
  • }
  • }
  • for(int i=1;i<=nb_tab;i++)
  • {
  • if(tab_pieton_coll[i].taille_tab!=1)
  • {
  • for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
  • {
  • individus indiv1=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton1];
  • individus indiv2=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton2];
  • int Tcoll=type_collision(indiv1,indiv2);
  • if(Tcoll==blocage)
  • traitement_collision(tab_pieton_coll[i].tab_pair_collision[j].pieton1,tab_pieton_coll[i].tab_pair_collision[j].pieton2);
  • }
  • }
  • }
  • for(int i=1;i<=nb_tab;i++)
  • {
  • if(tab_pieton_coll[i].taille_tab!=1)
  • {
  • for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
  • {
  • individus indiv1=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton1];
  • individus indiv2=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton2];
  • int Tcoll=type_collision(indiv1,indiv2);
  • if(Tcoll!=blocage)
  • traitement_collision(tab_pieton_coll[i].tab_pair_collision[j].pieton1,tab_pieton_coll[i].tab_pair_collision[j].pieton2);
  • }
  • }
  • }
  • }
  • //=============================================================================================
  • bool rec_col(int ind1,int ind2)
  • { bool col;
  • if(ind1!=ind2&&!(monde[ind1].chez_lui||monde[ind2].chez_lui)) //j'aurai un pb ici car l'affectation des valeur de chez lui se fait avant cette operation donc" je doit la reviser
  • {
  • if((monde[ind1].position.I==monde[ind2].zone_securite[0].I&&monde[ind1].position.J==monde[ind2].zone_securite[0].J)||(monde[ind1].position.I==monde[ind2].zone_securite[1].I&&monde[ind1].position.J==monde[ind2].zone_securite[1].J)||(monde[ind1].position.I==monde[ind2].position.I&&monde[ind1].position.J==monde[ind2].position.J))
  • col=true;
  • if((monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].position.I&&monde[ind1].zone_securite[0].J==monde[ind2].position.J))
  • col=true;
  • if((monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].position.I&&monde[ind1].zone_securite[1].J==monde[ind2].position.J))
  • col=true;
  • if(col) //il ya une collision
  • {
  • return true;
  • }
  • }
  • }
  • //=============================================================================================
  • //TRAITEMENT DES COLLISIONS
  • //=============================================================================================
  • void traitement_collision(int ind1,int ind2)
  • {
  • int i,pmoins,pplus;
  • coordonne celcomp;
  • monde[ind1].direction=ma_direction(monde[ind1]);
  • monde[ind2].direction=ma_direction(monde[ind2]);
  • individus indiv1=monde[ind1];
  • individus indiv2=monde[ind2];
  • if(monde[ind1].priorite>=monde[ind2].priorite) {pplus=ind1; pmoins=ind2;}
  • else {pplus=ind2;pmoins=ind1;}
  • int Tcoll=type_collision(indiv1,indiv2);
  • switch(Tcoll)
  • {
  • case confrontation:
  • celcomp=droite_ou_gauche(monde[pmoins]);
  • if(celcomp.I==-1&&celcomp.J==-1||monde[pmoins].action==arrest)//le moins prioritaire ne peut pas bouger ou il est bloquer
  • {
  • //on essay avec le plus prioritaire
  • celcomp=droite_ou_gauche(monde[pplus]);
  • if(celcomp.I==-1&&celcomp.J==-1) //le plus prioritaire ne peut pas bouger aussi
  • {
  • //reculer le moin prioritaire
  • monde[pmoins].parser=monde[pmoins].parser-2;
  • monde[pmoins].position=monde[pmoins].chemin[monde[pmoins].parser];
  • }
  • else //le plus prioritaire peut bouger er le moins prioritairte ne peut pas
  • { if(monde[pplus].action!=arrest)
  • {
  • coordonne c=monde[pplus].start;
  • monde[pplus].start=celcomp;
  • recherche_chemin(monde[pplus].start,monde[pplus].goal);
  • extraire_chemin(pplus);
  • monde[pplus].position=monde[pplus].chemin[monde[pplus].parser];
  • monde[pplus].parser--;
  • monde[pplus].start=c;
  • }
  • }
  • }
  • else // le moin prioritaire peut bouger)
  • {
  • coordonne c=monde[pmoins].start;
  • monde[pmoins].start=celcomp;
  • recherche_chemin(monde[pmoins].start,monde[pmoins].goal);
  • extraire_chemin(pmoins);
  • monde[pmoins].position=monde[pmoins].chemin[monde[pmoins].parser];
  • monde[pmoins].parser;
  • monde[pmoins].start=c;
  • }
  • break;
  • case perpendicularite:
  • if(monde[pplus].action!=arrest)//si le plus prioritaire n'est pas bloqué
  • bloquer(pmoins);
  • break;
  • case blocage: if(monde[ind1].direction==NORD)
  • if(monde[ind1].position.I<=monde[ind2].position.I) bloquer(ind1);
  • //else bloquer(ind2);
  • if(monde[ind1].direction==SUD)
  • if(monde[ind1].position.I<=monde[ind2].position.I) bloquer(ind2);
  • //else bloquer(ind1);
  • if(monde[ind1].direction==EST)
  • if(monde[ind1].position.J<=monde[ind2].position.I) bloquer(ind1);
  • //else bloquer(ind2);
  • if(monde[ind1].direction==OUEST)
  • if(monde[ind1].position.I<=monde[ind2].position.I) bloquer(ind1);
  • //else bloquer(ind2);
  • if(monde[ind1].direction==TDN||monde[ind1].direction==TGN)
  • if(monde[ind1].position.I<=monde[ind2].position.I) bloquer(ind1);
  • //else bloquer(ind2);
  • if(monde[ind1].direction==TDS||monde[ind1].direction==TGS)
  • if(monde[ind1].position.I<=monde[ind2].position.I) bloquer(ind2);
  • //else bloquer(ind1);
  • if(monde[ind1].direction==TDE||monde[ind1].direction==TGE)
  • if(monde[ind1].position.J<=monde[ind2].position.J) bloquer(ind1);
  • //else bloquer(ind2);
  • if(monde[ind1].direction==TDO||monde[ind1].direction==TGO)
  • if(monde[ind1].position.J<=monde[ind2].position.J) bloquer(ind2);
  • //else bloquer(ind1);
  • break;
  • }
  • }
  • //=====================================================================================================
  • int ma_direction(individus indiv) // quel est la direction du piéton EST ou OUEST........
  • {
  • if(indiv.position.I==indiv.zone_securite[0].I&&indiv.position.I==indiv.zone_securite[1].I)//horizontale
  • {
  • if(indiv.position.J<indiv.zone_securite[0].J&&indiv.zone_securite[0].J<indiv.zone_securite[1].J)
  • return(EST);
  • else
  • return(OUEST);
  • }
  • else
  • {
  • if(indiv.position.J==indiv.zone_securite[0].J&&indiv.position.J==indiv.zone_securite[1].J)//verticale
  • if(indiv.position.I<indiv.zone_securite[0].I&&indiv.zone_securite[0].I<indiv.zone_securite[1].I)
  • return(NORD);
  • else
  • return(SUD);
  • else //ni horizontale ni verticale
  • if(indiv.position.I<indiv.zone_securite[1].I) //vers le nord
  • if(indiv.position.J<indiv.zone_securite[1].J)
  • if(indiv.position.I==indiv.zone_securite[0].I)
  • return(TGN);
  • else
  • return(TDE); // indiv.zone_securite[0].I==indiv.zone_securite[1].I
  • else
  • if(indiv.position.I==indiv.zone_securite[0].I)
  • return(TDN);
  • else
  • return(TGO);
  • else
  • if(indiv.position.J<indiv.zone_securite[1].J) //tourner vers le sud
  • if(indiv.position.I==indiv.zone_securite[0].I)
  • return(TGS);
  • else
  • return(TGE);
  • else
  • if(indiv.position.I==indiv.zone_securite[0].I)
  • return(TDS);
  • else
  • return(TDO);
  • }
  • }
  • //============================================================================================
  • void bloquer(int i)
  • {
  • monde[i].action=arrest;
  • }
  • //============================================================================================
  • coordonne droite_ou_gauche(individus indiv) // rendre la case libre adjacente ; retourner la drote si elle est libre sinon la gauche
  • {
  • coordonne Case;
  • int i=indiv.position.I;
  • int j=indiv.position.J;
  • switch(indiv.direction)
  • {
  • case NORD: if(matENV[i][j+1].L==0)
  • { matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • return(matENV[i][j+1].ID); //droite
  • }
  • else
  • {
  • if(matENV[i+1][j+1].L==0)
  • {
  • matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • return(matENV[i+1][j+1].ID); //droite diagonnale
  • }
  • else
  • if(matENV[i][j-1].L==0) //gauche
  • { matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • return(matENV[i][j-1].ID);
  • }
  • else
  • if(matENV[i+1][j-1].L==0) //gauche diagonnale
  • { matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • return (matENV[i+1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • }
  • break;
  • case SUD: if(matENV[i][j-1].L==0)
  • { matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • return(matENV[i][j-1].ID); //droite
  • }
  • else
  • {
  • if(matENV[i-1][j-1].L==0)
  • { matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • return(matENV[i-1][j-1].ID); //droite diagonnale
  • }
  • else
  • if(matENV[i][j+1].L==0) //gauche
  • { matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • return(matENV[i][j+1].ID);
  • }
  • else
  • if(matENV[i-1][j+1].L==0) //gauche diagonnale
  • { matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • return (matENV[i-1][j+1].ID);
  • }
  • else
  • { Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • }
  • break;
  • case EST: if(matENV[i-1][j].L==0)
  • { matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • return(matENV[i-1][j].ID); //droite
  • }
  • else
  • {
  • if(matENV[i-1][j+1].L==0)
  • { matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • return(matENV[i-1][j+1].ID); //droite diagonnale
  • }
  • else
  • if(matENV[i+1][j].L==0) //gauche
  • { matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • return(matENV[i+1][j].ID);
  • }
  • else
  • if(matENV[i+1][j+1].L==0) //gauche diagonnale
  • { matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • return (matENV[i+1][j+1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • }
  • break;
  • case OUEST: if(matENV[i+1][j].L==0)
  • { matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • return(matENV[i+1][j].ID); //droite
  • }
  • else
  • {
  • if(matENV[i+1][j-1].L==0)
  • { matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • return(matENV[i+1][j-1].ID); //droite diagonnale
  • }
  • else
  • if(matENV[i-1][j].L==0) //gauche
  • { matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • return(matENV[i-1][j].ID);
  • }
  • else
  • if(matENV[i-1][j-1].L==0) //gauche diagonnale
  • { matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • return (matENV[i-1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • }
  • break;
  • case TDN: if(matENV[i+1][j].L==0)
  • { matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • return(matENV[i+1][j].ID);
  • }
  • else
  • if(matENV[i+1][j+1].L==0)
  • { matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • return(matENV[i+1][j+1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TGN: if(matENV[i+1][j].L==0)
  • { matENV[i+1][j].ID.I=i+1;
  • matENV[i+1][j].ID.J=j;
  • return(matENV[i+1][j].ID);
  • }
  • else
  • if(matENV[i+1][j-1].L==0)
  • { matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • return(matENV[i+1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TDS: if(matENV[i-1][j].L==0)
  • { matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • return(matENV[i-1][j].ID);
  • }
  • else
  • if(matENV[i-1][j-1].L==0)
  • { matENV[i-1][j-1].ID.I=i-1;
  • matENV[i-1][j-1].ID.J=j-1;
  • return(matENV[i-1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TGS: if(matENV[i-1][j].L==0)
  • { matENV[i-1][j].ID.I=i-1;
  • matENV[i-1][j].ID.J=j;
  • return(matENV[i-1][j].ID);
  • }
  • else
  • if(matENV[i-1][j+1].L==0)
  • { matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • return(matENV[i-1][j+1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TDE: if(matENV[i][j+1].L==0)
  • { matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • return(matENV[i][j+1].ID);
  • }
  • else
  • if(matENV[i-1][j+1].L==0)
  • { matENV[i-1][j+1].ID.I=i-1;
  • matENV[i-1][j+1].ID.J=j+1;
  • return(matENV[i-1][j+1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TGE: if(matENV[i][j+1].L==0)
  • { matENV[i][j+1].ID.I=i;
  • matENV[i][j+1].ID.J=j+1;
  • return(matENV[i][j+1].ID);
  • }
  • else
  • if(matENV[i+1][j+1].L==0)
  • { matENV[i+1][j+1].ID.I=i+1;
  • matENV[i+1][j+1].ID.J=j+1;
  • return(matENV[i+1][j+1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TDO: if(matENV[i][j-1].L==0)
  • { matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • return(matENV[i][j-1].ID);
  • }
  • else
  • if(matENV[i+1][j-1].L==0)
  • { matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • return(matENV[i+1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • case TGO: if(matENV[i][j-1].L==0)
  • { matENV[i][j-1].ID.I=i;
  • matENV[i][j-1].ID.J=j-1;
  • return(matENV[i][j-1].ID);
  • }
  • else
  • if(matENV[i+1][j-1].L==0)
  • { matENV[i+1][j-1].ID.I=i+1;
  • matENV[i+1][j-1].ID.J=j-1;
  • return(matENV[i+1][j-1].ID);
  • }
  • else
  • {
  • Case.I=-1;Case.J=-1;
  • return(Case);
  • }
  • break;
  • }
  • }
  • //----------------------------------------------------------------------------------------------
  • int type_collision(individus indiv1,individus indiv2)
  • {
  • if(indiv1.direction==indiv2.direction)
  • return(blocage);
  • switch(indiv1.direction)
  • {
  • case NORD:switch(indiv2.direction){
  • case NORD: return(blocage);
  • break;
  • case SUD: return(confrontation);
  • break;
  • default : return(perpendicularite);
  • break;
  • }
  • break;
  • case SUD: switch(indiv2.direction){
  • case NORD: return(confrontation);
  • break;
  • case SUD: return(blocage);
  • break;
  • default : return(perpendicularite);
  • break;
  • }
  • break;
  • case EST: switch(indiv2.direction){
  • case OUEST: return(confrontation);
  • break;
  • case EST: return(blocage);
  • break;
  • default : return(perpendicularite);
  • break;
  • }
  • break;
  • case OUEST:switch(indiv2.direction){
  • case EST: return(confrontation);
  • break;
  • case OUEST: return(blocage);
  • break;
  • default : return(perpendicularite);
  • break;
  • }
  • break;
  • default: return(perpendicularite);
  • break;
  • }
  • }
  • //============================================================================================================
  • int recherche_tab_pieton(int pieton)
  • {
  • for(int i=1;i<=nb_tab;i++)
  • for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
  • {
  • if(tab_pieton_coll[i].tab_pair_collision[j].pieton1==pieton||tab_pieton_coll[i].tab_pair_collision[j].pieton2==pieton)
  • return (i); //retourne le numero de tableau
  • }
  • return 0; // le pieton n'existe pas
  • }
  • //---------------------------------------------------------------------------------------
  • void inserer_pietons(int p1,int p2,int num)
  • {
  • tab_pieton_coll[num].taille_tab++;
  • tab_pieton_coll[num].tab_pair_collision[tab_pieton_coll[num].taille_tab].pieton1=p1;
  • tab_pieton_coll[num].tab_pair_collision[tab_pieton_coll[num].taille_tab].pieton2=p2;
  • }
  • //---------------------------------------------------------------------------
  • //=========================================================================================//
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::SceneClick(TObject *Sender)
  • {
  • //indiv->Enabled=true;
  • individus->Enabled=true;
  • Reinit->Enabled=true;
  • vu2d->Enabled=true;
  • V2D->Enabled=true;
  • vu3d->Enabled=true;
  • V3D->Enabled=true;
  • init->Enabled=true;
  • e=new evrm;
  • e->set_taille(40,60);
  • e->init();
  • Scene->Checked=true;
  • //Timer3 ->Enabled=true;
  • }
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::QuitterClick(TObject *Sender)
  • {
  • // a->bs.m_a_j_f(a->bs.type) ;
  • Close();
  • }
  • //////////////////////////////////////
  • void __fastcall TFormMain::individusClick(TObject *Sender)
  • {
  • if(Scene->Checked)
  • individus->Down=true;
  • // a=new agent(e);
  • agt_dess=true;
  • //indiv->Enabled=false;
  • //individus->Enabled=false;
  • Reinit->Enabled=true;
  • /*
  • a=new agent(e);
  • agt_dess=true;
  • supp_agn->Enabled=true;
  • s_agent->Enabled=true;
  • Ajou_agn->Enabled=false;
  • a_agent->Enabled=false;
  • Reinit->Enabled=true;
  • l_anim->Enabled=true;
  • p_anim->Enabled=true;
  • a_anim->Enabled=true;
  • Lancer1->Enabled=true;
  • Pause1->Enabled=true;
  • Arreter1->Enabled=true;*/
  • }
  • ///////////////////////////////////////
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::indivClick(TObject *Sender)
  • {
  • //individus->Click();
  • /*if(Scene->Checked)
  • indiv->Checked=true;
  • // a=new agent(e);
  • //agt_dess=true;
  • indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;*/
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::supp_agnClick(TObject *Sender)
  • {
  • if(Scene->Enabled==false)
  • Scene->Enabled=true;
  • //a->clean();
  • //free(a);
  • agt=false;
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • if(V2D->Checked)
  • {
  • indiv->Enabled=true;
  • individus->Enabled=true;
  • }
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • /////////////////////////////////////////////////:
  • void __fastcall TFormMain::ReinitClick(TObject *Sender)
  • {
  • Scene->Enabled=true;
  • Timer1->Enabled=false;
  • Timer2->Enabled=false;
  • free(e);
  • //free(a);
  • Scene->Checked=false;
  • agt=false;
  • //
  • // supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • //indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • vu2d->Enabled=false;
  • V2D->Enabled=false;
  • vu3d->Enabled=false;
  • V3D->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::V2DClick(TObject *Sender)
  • {
  • indiv->Enabled=true;
  • individus->Enabled=true;
  • V2D->Checked=true ;
  • V3D->Checked=false ;
  • v2d=true ;
  • v3d=false ;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::V3DClick(TObject *Sender)
  • {
  • indiv->Enabled=false;
  • individus->Enabled=false;
  • V3D->Checked=true ;
  • V2D->Checked=false ;
  • vu2d->Enabled=true;
  • vu3d->Enabled=false;
  • v3d=true ;
  • v2d=false ;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Timer1Timer(TObject *Sender)
  • {
  • if(aller)
  • {
  • se_deplacer();
  • }
  • //FormMain->DrawObjects();
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::AnimClick(TObject *Sender)
  • {
  • //Timer1->Enabled=true;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Lancer1Click(TObject *Sender)
  • {
  • initial_matENV();
  • individus-> Down=false;
  • indicev=indicef=-1;
  • if(nbmaxind)
  • {
  • if(!pause)
  • {
  • for(int i=1;i<=nbmaxind;i++)
  • {
  • monde[i].position.I = monde[i].start.I ;
  • monde[i].position.J = monde[i].start.J ;
  • monde[i].chez_lui=false;
  • }
  • back_to_home();
  • Timer1->Enabled=true;
  • }
  • }
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Pause1Click(TObject *Sender)
  • {
  • Timer1->Enabled=false;
  • //Timer2->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Arreter1Click(TObject *Sender)
  • {
  • Timer1->Enabled=false;
  • //Timer2->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::initClick(TObject *Sender)
  • {
  • Timer1->Enabled=false;
  • Timer2->Enabled=false;
  • free(e);
  • //free(a);
  • Scene->Checked=false;
  • agt=false;
  • //
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • //indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • vu2d->Enabled=false;
  • V2D->Enabled=false;
  • vu3d->Enabled=false;
  • V3D->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::s_agentClick(TObject *Sender)
  • {
  • //s_agent->Down=true;
  • if(Scene->Enabled==false)
  • Scene->Enabled=true;
  • //a ->clean();
  • //free(a);
  • agt=false;
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • if(V2D->Checked)
  • {
  • //indiv->Enabled=true;
  • individus->Enabled=true;
  • }
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • //agt_dess=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::l_animClick(TObject *Sender)
  • {
  • Timer1->Enabled=true;
  • Timer2->Enabled=true;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::p_animClick(TObject *Sender)
  • {
  • Timer1->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::a_animClick(TObject *Sender)
  • {
  • Timer1->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::vu2dClick(TObject *Sender)
  • {
  • indiv->Enabled=true;
  • individus->Enabled=true;
  • V2D->Checked=true ;
  • V3D->Checked=false ;
  • vu2d->Enabled=false;
  • vu3d->Enabled=true;
  • v2d=true ;
  • v3d=false ;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::vu3dClick(TObject *Sender)
  • {
  • indiv->Enabled=false;
  • individus->Enabled=false;
  • V3D->Checked=true ;
  • V2D->Checked=false ;
  • vu2d->Enabled=true;
  • vu3d->Enabled=false;
  • v3d=true ;
  • v2d=false ;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Timer3Timer(TObject *Sender)
  • {
  • Timer3->Enabled=false;
  • //int r= Application->MessageBox("Vous voulez continuer ?","Test d'acceptation", MB_YESNO);
  • //if(r==IDNO)
  • //{
  • //free(e);
  • //free(a);
  • //Scene->Checked=false;
  • agt=false;
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • //indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • vu2d->Enabled=false;
  • V2D->Enabled=false;
  • vu3d->Enabled=false;
  • V3D->Enabled=false;
  • //}
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Timer4Timer(TObject *Sender)
  • {
  • Timer4->Enabled=false;
  • Timer1->Enabled=false;
  • Timer2->Enabled=false;
  • free(e);
  • //free(a);
  • Scene->Checked=false;
  • Scene->Enabled=true;
  • agt=false;
  • //
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • vu2d->Enabled=false;
  • V2D->Enabled=false;
  • vu3d->Enabled=false;
  • V3D->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::RienitClick(TObject *Sender)
  • {
  • Scene->Enabled=true;
  • Timer1->Enabled=false;
  • Timer2->Enabled=false;
  • free(e);
  • //free(a);
  • Scene->Checked=false;
  • agt=false;
  • //
  • individus->Down=false;
  • //supp_agn->Enabled=false;
  • //s_agent->Enabled=false;
  • //indiv->Enabled=false;
  • individus->Enabled=false;
  • Reinit->Enabled=true;
  • //l_anim->Enabled=false;
  • //p_anim->Enabled=false;
  • dem->Enabled=false;
  • //a_anim->Enabled=false;
  • //Lancer1->Enabled=false;
  • //Pause1->Enabled=false;
  • //Arreter1->Enabled=false;
  • //Evenement_de_panique1->Enabled=false;
  • vu2d->Enabled=false;
  • V2D->Enabled=false;
  • vu3d->Enabled=false;
  • V3D->Enabled=false;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::Panel1MouseDown(TObject *Sender,
  • TMouseButton Button, TShiftState Shift, int X, int Y)
  • {
  • int ixpos,iypos;
  • GLfloat r1 = (20.0 / Panel1->Width);
  • GLfloat r2 = (20.0 / Panel1->Height);
  • GLfloat r, W;
  • // point p;
  • if(agt_dess )
  • {
  • if (r1 < r2)
  • {
  • r = r2;
  • W = Panel1->Height;
  • }
  • else
  • {
  • r = r1;
  • W = Panel1->Width;
  • }
  • Xpos = ((X - W / 2.0) * r)+((e->col)/4.0)-3.5 ;
  • Ypos = ((Y- W / 2.0 ) * r)+((e->lig)/4);;
  • ixpos=Xpos-int(Xpos);
  • if(ixpos>0.5)
  • Xpos=int(Xpos)+1;
  • else
  • Xpos=int(Xpos) ;
  • iypos=Ypos-int(Ypos);
  • if(ixpos>0.5)
  • Xpos=int(Xpos)+1;
  • else
  • Xpos=int(Xpos);
  • if( individus->Down && nbmaxind<30)
  • {
  • if(!But1)
  • {
  • if((Xpos<e->col)&&(Ypos<e->lig)&&(e->get_val(Ypos*2,Xpos*2)==0) )
  • {
  • nbmaxind++; // e->get_val_id(Xpos,Ypos)
  • monde[nbmaxind].start.I=monde[nbmaxind].position.I=Ypos*2;
  • e->matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
  • matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
  • monde[nbmaxind].start.J=monde[nbmaxind].position.J=Xpos*2;
  • e->matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
  • matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
  • monde[nbmaxind].action=arrest;
  • monde[nbmaxind].chez_lui=false;
  • monde[nbmaxind].color.r=random(255)/255.0; monde[nbmaxind].color.v=random(200)/255.0;
  • monde[nbmaxind].angle=0;
  • monde[nbmaxind].butaccessible=false;
  • monde[nbmaxind].longueurchemin=0;
  • monde[nbmaxind].direction=1;
  • point p;
  • set_point(&p,Ypos,-2.0,Xpos);
  • //aff_individus();
  • //e->init_ag(Xpos*2,Ypos*2,0.5,0.5);
  • e->matENV[Ypos*2][Xpos*2].L=2; //occupée par un individu
  • individus_creation();
  • set_centre(p);
  • glPopMatrix();
  • agt=true;
  • But1=true;
  • }
  • /*else
  • {
  • ShowMessage("Place occupée ! ");
  • }*/
  • }
  • else
  • if((Xpos<e->col)&&(Ypos<e->lig)&&(e->get_val(Ypos*2,Xpos*2)==0) )
  • {
  • point p;
  • set_point(&p,Ypos,-2.0,Xpos);
  • glPushMatrix();
  • monde[nbmaxind].goal.I=Ypos*2;
  • e->matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
  • monde[nbmaxind].goal.J= Xpos*2;
  • e->matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
  • aff_but();
  • set_centre(p);
  • glPopMatrix();
  • But1=false;
  • }
  • /*else
  • ShowMessage("Place occupée ! ");*/
  • }
  • if(nbmaxind==2)
  • {
  • //ShowMessage("Il y a assez de population");
  • individus->Down = false;
  • individus->Enabled = false;
  • }
  • //supp_agn->Enabled=true;
  • //s_agent->Enabled=true;
  • //l_anim->Enabled=true;
  • //p_anim->Enabled=true;
  • dem->Enabled=true;
  • //a_anim->Enabled=true;
  • //Lancer1->Enabled=true;
  • //Pause1->Enabled=true;
  • //Arreter1->Enabled=true;
  • //Evenement_de_panique1->Enabled=true;
  • }
  • }
  • //---------------------------------------------------------------------------
  • void initial_matENV()
  • { int i,j;
  • for(i=0;i<40;i++)
  • {
  • for(j=0;j<60;j++)
  • {
  • matENV[i][j].L=e->get_val(i,j);
  • //matENV[i][j].ID.I=e->matENV[i][j].ID.I;
  • //matENV[i][j].ID.J=e->matENV[i][j].ID.J;
  • }
  • }
  • }
  • //////////////////////////
  • void __fastcall TFormMain::Timer2Timer(TObject *Sender)
  • {
  • if(aller)
  • {
  • se_deplacer();
  • }
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TFormMain::demClick(TObject *Sender)
  • {
  • Timer1->Enabled=false; aller=false;
  • int k=1,i;
  • indicev=indicef=-1;
  • for(i=1;i<=nbmaxind ;i++)
  • {
  • monde[i].goal.I=0;
  • monde[i].goal.J=0;
  • }
  • for(i=1;i<=nbmaxind ;i++)
  • { monde[i].start.I=monde[i].position.I=pospi[i].I;
  • e->matENV[pospi[i].I][pospj[i].J].ID.I=pospi[i].I;
  • matENV[pospi[i].I][pospj[i].J].ID.I=pospi[i].I;
  • monde[i].start.J=monde[i].position.J=pospj[i].J;
  • e->matENV[pospi[i].I][pospj[i].J].ID.J=pospj[i].J;
  • matENV[pospi[i].I][pospj[i].J].ID.J=pospj[i].J;
  • monde[i].action=arrest;
  • monde[i].chez_lui=false;
  • //monde[i].color.r=random(255)/255.0; monde[nbmaxind].color.v=random(200)/255.0;
  • monde[i].angle=0;
  • monde[i].butaccessible=false;
  • monde[i].longueurchemin=0;
  • monde[i].direction=1;
  • if(pospi[i].I<20)
  • {
  • monde[i].goal.I=2;
  • monde[i].goal.J=30;
  • }
  • if(pospi[i].I>=20)
  • {
  • monde[i].goal.I=39;
  • monde[i].goal.J=14;
  • }
  • }
  • if(nbmaxind)
  • {
  • if(!pause)
  • {
  • for(i=1;i<=nbmaxind;i++)
  • {
  • monde[i].position.I = monde[i].start.I;//=pospi[i].I ;
  • monde[i].position.J = monde[i].start.J;//=pospj[i].J ;
  • monde[i].chez_lui=false;
  • }
  • back_to_home1();
  • Timer2->Enabled=true;
  • }
  • }
  • }
  • //---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "projet.h"
#include "evrm.h"

  #define NORD 0
  #define SUD 1
  #define EST 2
  #define OUEST 3
  #define TDN 4
  #define TGN 5
  #define TDS 6
  #define TGS 7
  #define TDE 8
  #define TGE 9
  #define TGO 10
  #define TDO 11

    #define  confrontation 0
    #define  perpendicularite 1
    #define  blocage  2

    #define move 0
    #define arrest 1

 const int nbcelI=40;
const nbcelJ=60;
const int D=0;
const int HV=1;
coordonne pospi[30],pospj[30];
int posi,posj,nbcel,indicef,indicev,indice;
int maxcar=0,nbmaxind=0,maxlamp=0,maxarb=0;
bool but1=false,decoupage1=false,off=true,first=false;
cellule chemin[44*80];bool aller=false,vs=false,draw=false,pre=false,creer_obs=false,pre_ob=true,creer_ind=false,pre_ind=true,creer_but=false,pre_but=true;
bool start=false,go=true,pause=false;
bool one=false,twoo=false,three=false,four=false,choisir=false;
cellule elem1;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
int  submenid,menid;
 static int primitive = 0;
evrm *e;
//agent *a;
GLuint tex[21];
 point pt ;
int c,cc;
float xx,yy=10;
bool geni =false;
bool arret=false;
bool agt_dess=false;
bool cam=false;
bool agt=false;
bool v2d=true,v3d=false;
//int nbmaxind=0;
const float piover180 = 0.0174532925f;
float heading;
float xpos=0;
float zpos=18;
int Xpos,Ypos;//position de l'agent
bool But1=false;
GLfloat	yrot;                   // Y Rotation
GLfloat walkbias = 0;
GLfloat walkbiasangle = 0;
GLfloat lookupdown = 0.0f;
GLfloat	z = 0.0f;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
    : TForm(Owner)
{

    Application->OnIdle = IdleLoop;

    size = 50.0f;



}
//---------------------------------------------------------------------------
void __fastcall TFormMain::IdleLoop(TObject*, bool& done)
{
    done = false;
    RenderGLScene();
    SwapBuffers(hdc);
   
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
    hdc = GetDC(Panel1->Handle);
    SetPixelFormatDescriptor();
    hrc = wglCreateContext(hdc);
    if(hrc == NULL)
    	ShowMessage(":-)~ hrc == NULL");
    if(wglMakeCurrent(hdc, hrc) == false)
    	ShowMessage("Could not MakeCurrent");
    w = ClientWidth;
    h = ClientHeight;

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
   //LoadGLTextures(tex);                 // Jump to texture loading routine ( NEW )

  texturage(tex);
  // SetupLighting();
    //glClearColor(0.623f, 0.623f,1.0f, 1.0f);
    //glClearColor(0.733333f, 0.733333f,1.0f, 1.0f);
  //glClearColor(1.0f,1.0f,1.0f, 1.0f);

    glClearColor(0.792157f,0.894118f,1.0f, 1.0f);
   //glClearColor(0.823529f,0.909804f,0.968627f, 1.0f);


  V2D->Checked=true;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetPixelFormatDescriptor()
{
    PIXELFORMATDESCRIPTOR pfd = {
    	sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        24,
        0,0,0,0,0,0,
        0,0,
        0,0,0,0,0,
        32,
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0,0,
    };
    PixelFormat = ChoosePixelFormat(hdc, &pfd);
    SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormResize(TObject *Sender)
{
    GLfloat nRange = 10.0;
    w = Panel1->Width;
    h = Panel1->Height;


    glViewport     ( 0, 0, w, h );

  glMatrixMode   ( GL_PROJECTION );  // Select The Projection Matrix
  glLoadIdentity ( );                // Reset The Projection Matrix

   if (w <= h)
        glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
    else
	glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

  glMatrixMode   ( GL_MODELVIEW );  // Select The Model View Matrix
  glLoadIdentity ( );    // Reset The Model View Matrix


}
//---------------------------------------------------------------------------
void __fastcall TFormMain::RenderGLScene()
{
    GLfloat nRange = 10.0;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode   ( GL_PROJECTION );  // Select The Projection Matrix
  glLoadIdentity ( );                // Reset The Projection Matrix
  if(v3d) gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
  if(v2d) glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);


      glMatrixMode   ( GL_MODELVIEW );  // Select The Model View Matrix
      glLoadIdentity();

if (v2d)
 gluLookAt(0.0,1.0,0.0,0.0,0.0,0.0 ,0.0,0.0,-1.0);
if (v3d)
{
 if (cam==true )
 {      GLfloat x_m, y_m, z_m, u_m, v_m;
	GLfloat xtrans = -xpos;
	GLfloat ztrans = -zpos;
	GLfloat ytrans = -walkbias-0.25f;
	GLfloat sceneroty = 360.0f - yrot;

	int numtriangles;

	glRotatef(lookupdown,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);

	glTranslatef(xtrans, ytrans, ztrans);
  }
  else
   gluLookAt(xx,yy+2,12.0,0.0,0.0,0.0 ,0.0,0.0,-1.0);
}
    DrawObjects();

    glFlush();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawObjects()
{


     if(Scene->Checked==true)
       Draw_maison();
       

if(agt==true)
{
  //aff_individus();
 Draw_agent();
   //aff_but();
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormPaint(TObject *Sender)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   //  glClearColor(1.0f,1.0f,1.0f, 0.0f);
     // glClearColor(0.623f, 0.623f,1.0f, 1.0f);
    //glClearColor(0.733333f, 0.733333f,1.0f, 1.0f);
  glClearColor(0.1f,0.3f,0.8f, 1.0f);

    //glClearColor(0.792157f,0.894118f,1.0f, 1.0f);
   //glClearColor(0.823529f,0.909804f,0.968627f, 1.0f);


    DrawObjects();
     glFlush();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

//--------------------------------------------------------------------------*/
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TFormMain::Draw_maison()
{

maison ma_scene;
ma_scene.Dessiner(tex,e);
creat(e);

}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Draw_agent()
{point p;

 glPushMatrix();
 glTranslatef(-(e->col)/4,0.0,-(e->lig)/4);
 aff_individus();

 glPopMatrix();
 creat(e);

 glPushMatrix();
 glTranslatef(-(e->col)/4,0.0,-(e->lig)/4);
 aff_but();
   
 glPopMatrix();
 creat(e);
}
 ///////////////////////////////////:
 void TFormMain::set_centre(point p)
{
 set_point(&pt,p.x,p.y,p.z);
}
/////////////////////////////
void TFormMain::set_point(point *p,GLfloat x,GLfloat y,GLfloat z)
{p->x=x;
p->y=y;
p->z=z;
} 
/////////////////////////////////
/////////////dessiner individus////
  void  TFormMain::aff_individus()
  {
   GLfloat h_p=1.5,h_v=(2*h_p)/3,h_m=h_v,h_c=h_v/6,rad_v=0.4,rad_p=rad_v/2.3,rad_m=rad_p/2,rad_t=(2*rad_v)/3,rad_c=rad_v/3;
   GLint ang=4;
   GLUquadricObj *quadratic;
  quadratic=gluNewQuadric();
  point pt;
  
 float angle=-90;
        int x,y;
        int nb=1,i;

  for(i=1;i<=nbmaxind;i++)
 {  //set_point(&pt,Xpos,-2.0,Ypos);
     //monde[i].priorite=i;
    // angle=monde[i].angle;
     e->init_ag(monde[i].position.I,monde[i].position.J,0.5,0.5);
  glPushMatrix();
  // glTranslatef(pt.x+0.25,pt.y,pt.z+0.25);
    // glTranslatef(pt.x,pt.y,pt.z);
   //   glTranslatef(Xpos,-2,Ypos);
   
    
  /////////////////////////tete ////////////////////////////////////
 // glColor3f(1.0f,1.0f,1.0f);
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(0.0,h_p+h_v+h_c+rad_t,0.0);
// gluSphere(quadratic,rad_t,32,32);
  glCallList(nb);nb++;
 glPopMatrix();
  /////////////////////////////cou //////////////////////////
 //glColor3f(1.0f,1.0f,1.0f);
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(0.0,h_p+h_v+rad_c/2,0.0);
 //glRotatef(-90,1.0,0.0,0.0);
 glRotatef(angle,1.0,0.0,0.0);
 //gluCylinder(quadratic,rad_c,rad_c,h_c,32,32);
  glCallList(nb);nb++;
 glPopMatrix();
 ////////////////////////ventre//////////////////////////
glColor3f(0.4f,0.21f,0.6f);
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(0.0,h_p,0.0);
 // glRotatef(-90,1.0,0.0,0.0);
  glRotatef(angle,1.0,0.0,0.0);
 //gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
   glCallList(nb);nb++;
  glPopMatrix();
 ///////////////////////////////////////////
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(0.0,h_p+h_v,0.0);
// glRotatef(-90,1.0,0.0,0.0);
  glRotatef(angle,1.0,0.0,0.0);
 //Circle(rad_v);
  glCallList(nb);nb++;
 glPopMatrix();
 /////////////////////////main_g///////////////////////////

 glPushMatrix();
 glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(-(rad_v+rad_m+0.02),h_p,0.0);
  //glRotatef(-90,1.0,0.0,0.0);
  glRotatef(angle,1.0,0.0,0.0);
  glRotatef(ang,0.0,1.0,0.0);
 //gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
  glCallList(nb);nb++;
 glPopMatrix();

 ///////////////////////////main_d //////////////////////////

 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(+(rad_v+rad_m+0.02),h_p,0.0);
  //glRotatef(-90,1.0,0.0,0.0);
    glRotatef(-90,1.0,0.0,0.0);
  glRotatef(-ang,0.0,1.0,0.0);
 //gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
 glCallList(nb);nb++;
 glPopMatrix();

 ////////////////////////::::/pied-g ///////////////////////////
 glColor3f(0.0f,0.0f,0.0f);
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(-(rad_v-rad_p),0.0,0.0);
 // glRotatef(-90,1.0,0.0,0.0);
  glRotatef(angle,1.0,0.0,0.0);
 //gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
   glCallList(nb);nb++;
 glPopMatrix();
 /////////////////////:/pied-d/////////////////////////:
glColor3f(0.0f,0.0f,0.0f);
 glPushMatrix();
  glTranslated((monde[i].position.J/2),-2.0,(monde[i].position.I/2));
 glTranslatef(+(rad_v-rad_p),0.0,0.0);
  //glRotatef(-90,1.0,0.0,0.0);
     glRotatef(angle,1.0,0.0,0.0);
 //gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
  glCallList(nb);nb++;
 glPopMatrix();
 glPopMatrix();
   e->init_ag(pt.x,pt.z,0.5,0.5);
 //e->new_obs(pt.x,pt.z,0.5,0.5);
}
}
/////////////////////////////////////////////////
   void TFormMain::individus_creation()
    {
        GLfloat h_p=1.4,h_v=(2*h_p)/3,h_m=h_v,h_c=h_v/6,rad_v=0.4,rad_p=rad_v/2.3,rad_m=rad_p/2,rad_t=(2*rad_v)/3,rad_c=rad_v/3;
        GLUquadricObj *quadObj;
         GLUquadricObj *quadratic;
        quadratic=gluNewQuadric();
          GLint ang=4;
        int nb=1;
        //int h_p=1.0, h_v= 0.5,h_m=0.5;
        for(int i=1;i<=nbmaxind;i++)
           {
                monde[i].priorite=i;

    //************************* tete *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                 //glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                  glColor3f(1.0f,1.0f,1.0f);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
                //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                 gluSphere(quadratic,rad_t,32,32);
                glEndList();
    //*************************  cou *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                 //glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                 glColor3f(1.0f,1.0f,1.0f);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
               // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
               gluCylinder(quadratic,rad_c,rad_c,h_c,32,32);
                glEndList();
    //************************* vente *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                 glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
               // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
                glEndList();
    /////////////////////////////////////////////////////////////
        glNewList( nb, GL_COMPILE);nb++;
                 glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
               // gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                //gluCylinder(quadratic,rad_v,rad_v,h_v,32,32);
                Circle(rad_v);
                glEndList();
      //************************* mais_g *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                 glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
                 gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
                //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                glEndList();
       //************************* main_d *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                 glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
                gluCylinder(quadratic,rad_m,rad_m,h_m,32,32);
                //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                glEndList();
       //************************* pied_g *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                // glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                 glColor3f(1.0f,1.0f,1.0f);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
                 gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
              //  gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                glEndList();
        //************************* pied_d *************************************

                  glNewList( nb, GL_COMPILE);nb++;
                // glColor3f(monde[i].color.r,monde[i].color.v,0.4);
                glColor3f(1.0f,1.0f,1.0f);
                quadObj = gluNewQuadric ();
                gluQuadricDrawStyle (quadObj, GLU_FILL);
                gluQuadricNormals (quadObj, GLU_SMOOTH);
                 gluCylinder(quadratic,rad_p,rad_p,h_p,32,32);
                //gluCylinder (quadObj,0.15,0.13,0.35, 16, 16);
                glEndList();
    }
    }


  
/////////////////

//-------------------------------------------------------------------------
   void TFormMain::aff_but()
{
        int x,y,i,j;

        for(int t=1;t<=nbmaxind;t++)
           {
                glPushMatrix();
                i=monde[t].goal.I/2;
                j=monde[t].goal.J/2;
                x=j;
                y=i;
                glColor3f(monde[t].color.r,monde[t].color.v,0.4);
                glTranslated(x,-1.9,y);
                glScaled(1,0.1,1);
                glutSolidCube(1);
                glPopMatrix();
           }
}
//////////////////////////////:::
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key == VK_UP)
    {
     xpos -= (float)sin(heading*piover180) * 0.05f;
					zpos -= (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle >= 359.0f)
					{
						walkbiasangle = 0.0f;
					}
					else
					{
						walkbiasangle+= 30;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
    }
    if(Key == VK_DOWN)
    {
     xpos += (float)sin(heading*piover180) * 0.05f;
					zpos += (float)cos(heading*piover180) * 0.05f;
					if (walkbiasangle <= 1.0f)
					{
						walkbiasangle = 359.0f;
					}
					else
					{
						walkbiasangle-= 30;
					}
					walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
    }
    if(Key == VK_LEFT)
    {
     heading +=4.0f;
					yrot = heading;
    }
    if(Key == VK_RIGHT)
    {
     heading -= 4.0f;
					yrot = heading;
    }
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupLighting()
{
    GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
    GLfloat MaterialDiffuse[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat MaterialShininess[] = {50.0};

    GLfloat AmbientLightPosition0[] = {3.0, 6.0, 5.0, 0.0};
    GLfloat LightAmbient0[] = {1.0, 1.0, 1.0, 1.0};

    GLfloat AmbientLightPosition1[] = {-3.0, 6.0, 5.0, 0.0};
    GLfloat LightAmbient1[] = {1.0, 1.0, 1.0, 1.0};

    GLfloat AmbientLightPosition2[] = {3.0,6.0, -5.0, 0.0};
    GLfloat LightAmbient2[] = {1.0, 1.0, 1.0, 1.0};

    GLfloat AmbientLightPosition3[] = {-3.0, 6.0, -5.0, 0.0};
    GLfloat LightAmbient3[] = {1.0, 1.0, 1.0, 1.0};



    glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
    glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);

     glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition0);
     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0);

     glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition1);
     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient1);

     glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition2);
     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient2);

     glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition3);
     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient3);

    glEnable(GL_LIGHTING);

    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT2);
    glEnable(GL_LIGHT3);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    glShadeModel(GL_SMOOTH);
}
//---------------------------------------------------------------------------
    ////////////////////////creation de la scene//////////////////
//---------------------------------------------------------------------------
 

 /////////////////////////
//==========================================================================

                     // RECHERCHE DU CHEMIN

//===========================================================================


//+++++++++++++++++++++++++++++FONCTIONS POUR LES PILES++++++++++++++++++++++
void empiler(cellule pile[nbcelI*nbcelJ],cellule element,int *indice)
  {
     (*indice)++;
     pile[*indice]=element;
   }
//------------------------------------------------------------------------
cellule depiler(cellule pile[nbcelI*nbcelJ],int *indice)
  {     cellule cel3;
        cel3=pile[*indice];
        (*indice)--;
        return(cel3);

  }
//------------------------------------------------------------------------
bool pile_vide(cellule pile[nbcelI*nbcelJ],int indice)
{
         if(indice==-1)
           return(true);
        else
        return(false);
}
//------------------------------------------------------------------------
trier_la_pile_des_visites()
{   //???????????????????
 cellule element;
        for(int i=indicev;i>=0;i--)
                {
                  if(pile_des_visites[i].F<pile_des_visites[indicev].F)
                      {
                        element=pile_des_visites[indicev];
                        pile_des_visites[indicev]=pile_des_visites[i];
                        pile_des_visites[i]=element;
                      }
                }
 }
//------------------------------------------------------------------------
 int exist_dans_pile(cellule pile[nbcelI*nbcelJ],cellule element,int indice)
    {
      for(int i=0;i<=indice;i++)
        if(element.ID.I==pile[i].ID.I&&element.ID.J==pile[i].ID.J)
                return i;             //l'element existe dans la pile et on retourne son emplecement
      return(-1);                    //l'element n'existe pas

    }
//+++++++++++++++++++++++++++++CALCULE DES COUTS DES CHEMINS ET TESTS ++++++++++++++++++++++++++++

int calcule_de_H(cellule element)
      {  int n;
     n=(abs(but.ID.I-element.ID.I)+abs(but.ID.J-element.ID.J))*10;
        return(n);
     }
//---------------------------------------------------------------------------
int teste_adjacente(cellule celadj)
  {  
      int i,j;
     //cellule elem1,elem2,elem3,elem4;
      i=celadj.ID.I;
      j=celadj.ID.J;
    cellule elem1=matENV[i-1][j];
   cellule elem2=matENV[i+1][j];
   cellule elem3=matENV[i][j-1];
   cellule  elem4=matENV[i][j+1];
    
      if(elem1.L==1||elem2.L==1)
               return 0;
     return 1;

  }
//-----------------------------------------------------------------------------------------
bool cellule_limite(cellule celcour)
  { if(celcour.ID.I==0||celcour.ID.I==nbcelI-1||celcour.ID.J==0||celcour.ID.J==nbcelJ-1)  //je doit ajouter le teste si la cellule est en 0,0........
             return true;
        else
              return false;
  }
//------------------------------------------------------------------------------------------
traitement_cellule(int type,cellule celadj,cellule celcour)
    {     int pos;
        if(celadj.L==0)
           {
              if(exist_dans_pile(pile_finale,celadj,indicef)==(-1))
                  {
                      if(pos=exist_dans_pile(pile_des_visites,celadj,indicev)==(-1))
                          {
                              celadj.pere=celcour.ID;
                              if(type==D&&teste_adjacente(celadj)==1)
                                 //if(teste_adjacente(celadj)==1)
                                   {
                                    celadj.G=celcour.G+14;
                                    celadj.H=calcule_de_H(celadj);
                                    celadj.F=celadj.H+celadj.G;
                                    empiler(pile_des_visites,celadj,&indicev);

                                    }
                              if(type==HV)
                                   {
                                    celadj.G=celcour.G+10;
                                    celadj.H=calcule_de_H(celadj);
                                    celadj.F=celadj.H+celadj.G;
                                    empiler(pile_des_visites,celadj,&indicev);
                                    }
                          }
                      else  //l'element existe dans la pile des visité
                          {
                              if(type==HV)
                                {
                                 if(celcour.G+10<celadj.G)
                                    {
                                        celadj.G=celcour.G+10;
                                        celadj.F=celadj.G+celadj.H;
                                        celadj.pere=celcour.ID;
                                        pile_des_visites[pos]=celadj;
                                    }
                                 }
                              else //type  ==D   "diagonale"
                                 {
                                   if(celcour.G+14<celadj.G)
                                    {
                                        celadj.G=celcour.G+14;
                                        celadj.F=celadj.G+celadj.H;
                                        celadj.pere=celcour.ID;
                                        pile_des_visites[pos]=celadj;
                                    }
                                 }


                          }
                  }
           }
  }
//------------------------------------------------------------------------------------------

recherch_cases_valide(cellule celcour)
    {    int i=celcour.ID.I;
        int j=celcour.ID.J;
        cellule cel1,cel2,cel3;
        if(!cellule_limite(celcour))          //  la cellule n'est une cellule limite
           {    matENV[i][j-1].ID.I=i;
                matENV[i][j-1].ID.J=j-1;
                traitement_cellule(HV,matENV[i][j-1],celcour);
                 matENV[i][j+1].ID.I=i;
                matENV[i][j+1].ID.J=j+1;
                traitement_cellule(HV,matENV[i][j+1],celcour);
                 matENV[i-1][j].ID.I=i-1;
                matENV[i-1][j].ID.J=j;
                traitement_cellule(HV,matENV[i-1][j],celcour);
                matENV[i+1][j].ID.I=i+1;
                matENV[i+1][j].ID.J=j;
                traitement_cellule(HV,matENV[i+1][j],celcour);

                matENV[i+1][j-1].ID.I=i+1;
               matENV[i+1][j-1].ID.J=j-1;
                traitement_cellule(D,matENV[i+1][j-1],celcour);
                matENV[i-1][j-1].ID.I=i-1;
                matENV[i-1][j-1].ID.J=j-1;
                traitement_cellule(D,matENV[i-1][j-1],celcour);
                 matENV[i+1][j+1].ID.I=i+1;
                matENV[i+1][j+1].ID.J=j+1;
                traitement_cellule(D,matENV[i+1][j+1],celcour);
                 matENV[i-1][j+1].ID.I=i-1;
                matENV[i-1][j+1].ID.J=j+1;
                traitement_cellule(D,matENV[i-1][j+1],celcour);
           }
        else
           {
             switch (i)
                        {
                           case 0:   matENV[i][j-1].ID.I=i;
                                     matENV[i][j-1].ID.J=j-1;
                                    traitement_cellule(HV,matENV[i][j-1],celcour);
                                      matENV[i][j+1].ID.I=i;
                                      matENV[i][j+1].ID.J=j+1;
                                    traitement_cellule(HV,matENV[i][j+1],celcour);
                                     matENV[i+1][j].ID.I=i+1;
                                       matENV[i+1][j].ID.J=j;
                                    traitement_cellule(HV,matENV[i+1][j],celcour);
                                       matENV[i+1][j-1].ID.I=i+1;
                                       matENV[i+1][j-1].ID.J=j-1;
                                    traitement_cellule(D,matENV[i+1][j-1],celcour);
                                     matENV[i+1][j+1].ID.I=i+1;
                                     matENV[i+1][j+1].ID.J=j+1;
                                    traitement_cellule(D,matENV[i+1][j+1],celcour);
                                    break;

                           case nbcelI-1:  matENV[i][j-1].ID.I=i;
                                           matENV[i][j-1].ID.J=j-1;
                                          traitement_cellule(HV,matENV[i][j-1],celcour);
                                           matENV[i][j+1].ID.I=i;
                                           matENV[i][j+1].ID.J=j+1;
                                          traitement_cellule(HV,matENV[i][j+1],celcour);
                                            matENV[i-1][j].ID.I=i-1;
                                             matENV[i-1][j].ID.J=j;
                                          traitement_cellule(HV,matENV[i-1][j],celcour);
                                            matENV[i-1][j-1].ID.I=i-1;
                                            matENV[i-1][j-1].ID.J=j-1;
                                          traitement_cellule(D,matENV[i-1][j-1],celcour);
                                           matENV[i-1][j+1].ID.I=i-1;
                                           matENV[i-1][j+1].ID.J=j+1;
                                          traitement_cellule(D,matENV[i-1][j+1],celcour);
                                          break;


                        }

              switch (j)
                         {
                             case 0:     matENV[i-1][j].ID.I=i-1;
                                           matENV[i-1][j].ID.J=j;
                                         traitement_cellule(HV,matENV[i-1][j],celcour);
                                          matENV[i+1][j].ID.I=i+1;
                                           matENV[i+1][j].ID.J=j;
                                         traitement_cellule(HV,matENV[i+1][j],celcour);
                                          matENV[i][j+1].ID.I=i;
                                           matENV[i][j+1].ID.J=j+1;
                                         traitement_cellule(HV,matENV[i][j+1],celcour);
                                          matENV[i+1][j+1].ID.I=i+1;
                                           matENV[i+1][j+1].ID.J=j+1;
                                         traitement_cellule(D,matENV[i+1][j+1],celcour);
                                           matENV[i-1][j+1].ID.I=i-1;
                                           matENV[i-1][j+1].ID.J=j+1;
                                         traitement_cellule(D,matENV[i-1][j+1],celcour);
                                          break;

                             case nbcelJ-1:  matENV[i-1][j].ID.I=i-1;
                                             matENV[i-1][j].ID.J=j;
                                             traitement_cellule(HV,matENV[i-1][j],celcour);
                                              matENV[i+1][j].ID.I=i+1;
                                              matENV[i+1][j].ID.J=j;
                                             traitement_cellule(HV,matENV[i+1][j],celcour);
                                             matENV[i][j-1].ID.I=i;
                                            matENV[i][j-1].ID.J=j-1;
                                             traitement_cellule(HV,matENV[i][j-1],celcour);
                                              matENV[i+1][j-1].ID.I=i+1;
                                           matENV[i+1][j-1].ID.J=j-1;
                                             traitement_cellule(D,matENV[i+1][j-1],celcour);
                                              matENV[i-1][j-1].ID.I=i-1;
                                               matENV[i-1][j-1].ID.J=j-1;
                                             traitement_cellule(D,matENV[i-1][j-1],celcour);
                                             break;
                         }
           }
   }
//----------------------------------------------------------------------------------------------
bool recherche_chemin(coordonne d,coordonne b)
     {     cellule cel;
           indicev=indicef=-1;
           but.ID=b;
           bool resultat=false;
           empiler(pile_des_visites,matENV[d.I][d.J],&indicev);
           while(!resultat)
              {
                    cel=pile_des_visites[indicev];
                    if(cel.ID.I==b.I&&cel.ID.J==b.J)     //la cellule est cel du but
                       {
                          empiler(pile_finale,depiler(pile_des_visites,&indicev),&indicef);
                          resultat=true;
                          return resultat;
                       }
                    else
                       {
                           if(!pile_vide(pile_des_visites,indicev))    //la pile des visite n'est pas vide
                              {
                                 empiler(pile_finale,depiler(pile_des_visites,&indicev),&indicef);
                                 recherch_cases_valide(cel);
                                 trier_la_pile_des_visites();
                              }
                           else
                                return false;
                       }
              }

     }
//---------------------------------------------------------------------------
void back_to_home()       //tous les individus cherchent leur chemin
    {

        for(int i=1;i<=nbmaxind;i++)
          {
               bool found=recherche_chemin(monde[i].start,monde[i].goal);
               if(found)
                   {
                     extraire_chemin(i);
                     monde[i].butaccessible=true;
                     monde[i].position=monde[i].start;
                   }
               else
                     monde[i].butaccessible=false;
          }
       aller=true;
    }
    ////////////////////////////////////////////////////
    void back_to_home1()       //tous les individus cherchent leur chemin
    {

        for(int i=1;i<=nbmaxind;i++)
          {
               bool found=recherche_chemin(monde[i].start,monde[i].goal);
               if(found)
                   {
                     extraire_chemin(i);
                     monde[i].butaccessible=true;
                     monde[i].position=monde[i].start;
                   }
               else
                     monde[i].butaccessible=false;
          }
       aller=true;
    }
//---------------------------------------------------------------------------
extraire_chemin(int ind)
     {
                coordonne inter[3000],interm;
                cellule element,ident;
                int pos=0,c=0,i=indicef;
                bool trouve=false;

                element=pile_finale[indicef];
                inter[c++]=pile_finale[indicef].ID;
                while(!trouve)
                {
                        ident.ID=element.pere;
                        pos=exist_dans_pile(pile_finale,ident,indicef);
                        element=pile_finale[pos];
                        inter[c++]=element.ID;

                        if(element.ID.I==monde[ind].start.I&&element.ID.J==monde[ind].start.J)
                                trouve=true;
                        nbcel=c;
                }
                monde[ind].longueurchemin=c;
                monde[ind].parser=0;

                //inverser et copier dans le tableau chemin
                for(int i=0;i<nbcel;i++)
                  {
                      monde[ind].chemin[i]=inter[--c];
                  }
     }
//---------------------------------------------------------------------------
float direction(int i)
{
int proch=0;
     switch (monde[i].position.I-monde[i].chemin[i].I)
     {
       case  1: if(monde[i].position.J-monde[i].chemin[i].J == 0)proch=3;
                if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=2;
                if(monde[i].position.J-monde[i].chemin[i].J ==-1)proch=4;
       break;
       case  0:
                if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=1;
                 else proch=5;
       break;
        case -1: if(monde[i].position.J-monde[i].chemin[i].J == 0)proch=7;
                if(monde[i].position.J-monde[i].chemin[i].J == 1)proch=8;
                if(monde[i].position.J-monde[i].chemin[i].J == -1)proch=6;
       break;
     }
return(45 *(proch-monde[i].direction));
}
//===========================================================================

                  //FIN RECHERCHE DU CHEMIN

//===========================================================================


  //-FONCTION DE DEPLACEMENT D'INDIVIDU------------------------------------------------------
void TFormMain::se_deplacer()
{
        //ici d'abord on fait un appel a la procedure de perception
        for(int i=1;i<=nbmaxind;i++)    //tous les individus sont supposé en mouvement sauf s'il y aura une action de bloquer qlq'1
           {
                monde[i].action=move;
                matENV[monde[i].position.I][monde[i].position.J].L=0;
       //         e->matENV[monde[i].position.I][monde[i].position.J].L=0;
                monde[i].lieu=matENV[monde[i].position.I][monde[i].position.J].lieu;
           }

        trouver_zone_securite();     //perception

       recherche_collision();       //perception decision      action
       
        //nettoyer la matENV des traces d'individus
        for(int i=1;i<=nbmaxind;i++)
             {
                if(!monde[i].chez_lui&&monde[i].butaccessible&&monde[i].action==move)
                  {

                   if(monde[i].longueurchemin==monde[i].parser+1)
                      monde[i].chez_lui=true;
                   else
                      monde[i].parser++;
                    point p;
                   monde[i].angle=direction(i);
                   matENV[monde[i].position.I][monde[i].position.J].L=2;
                   pospi[i].I= monde[i].position.I;
                   pospj[i].J= monde[i].position.J;
                   e->matENV[monde[i].position.I][monde[i].position.J].L=2;
                 


                  }
             }
}

//==============================================================================================



 //==============================================================================================
void trouver_zone_securite()
  {
        for(int i=1;i<=nbmaxind;i++)
          {
          if(!monde[i].chez_lui&&monde[i].butaccessible)
            {
               monde[i].position=monde[i].chemin[monde[i].parser];
               if(monde[i].parser+1==monde[i].longueurchemin)  //but attein
                    {
                        monde[i].zone_securite[0].I=-1;
                        monde[i].zone_securite[0].J=-1;
                        monde[i].zone_securite[1].I=-1;
                        monde[i].zone_securite[1].J=-1;
                    }
               else
                 {
                        if(monde[i].parser+2==monde[i].longueurchemin)
                        {
                         monde[i].zone_securite[0]=monde[i].chemin[monde[i].parser+1];
                         monde[i].zone_securite[1].I=-1;
                         monde[i].zone_securite[1].J=-1;
                         }
                        else
                            {
                               monde[i].zone_securite[0]=monde[i].chemin[monde[i].parser+1];
                               monde[i].zone_securite[1]=monde[i].chemin[monde[i].parser+2];
                            }
                 }
              }
          }
  }
//==========================================================================================
      //RECHERCHE DES COLLISIONS POSSIBLE

//==========================================================================================
  void recherche_collision()
 {       int num_tab;
         for(int i=0;i<=nb_tab;i++)
           tab_pieton_coll[i].taille_tab=0;
         nb_tab=0; 
        for(int ind1=1;ind1<=nbmaxind;ind1++)
           {
                for(int ind2=ind1;ind2<=nbmaxind;ind2++)
                   {
                        if(ind1!=ind2&&!(monde[ind1].chez_lui||monde[ind2].chez_lui))  //j'aurai un pb ici car l'affectation des valeur de chez lui se fait avant cette operation donc" je doit la reviser
                           {
                              bool collision=false;
                              if((monde[ind1].position.I==monde[ind2].zone_securite[0].I&&monde[ind1].position.J==monde[ind2].zone_securite[0].J)||(monde[ind1].position.I==monde[ind2].zone_securite[1].I&&monde[ind1].position.J==monde[ind2].zone_securite[1].J)||(monde[ind1].position.I==monde[ind2].position.I&&monde[ind1].position.J==monde[ind2].position.J))
                                     collision=true;
                              if((monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].position.I&&monde[ind1].zone_securite[0].J==monde[ind2].position.J))
                                     collision=true;
                              if((monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].position.I&&monde[ind1].zone_securite[1].J==monde[ind2].position.J))
                                      collision=true;

                              if(collision) //il ya une collision
                                 {
                                    //traitement_collision(ind1,ind2);//??????????????????
                                    num_tab=recherche_tab_pieton(ind1);
                                    if(num_tab!=0)
                                       inserer_pietons(ind1,ind2,num_tab);
                                    else
                                        {
                                             num_tab=recherche_tab_pieton(ind2);
                                             if(num_tab!=0)
                                                  inserer_pietons(ind1,ind2,num_tab);
                                             else
                                                {
                                                   nb_tab++;
                                                   num_tab=nb_tab;
                                                   inserer_pietons(ind1,ind2,num_tab);
                                                }
                                        }

                                 }

                           }
                   }
           }
      for(int i=1;i<=nb_tab;i++)
            {
               if(tab_pieton_coll[i].taille_tab==1)
                        {
                            traitement_collision(tab_pieton_coll[i].tab_pair_collision[1].pieton1,tab_pieton_coll[i].tab_pair_collision[1].pieton2);
                        }
            }
      for(int i=1;i<=nb_tab;i++)
            {
               if(tab_pieton_coll[i].taille_tab!=1)
                        {
                            for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
                               {
                                individus indiv1=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton1];
                                individus indiv2=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton2];
                                int Tcoll=type_collision(indiv1,indiv2);
                                if(Tcoll==blocage)
                                        traitement_collision(tab_pieton_coll[i].tab_pair_collision[j].pieton1,tab_pieton_coll[i].tab_pair_collision[j].pieton2);
                                }
                        }
            }
      for(int i=1;i<=nb_tab;i++)
            {
               if(tab_pieton_coll[i].taille_tab!=1)
                        {
                            for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
                               {
                                individus indiv1=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton1];
                                individus indiv2=monde[tab_pieton_coll[i].tab_pair_collision[j].pieton2];
                                int Tcoll=type_collision(indiv1,indiv2);
                                if(Tcoll!=blocage)
                                        traitement_collision(tab_pieton_coll[i].tab_pair_collision[j].pieton1,tab_pieton_coll[i].tab_pair_collision[j].pieton2);
                                }
                        }
            }
 }
//=============================================================================================
 bool rec_col(int  ind1,int ind2)
    {   bool col;
        if(ind1!=ind2&&!(monde[ind1].chez_lui||monde[ind2].chez_lui))  //j'aurai un pb ici car l'affectation des valeur de chez lui se fait avant cette operation donc" je doit la reviser
                           {
                              if((monde[ind1].position.I==monde[ind2].zone_securite[0].I&&monde[ind1].position.J==monde[ind2].zone_securite[0].J)||(monde[ind1].position.I==monde[ind2].zone_securite[1].I&&monde[ind1].position.J==monde[ind2].zone_securite[1].J)||(monde[ind1].position.I==monde[ind2].position.I&&monde[ind1].position.J==monde[ind2].position.J))
                                     col=true;
                              if((monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[0].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[0].I==monde[ind2].position.I&&monde[ind1].zone_securite[0].J==monde[ind2].position.J))
                                     col=true;
                              if((monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[0].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[0].J&&monde[ind2].zone_securite[0].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].zone_securite[1].I&&monde[ind1].zone_securite[1].J==monde[ind2].zone_securite[1].J&&monde[ind2].zone_securite[1].J!=-1)||(monde[ind1].zone_securite[1].I==monde[ind2].position.I&&monde[ind1].zone_securite[1].J==monde[ind2].position.J))
                                      col=true;

                              if(col) //il ya une collision
                                 {
                                    return true;
                                 }

                           }
    }
 //=============================================================================================
                 //TRAITEMENT DES COLLISIONS
//=============================================================================================
void traitement_collision(int ind1,int ind2)
   {
             int i,pmoins,pplus;
             coordonne celcomp;

             monde[ind1].direction=ma_direction(monde[ind1]);
             monde[ind2].direction=ma_direction(monde[ind2]);
             individus indiv1=monde[ind1];
             individus indiv2=monde[ind2];

             if(monde[ind1].priorite>=monde[ind2].priorite)   {pplus=ind1; pmoins=ind2;}
             else {pplus=ind2;pmoins=ind1;}

             int Tcoll=type_collision(indiv1,indiv2);
             switch(Tcoll)
                {

                     case confrontation:
                                              celcomp=droite_ou_gauche(monde[pmoins]);
                                              if(celcomp.I==-1&&celcomp.J==-1||monde[pmoins].action==arrest)//le moins prioritaire ne peut pas bouger ou il est bloquer
                                                  {
                                                    //on essay avec le plus prioritaire
                                                    celcomp=droite_ou_gauche(monde[pplus]);
                                                    if(celcomp.I==-1&&celcomp.J==-1)    //le plus prioritaire ne peut pas bouger aussi
                                                       {
                                                             //reculer le moin prioritaire
                                                             monde[pmoins].parser=monde[pmoins].parser-2;
                                                             monde[pmoins].position=monde[pmoins].chemin[monde[pmoins].parser];
                                                       }
                                                    else     //le plus prioritaire peut  bouger   er le moins prioritairte ne peut pas
                                                       {     if(monde[pplus].action!=arrest)
                                                              {
                                                             coordonne c=monde[pplus].start;
                                                             monde[pplus].start=celcomp;
                                                             recherche_chemin(monde[pplus].start,monde[pplus].goal);

                                                             extraire_chemin(pplus);
                                                             monde[pplus].position=monde[pplus].chemin[monde[pplus].parser];
                                                             monde[pplus].parser--;
                                                             monde[pplus].start=c;
                                                                }
                                                       }
                                                  }
                                              else    // le moin prioritaire peut bouger)
                                                  {
                                                      coordonne c=monde[pmoins].start;
                                                      monde[pmoins].start=celcomp;
                                                      recherche_chemin(monde[pmoins].start,monde[pmoins].goal);

                                                      extraire_chemin(pmoins);
                                                      monde[pmoins].position=monde[pmoins].chemin[monde[pmoins].parser];
                                                      monde[pmoins].parser;
                                                      monde[pmoins].start=c;
                                                  }

                                        break;

                      case perpendicularite:
                                            if(monde[pplus].action!=arrest)//si le plus prioritaire n'est pas bloqué
                                                       bloquer(pmoins);

                                           break;

                     case blocage:         if(monde[ind1].direction==NORD)
                                                if(monde[ind1].position.I<=monde[ind2].position.I)  bloquer(ind1);
                                                //else bloquer(ind2);
                                           if(monde[ind1].direction==SUD)
                                                if(monde[ind1].position.I<=monde[ind2].position.I)  bloquer(ind2);
                                                //else bloquer(ind1);
                                           if(monde[ind1].direction==EST)
                                                if(monde[ind1].position.J<=monde[ind2].position.I)  bloquer(ind1);
                                                //else bloquer(ind2);
                                           if(monde[ind1].direction==OUEST)
                                                if(monde[ind1].position.I<=monde[ind2].position.I)  bloquer(ind1);
                                                //else bloquer(ind2);
                                           if(monde[ind1].direction==TDN||monde[ind1].direction==TGN)
                                                if(monde[ind1].position.I<=monde[ind2].position.I)  bloquer(ind1);
                                                //else bloquer(ind2);
                                           if(monde[ind1].direction==TDS||monde[ind1].direction==TGS)
                                                if(monde[ind1].position.I<=monde[ind2].position.I)  bloquer(ind2);
                                                //else bloquer(ind1);
                                           if(monde[ind1].direction==TDE||monde[ind1].direction==TGE)
                                                if(monde[ind1].position.J<=monde[ind2].position.J)  bloquer(ind1);
                                                //else bloquer(ind2);
                                           if(monde[ind1].direction==TDO||monde[ind1].direction==TGO)
                                                if(monde[ind1].position.J<=monde[ind2].position.J)  bloquer(ind2);
                                                //else bloquer(ind1);

                                           break;
                }

   }

//=====================================================================================================
int ma_direction(individus indiv)   // quel est la direction du piéton EST ou OUEST........
   {
      if(indiv.position.I==indiv.zone_securite[0].I&&indiv.position.I==indiv.zone_securite[1].I)//horizontale
         {
             if(indiv.position.J<indiv.zone_securite[0].J&&indiv.zone_securite[0].J<indiv.zone_securite[1].J)
                return(EST);
             else
                return(OUEST);
         }
      else
         {
              if(indiv.position.J==indiv.zone_securite[0].J&&indiv.position.J==indiv.zone_securite[1].J)//verticale
                if(indiv.position.I<indiv.zone_securite[0].I&&indiv.zone_securite[0].I<indiv.zone_securite[1].I)
                        return(NORD);
                else
                        return(SUD);
              else   //ni horizontale ni verticale
                if(indiv.position.I<indiv.zone_securite[1].I)  //vers le nord
                   if(indiv.position.J<indiv.zone_securite[1].J)
                      if(indiv.position.I==indiv.zone_securite[0].I)
                           return(TGN);
                      else
                           return(TDE);   //  indiv.zone_securite[0].I==indiv.zone_securite[1].I
                   else
                        if(indiv.position.I==indiv.zone_securite[0].I)
                             return(TDN);
                        else
                             return(TGO);
                else
                    if(indiv.position.J<indiv.zone_securite[1].J)   //tourner vers le sud
                        if(indiv.position.I==indiv.zone_securite[0].I)
                                return(TGS);
                        else
                                return(TGE);
                    else
                        if(indiv.position.I==indiv.zone_securite[0].I)
                                return(TDS);
                        else
                                return(TDO);


         }
   }
//============================================================================================
void bloquer(int i)
   {
        monde[i].action=arrest;
   }
//============================================================================================
coordonne droite_ou_gauche(individus indiv)     // rendre la case libre adjacente ; retourner la drote si elle est libre sinon la gauche
    {
         coordonne Case;
         int i=indiv.position.I;
         int j=indiv.position.J;

         switch(indiv.direction)
               {
                    case NORD: if(matENV[i][j+1].L==0)
                                {       matENV[i][j+1].ID.I=i;
                                         matENV[i][j+1].ID.J=j+1;
                                        return(matENV[i][j+1].ID);   //droite
                                 }
                               else
                                  {
                                      if(matENV[i+1][j+1].L==0)
                                          {
                                             matENV[i+1][j+1].ID.I=i+1;
                                              matENV[i+1][j+1].ID.J=j+1;
                                            return(matENV[i+1][j+1].ID); //droite diagonnale
                                          }
                                      else
                                       
                                             if(matENV[i][j-1].L==0)      //gauche
                                              {  matENV[i][j-1].ID.I=i;
                                                  matENV[i][j-1].ID.J=j-1;
                                                return(matENV[i][j-1].ID);
                                                }
                                             else
                                                if(matENV[i+1][j-1].L==0)     //gauche diagonnale
                                                {      matENV[i+1][j-1].ID.I=i+1;
                                                        matENV[i+1][j-1].ID.J=j-1;
                                                        return (matENV[i+1][j-1].ID);
                                                }
                                                else
                                                        {
                                                            Case.I=-1;Case.J=-1;
                                                            return(Case);
                                                        }

                                  }
                                  break;
                    case SUD:  if(matENV[i][j-1].L==0)
                                  {     matENV[i][j-1].ID.I=i;
                                         matENV[i][j-1].ID.J=j-1;
                                        return(matENV[i][j-1].ID);   //droite
                                   }
                               else
                                  {
                                      if(matENV[i-1][j-1].L==0)
                                        {    matENV[i-1][j-1].ID.I=i-1;
                                             matENV[i-1][j-1].ID.J=j-1;
                                            return(matENV[i-1][j-1].ID);   //droite diagonnale
                                        }
                                      else
                                             if(matENV[i][j+1].L==0)      //gauche
                                              {  matENV[i][j+1].ID.I=i;
                                                  matENV[i][j+1].ID.J=j+1;
                                                return(matENV[i][j+1].ID);
                                              }
                                             else
                                                if(matENV[i-1][j+1].L==0)    //gauche diagonnale
                                                 {      matENV[i-1][j+1].ID.I=i-1;
                                                        matENV[i-1][j+1].ID.J=j+1;
                                                        return (matENV[i-1][j+1].ID);
                                                 }
                                                else
                                                        {                                                                                                   Case.I=-1;Case.J=-1;
                                                            return(Case);
                                                        }

                                  }
                               break;
                    case EST:  if(matENV[i-1][j].L==0)
                                 {      matENV[i-1][j].ID.I=i-1;
                                        matENV[i-1][j].ID.J=j;
                                        return(matENV[i-1][j].ID);   //droite
                                  }
                               else
                                  {
                                      if(matENV[i-1][j+1].L==0)
                                      {      matENV[i-1][j+1].ID.I=i-1;
                                              matENV[i-1][j+1].ID.J=j+1;
                                             return(matENV[i-1][j+1].ID);   //droite diagonnale
                                      }
                                      else
                                             if(matENV[i+1][j].L==0)      //gauche
                                             {  matENV[i+1][j].ID.I=i+1;
                                                matENV[i+1][j].ID.J=j;
                                                return(matENV[i+1][j].ID);
                                                }
                                             else
                                                if(matENV[i+1][j+1].L==0)     //gauche diagonnale
                                                {       matENV[i+1][j+1].ID.I=i+1;
                                                        matENV[i+1][j+1].ID.J=j+1;
                                                        return (matENV[i+1][j+1].ID);
                                                }
                                                else
                                                        {
                                                            Case.I=-1;Case.J=-1;
                                                            return(Case);
                                                        }

                                  }
                                  break;
                    case OUEST:  if(matENV[i+1][j].L==0)
                                  {     matENV[i+1][j].ID.I=i+1;
                                         matENV[i+1][j].ID.J=j;
                                        return(matENV[i+1][j].ID);   //droite
                                   }
                               else
                                  {
                                      if(matENV[i+1][j-1].L==0)
                                          { matENV[i+1][j-1].ID.I=i+1;
                                            matENV[i+1][j-1].ID.J=j-1;
                                            return(matENV[i+1][j-1].ID);   //droite diagonnale
                                          }
                                      else
                                             if(matENV[i-1][j].L==0)      //gauche
                                             {  matENV[i-1][j].ID.I=i-1;
                                                 matENV[i-1][j].ID.J=j;
                                                return(matENV[i-1][j].ID);
                                             }
                                             else
                                                if(matENV[i-1][j-1].L==0)     //gauche diagonnale
                                                {    matENV[i-1][j-1].ID.I=i-1;
                                                      matENV[i-1][j-1].ID.J=j-1;
                                                        return (matENV[i-1][j-1].ID);
                                                }
                                                else
                                                        {
                                                            Case.I=-1;Case.J=-1;
                                                            return(Case);
                                                        }

                                  }
                             break;
                    case TDN:  if(matENV[i+1][j].L==0)
                                {   matENV[i+1][j].ID.I=i+1;
                                     matENV[i+1][j].ID.J=j;   
                                    return(matENV[i+1][j].ID);
                                }
                               else
                                        if(matENV[i+1][j+1].L==0)
                                          {   matENV[i+1][j+1].ID.I=i+1;
                                               matENV[i+1][j+1].ID.J=j+1;
                                               return(matENV[i+1][j+1].ID);
                                          }
                                        else
                                        {
                                        Case.I=-1;Case.J=-1;
                                        return(Case);
                                        }
                               break;
                    case TGN:  if(matENV[i+1][j].L==0)
                                {   matENV[i+1][j].ID.I=i+1;
                                    matENV[i+1][j].ID.J=j;
                                    return(matENV[i+1][j].ID);
                                }
                               else
                                  if(matENV[i+1][j-1].L==0)
                                   {  matENV[i+1][j-1].ID.I=i+1;
                                       matENV[i+1][j-1].ID.J=j-1;
                                      return(matENV[i+1][j-1].ID);
                                   }
                                  else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;
                    case TDS: if(matENV[i-1][j].L==0)
                                {   matENV[i-1][j].ID.I=i-1;
                                    matENV[i-1][j].ID.J=j;
                                    return(matENV[i-1][j].ID);
                                }
                              else
                                 if(matENV[i-1][j-1].L==0)
                                  {  matENV[i-1][j-1].ID.I=i-1;
                                      matENV[i-1][j-1].ID.J=j-1;
                                    return(matENV[i-1][j-1].ID);
                                  }
                                 else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;
                    case TGS: if(matENV[i-1][j].L==0)
                               {    matENV[i-1][j].ID.I=i-1;
                                    matENV[i-1][j].ID.J=j;
                                    return(matENV[i-1][j].ID);
                               }
                              else
                                 if(matENV[i-1][j+1].L==0)
                                 {  matENV[i-1][j+1].ID.I=i-1;
                                    matENV[i-1][j+1].ID.J=j+1;    
                                    return(matENV[i-1][j+1].ID);
                                 }
                                 else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;

                    case TDE:  if(matENV[i][j+1].L==0)
                                {    matENV[i][j+1].ID.I=i;
                                     matENV[i][j+1].ID.J=j+1;   
                                    return(matENV[i][j+1].ID);
                                }
                               else
                                   if(matENV[i-1][j+1].L==0)
                                   {  matENV[i-1][j+1].ID.I=i-1;
                                      matENV[i-1][j+1].ID.J=j+1;  
                                      return(matENV[i-1][j+1].ID);
                                   }
                                   else
                                    {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                    }
                               break;
                    case TGE:  if(matENV[i][j+1].L==0)
                                {   matENV[i][j+1].ID.I=i;
                                    matENV[i][j+1].ID.J=j+1;    
                                    return(matENV[i][j+1].ID);
                                }
                               else
                                   if(matENV[i+1][j+1].L==0)
                                    {  matENV[i+1][j+1].ID.I=i+1;
                                       matENV[i+1][j+1].ID.J=j+1; 
                                      return(matENV[i+1][j+1].ID);
                                    }
                               else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;
                    case TDO: if(matENV[i][j-1].L==0)
                                {   matENV[i][j-1].ID.I=i;
                                    matENV[i][j-1].ID.J=j-1;    
                                    return(matENV[i][j-1].ID);
                                }
                              else
                                  if(matENV[i+1][j-1].L==0)
                                  { matENV[i+1][j-1].ID.I=i+1;
                                     matENV[i+1][j-1].ID.J=j-1;
                                    return(matENV[i+1][j-1].ID);
                                  }
                                  else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;
                    case TGO: if(matENV[i][j-1].L==0)
                                {   matENV[i][j-1].ID.I=i;
                                     matENV[i][j-1].ID.J=j-1;   
                                    return(matENV[i][j-1].ID);
                                }
                              else
                                  if(matENV[i+1][j-1].L==0)
                                   { matENV[i+1][j-1].ID.I=i+1;
                                     matENV[i+1][j-1].ID.J=j-1;
                                    return(matENV[i+1][j-1].ID);
                                    }
                               else
                                  {
                                    Case.I=-1;Case.J=-1;
                                    return(Case);
                                  }
                               break;
               }

    }

//----------------------------------------------------------------------------------------------
int type_collision(individus indiv1,individus indiv2)

 {
       if(indiv1.direction==indiv2.direction)
                  return(blocage);
       switch(indiv1.direction)
                        {
                             case NORD:switch(indiv2.direction){
                                                                   case NORD: return(blocage);
                                                                              break;
                                                                   case SUD: return(confrontation);
                                                                              break;
                                                                   default : return(perpendicularite);
                                                                             break;
                                                                }
                                        break;
                             case SUD: switch(indiv2.direction){
                                                                   case NORD: return(confrontation);
                                                                              break;
                                                                   case SUD: return(blocage);
                                                                              break;
                                                                   default : return(perpendicularite);
                                                                             break;
                                                                }
                                        break;
                             case EST:  switch(indiv2.direction){
                                                                   case OUEST: return(confrontation);
                                                                                break;
                                                                   case EST: return(blocage);
                                                                              break;
                                                                   default : return(perpendicularite);
                                                                             break;
                                                                }
                                        break;
                             case OUEST:switch(indiv2.direction){
                                                                   case EST: return(confrontation);
                                                                                break;
                                                                   case OUEST: return(blocage);
                                                                              break;
                                                                   default : return(perpendicularite);
                                                                             break;
                                                                }
                                        break;
                             default: return(perpendicularite);
                                      break;
                        }
  }
//============================================================================================================
int recherche_tab_pieton(int pieton)
    {
        for(int i=1;i<=nb_tab;i++)
           for(int j=1;j<=tab_pieton_coll[i].taille_tab;j++)
               {
                     if(tab_pieton_coll[i].tab_pair_collision[j].pieton1==pieton||tab_pieton_coll[i].tab_pair_collision[j].pieton2==pieton)
                            return (i);  //retourne le numero de tableau
               }
        return 0;    // le pieton n'existe pas
    }
   //---------------------------------------------------------------------------------------
void inserer_pietons(int p1,int p2,int num)
   {
        tab_pieton_coll[num].taille_tab++;
        tab_pieton_coll[num].tab_pair_collision[tab_pieton_coll[num].taille_tab].pieton1=p1;
        tab_pieton_coll[num].tab_pair_collision[tab_pieton_coll[num].taille_tab].pieton2=p2;
    } 


//---------------------------------------------------------------------------

//=========================================================================================//


//---------------------------------------------------------------------------

void __fastcall TFormMain::SceneClick(TObject *Sender)
{
//indiv->Enabled=true;
   individus->Enabled=true;
   Reinit->Enabled=true;
   vu2d->Enabled=true;
    V2D->Enabled=true;
    vu3d->Enabled=true;
    V3D->Enabled=true;
    init->Enabled=true;

    e=new evrm;
 e->set_taille(40,60);
 e->init();
 Scene->Checked=true;

    //Timer3 ->Enabled=true;
}
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

void __fastcall TFormMain::QuitterClick(TObject *Sender)
{
// a->bs.m_a_j_f(a->bs.type)  ;
Close();
}
//////////////////////////////////////
  void __fastcall TFormMain::individusClick(TObject *Sender)
{

if(Scene->Checked)
     individus->Down=true;

 // a=new agent(e);
   agt_dess=true;

   //indiv->Enabled=false;
   //individus->Enabled=false;
   Reinit->Enabled=true;


 /*
 a=new agent(e);
  agt_dess=true;
   supp_agn->Enabled=true;
   s_agent->Enabled=true;
   Ajou_agn->Enabled=false;
   a_agent->Enabled=false;
   Reinit->Enabled=true;
   l_anim->Enabled=true;
   p_anim->Enabled=true;
   a_anim->Enabled=true;
   Lancer1->Enabled=true;
   Pause1->Enabled=true;
   Arreter1->Enabled=true;*/   

}

///////////////////////////////////////
//---------------------------------------------------------------------------

void __fastcall TFormMain::indivClick(TObject *Sender)
{
    //individus->Click();
/*if(Scene->Checked)
      indiv->Checked=true;
  // a=new agent(e);
   //agt_dess=true;
  

   indiv->Enabled=false;
  individus->Enabled=false;
   Reinit->Enabled=true;*/

}
//---------------------------------------------------------------------------

void __fastcall TFormMain::supp_agnClick(TObject *Sender)
{


if(Scene->Enabled==false)
Scene->Enabled=true;

//a->clean();
//free(a);

agt=false;
//supp_agn->Enabled=false;
//s_agent->Enabled=false;
if(V2D->Checked) 
{
indiv->Enabled=true;
individus->Enabled=true;
}
//l_anim->Enabled=false;
//p_anim->Enabled=false;
  dem->Enabled=false;
//a_anim->Enabled=false;
//Lancer1->Enabled=false;
//Pause1->Enabled=false;
//Arreter1->Enabled=false;
 //Evenement_de_panique1->Enabled=false;
}
//---------------------------------------------------------------------------

 
/////////////////////////////////////////////////:


void __fastcall TFormMain::ReinitClick(TObject *Sender)
{

Scene->Enabled=true;
Timer1->Enabled=false;
Timer2->Enabled=false;
free(e);
//free(a);
Scene->Checked=false;


agt=false;

//
  // supp_agn->Enabled=false;
   //s_agent->Enabled=false;
   //indiv->Enabled=false;
   individus->Enabled=false;
   Reinit->Enabled=true;
   //l_anim->Enabled=false;
   //p_anim->Enabled=false;
    dem->Enabled=false;
   //a_anim->Enabled=false;
   //Lancer1->Enabled=false;
   //Pause1->Enabled=false;
   //Arreter1->Enabled=false;
   //Evenement_de_panique1->Enabled=false;

   vu2d->Enabled=false;
    V2D->Enabled=false;
    vu3d->Enabled=false;
    V3D->Enabled=false;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------

void __fastcall TFormMain::V2DClick(TObject *Sender)
{

indiv->Enabled=true;
   individus->Enabled=true;

V2D->Checked=true  ;
V3D->Checked=false ;
v2d=true  ;
v3d=false ;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::V3DClick(TObject *Sender)
{
indiv->Enabled=false;
   individus->Enabled=false;

V3D->Checked=true  ;
V2D->Checked=false ;
vu2d->Enabled=true;
vu3d->Enabled=false;
v3d=true  ;
v2d=false ;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{


if(aller)
{
   se_deplacer();
}
//FormMain->DrawObjects();



 
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::AnimClick(TObject *Sender)
{
//Timer1->Enabled=true;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Lancer1Click(TObject *Sender)
{
  initial_matENV();
  individus-> Down=false;
    indicev=indicef=-1;
        if(nbmaxind)
                {

                    
                    if(!pause)
                        {
                           for(int i=1;i<=nbmaxind;i++)
                                {
                                 monde[i].position.I = monde[i].start.I ;
                                 monde[i].position.J = monde[i].start.J ;
                                 monde[i].chez_lui=false;
                                }
                           back_to_home();
                           Timer1->Enabled=true;
                           
                        }
                }


}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Pause1Click(TObject *Sender)
{
Timer1->Enabled=false;
//Timer2->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Arreter1Click(TObject *Sender)
{
Timer1->Enabled=false;
//Timer2->Enabled=false;

}
//---------------------------------------------------------------------------


void __fastcall TFormMain::initClick(TObject *Sender)
{
Timer1->Enabled=false;
Timer2->Enabled=false;
free(e);
//free(a);

Scene->Checked=false;

agt=false;

//
   //supp_agn->Enabled=false;
   //s_agent->Enabled=false;
   //indiv->Enabled=false;
   individus->Enabled=false;
   Reinit->Enabled=true;
   //l_anim->Enabled=false;
   //p_anim->Enabled=false;
    dem->Enabled=false;
   //a_anim->Enabled=false;
   //Lancer1->Enabled=false;
   //Pause1->Enabled=false;
   //Arreter1->Enabled=false;
   //Evenement_de_panique1->Enabled=false;

   vu2d->Enabled=false;
    V2D->Enabled=false;
    vu3d->Enabled=false;
    V3D->Enabled=false;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------

void __fastcall TFormMain::s_agentClick(TObject *Sender)
{
//s_agent->Down=true;

if(Scene->Enabled==false)
Scene->Enabled=true;

//a ->clean();
//free(a);

agt=false;
//supp_agn->Enabled=false;
//s_agent->Enabled=false;
if(V2D->Checked) 
{
//indiv->Enabled=true;
individus->Enabled=true;
}
//l_anim->Enabled=false;
//p_anim->Enabled=false;
dem->Enabled=false;
//a_anim->Enabled=false;
//Lancer1->Enabled=false;
//Pause1->Enabled=false;
//Arreter1->Enabled=false;
//Evenement_de_panique1->Enabled=false;
//agt_dess=false;

}
//---------------------------------------------------------------------------

void __fastcall TFormMain::l_animClick(TObject *Sender)
{
Timer1->Enabled=true;
Timer2->Enabled=true;        
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::p_animClick(TObject *Sender)
{
Timer1->Enabled=false;        
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::a_animClick(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------




//---------------------------------------------------------------------------


void __fastcall TFormMain::vu2dClick(TObject *Sender)
{
indiv->Enabled=true;
individus->Enabled=true;
V2D->Checked=true  ;
V3D->Checked=false ;
vu2d->Enabled=false;
vu3d->Enabled=true;
v2d=true  ;
v3d=false ;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::vu3dClick(TObject *Sender)
{
indiv->Enabled=false;
individus->Enabled=false;

V3D->Checked=true  ;
V2D->Checked=false ;
vu2d->Enabled=true;
vu3d->Enabled=false;
v3d=true  ;
v2d=false ;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Timer3Timer(TObject *Sender)
{
Timer3->Enabled=false;
//int r= Application->MessageBox("Vous voulez continuer ?","Test d'acceptation", MB_YESNO);
//if(r==IDNO)
  //{
   //free(e);
//free(a);
//Scene->Checked=false;


agt=false;
   //supp_agn->Enabled=false;
   //s_agent->Enabled=false;
   //indiv->Enabled=false;
   individus->Enabled=false;
   Reinit->Enabled=true;
   //l_anim->Enabled=false;
   //p_anim->Enabled=false;
     dem->Enabled=false;
   //a_anim->Enabled=false;
   //Lancer1->Enabled=false;
   //Pause1->Enabled=false;
   //Arreter1->Enabled=false;
   //Evenement_de_panique1->Enabled=false;

   vu2d->Enabled=false;
    V2D->Enabled=false;
    vu3d->Enabled=false;
    V3D->Enabled=false;
  //}

}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Timer4Timer(TObject *Sender)
{
Timer4->Enabled=false;
Timer1->Enabled=false;
Timer2->Enabled=false;
free(e);
//free(a);

Scene->Checked=false;

Scene->Enabled=true;

agt=false;

//
   //supp_agn->Enabled=false;
   //s_agent->Enabled=false;
   indiv->Enabled=false;
   individus->Enabled=false;
   Reinit->Enabled=true;
   //l_anim->Enabled=false;
   //p_anim->Enabled=false;
     dem->Enabled=false;
   //a_anim->Enabled=false;
   //Lancer1->Enabled=false;
   //Pause1->Enabled=false;
   //Arreter1->Enabled=false;
   //Evenement_de_panique1->Enabled=false;

   vu2d->Enabled=false;
    V2D->Enabled=false;
    vu3d->Enabled=false;
    V3D->Enabled=false;
}        

//---------------------------------------------------------------------------

void __fastcall TFormMain::RienitClick(TObject *Sender)
{


Scene->Enabled=true;
Timer1->Enabled=false;
Timer2->Enabled=false;
free(e);
//free(a);
Scene->Checked=false;


agt=false;

//
   individus->Down=false;
   //supp_agn->Enabled=false;
   //s_agent->Enabled=false;
   //indiv->Enabled=false;
   individus->Enabled=false;
   Reinit->Enabled=true;
   //l_anim->Enabled=false;
   //p_anim->Enabled=false;
   dem->Enabled=false;
   //a_anim->Enabled=false;
   //Lancer1->Enabled=false;
   //Pause1->Enabled=false;
   //Arreter1->Enabled=false;
   //Evenement_de_panique1->Enabled=false;
   vu2d->Enabled=false;
    V2D->Enabled=false;
    vu3d->Enabled=false;
    V3D->Enabled=false;
}

//---------------------------------------------------------------------------


void __fastcall TFormMain::Panel1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
 int ixpos,iypos;
GLfloat r1 = (20.0 / Panel1->Width);
  GLfloat r2 = (20.0 / Panel1->Height);
  GLfloat r, W;
 // point p;

 if(agt_dess )
  {
       if (r1 < r2)
        {
           r = r2;
           W = Panel1->Height;
        }
      else
        {
           r = r1;
           W = Panel1->Width;
        }

     Xpos = ((X - W / 2.0) * r)+((e->col)/4.0)-3.5 ;
     Ypos = ((Y- W / 2.0 ) * r)+((e->lig)/4);;

     ixpos=Xpos-int(Xpos);
     if(ixpos>0.5)
       Xpos=int(Xpos)+1;
     else
       Xpos=int(Xpos) ;

    iypos=Ypos-int(Ypos);
    if(ixpos>0.5)
      Xpos=int(Xpos)+1;
    else
      Xpos=int(Xpos);

  if( individus->Down && nbmaxind<30)
  {
     if(!But1)
     {
       if((Xpos<e->col)&&(Ypos<e->lig)&&(e->get_val(Ypos*2,Xpos*2)==0) )
          {

            nbmaxind++;                                         //  e->get_val_id(Xpos,Ypos)
           
              monde[nbmaxind].start.I=monde[nbmaxind].position.I=Ypos*2;
              e->matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
               matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
               monde[nbmaxind].start.J=monde[nbmaxind].position.J=Xpos*2;
               e->matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
                matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
                    monde[nbmaxind].action=arrest;
                    monde[nbmaxind].chez_lui=false;
                    monde[nbmaxind].color.r=random(255)/255.0;  monde[nbmaxind].color.v=random(200)/255.0;
                     monde[nbmaxind].angle=0;
                    monde[nbmaxind].butaccessible=false;
                    monde[nbmaxind].longueurchemin=0;
                    monde[nbmaxind].direction=1;
                 point p;
               set_point(&p,Ypos,-2.0,Xpos);
                 //aff_individus();
               
            //e->init_ag(Xpos*2,Ypos*2,0.5,0.5);
             e->matENV[Ypos*2][Xpos*2].L=2; //occupée par un individu

                 individus_creation();
                 set_centre(p);
                 glPopMatrix();
    
            agt=true;
            But1=true;
          }
         /*else
         {
            ShowMessage("Place occupée ! ");

         }*/
       }
   else
   
         if((Xpos<e->col)&&(Ypos<e->lig)&&(e->get_val(Ypos*2,Xpos*2)==0) )
            {
               point p;
               set_point(&p,Ypos,-2.0,Xpos);
               glPushMatrix();
               monde[nbmaxind].goal.I=Ypos*2;
                e->matENV[Ypos*2][Xpos*2].ID.I=Ypos*2;
               monde[nbmaxind].goal.J= Xpos*2;
               e->matENV[Ypos*2][Xpos*2].ID.J=Xpos*2;
               
              aff_but();
               set_centre(p);
               glPopMatrix();
               But1=false;
            }

         /*else
          ShowMessage("Place occupée ! ");*/
   }

  if(nbmaxind==2)
  {
     //ShowMessage("Il y a assez de population");
       individus->Down = false;
       individus->Enabled = false;
      
  }
        
        //supp_agn->Enabled=true;
        //s_agent->Enabled=true;
        //l_anim->Enabled=true;
        //p_anim->Enabled=true;
        dem->Enabled=true;
        //a_anim->Enabled=true;
        //Lancer1->Enabled=true;
        //Pause1->Enabled=true;
        //Arreter1->Enabled=true;
        //Evenement_de_panique1->Enabled=true;

}


}
//---------------------------------------------------------------------------

 void initial_matENV()
 {  int i,j;
 for(i=0;i<40;i++)
 {
   for(j=0;j<60;j++)
   {
     matENV[i][j].L=e->get_val(i,j);
     //matENV[i][j].ID.I=e->matENV[i][j].ID.I;
     //matENV[i][j].ID.J=e->matENV[i][j].ID.J;
   }
 }
 }

 //////////////////////////
void __fastcall TFormMain::Timer2Timer(TObject *Sender)
{
 if(aller)
{
   se_deplacer();
}
 
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::demClick(TObject *Sender)
{
Timer1->Enabled=false;  aller=false;
int k=1,i;
  indicev=indicef=-1;
  for(i=1;i<=nbmaxind ;i++)
  {
    monde[i].goal.I=0;
    monde[i].goal.J=0;
    }
           for(i=1;i<=nbmaxind ;i++)
            {    monde[i].start.I=monde[i].position.I=pospi[i].I;
                               e->matENV[pospi[i].I][pospj[i].J].ID.I=pospi[i].I;
                               matENV[pospi[i].I][pospj[i].J].ID.I=pospi[i].I;
                               monde[i].start.J=monde[i].position.J=pospj[i].J;
                               e->matENV[pospi[i].I][pospj[i].J].ID.J=pospj[i].J;
                               matENV[pospi[i].I][pospj[i].J].ID.J=pospj[i].J;
                               monde[i].action=arrest;
                               monde[i].chez_lui=false;
                               //monde[i].color.r=random(255)/255.0;  monde[nbmaxind].color.v=random(200)/255.0;
                               monde[i].angle=0;
                               monde[i].butaccessible=false;
                               monde[i].longueurchemin=0;
                               monde[i].direction=1;
                    if(pospi[i].I<20)
                    {
                                
                                 monde[i].goal.I=2;
                                 monde[i].goal.J=30;

                      }
                        if(pospi[i].I>=20)
                              {  
                                 monde[i].goal.I=39;
                                 monde[i].goal.J=14;

                              }
            }
        if(nbmaxind)
                {


                    if(!pause)
                        {
                           for(i=1;i<=nbmaxind;i++)
                                {   
                                 monde[i].position.I = monde[i].start.I;//=pospi[i].I ;
                                 monde[i].position.J = monde[i].start.J;//=pospj[i].J ;
                                 monde[i].chez_lui=false;
                                }
                            
                           back_to_home1();
                           Timer2->Enabled=true;
                           
                        }
                }



}
//---------------------------------------------------------------------------






 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) MATRICE DE ROTATION, QUATERNION ET 3D par CGSI3
Source avec Zip Source avec une capture [GAMBAS] CLIENT FROG CREATOR par astralien3000
Source avec Zip Source avec une capture OPENGL AVEC VB6 par CGSI3
Source avec une capture BASSBOX (AUDIO + OPENGL VISUAL PLUGINS) par Zap
Source avec Zip MODÉLISATION STATISTIQUES par tandan

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture QUICKWAYTOFOLDERS par yex
Source avec Zip Source avec une capture EXTENSION DU SHELL : MENU CONTEXTUEL (WIN32 API) par racpp
Source avec Zip Source avec une capture WINDOG LE CHIEN par magma
Source avec Zip YOUPI LE PINGOUIN par magma
Source avec Zip Source avec une capture DESSIN SUR ÉCRAN (TRÈS SIMPLE) par ordiman85

Commentaires et avis

Commentaire de LETARTARE le 30/05/2011 10:03:50

Bonjour,
l'affichage du code s'arrête à la ligne 1820 !! donc difficile à analyser.

Commentaire de TeddyBear94 le 31/05/2011 10:15:25

Bonjour,
Pourquoi avoir tout mis dans le même fichier, ça rend le tout assez dur à lire...
Tu mélanges anglais et français dans ton source, le français est à éviter dans le code.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

zut g un prob [ par FUCKMAN ] g un prob ca me dis c:\windows\bureau\untitled1.cpp:2: ANSI C++ forbids declaration `remove' with no typec:\windows\bureau\untitled1.cpp:2: initializa Redessiner le Bureau [ par ZoB ] SalutDans un prog j'affiche le papierpeint sur l'ecran a l'aide de : HDC hdc = CreateDC("DISPLAY",0,0,0); PaintDesktop(hdc);Quand je quitte l'applica Redessiner le Bureau [ par ZoB ] SalutDans un prog j'affiche le papierpeint sur l'ecran a l'aide de : HDC hdc = CreateDC("DISPLAY",0,0,0); PaintDesktop(hdc);Quand je quitte l'applica fenetre transparente [ par pipo ] je cree une fenetre transparente avec WS_EX_TRANSPARENT mais le probleme c'est que quand je deplace ma fenetre le fond de la fenetre (le bureau de win probleme de fenetre transparente [ par pipo ] je cree une fenetre transparente avec WS_EX_TRANSPARENT mais le probleme c'est que quand je deplace ma fenetre le fond de la fenetre (le bureau de win Comment afficher un bouton sur le bureau de Windows [ par Haldwin ] Salut,je cherche deseperement le code pour créer un executable qui affiche par exemple un bouton sur le bureau de Windows c'est a dire que la fenetre wallpaper [ par Win32 ] Alors là, je sais plus quoi faire : La fonction SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\bitmap.bmp", SPIF_UPDATEINIFILE);ne fais rien ! Le Rafraichissement du bureau [ par Xentor609 ] Re-Salut,Je cherche une fonction permettant de changer l'ecran de fond du bureau.J'utilise la fonction SystemParametersInfo(), mais le bureau est chan Raffraichir le bureau [ par TryIt ] J'arrive à écrire sur le bureau de windows mais je n'arrive pas à effacer le texte.Si quelqu'un avait un exemple pour ecrivre du texte sur le bureau p Image sur le bureau [ par moimoimoi3x ] Bonjour Je voudrai savoir comment afficher une image sur le bureau comme un iconedonc que son parent soit le desktopd un simple click ouvrir un bimap


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,421 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales