diff --git a/travail_de_groupe/jeu_appren_par_renfo/RessourcesCommunesJeuRenforcement.pdf b/travail_de_groupe/jeu_appren_par_renfo/RessourcesCommunesJeuRenforcement.pdf new file mode 100644 index 0000000000000000000000000000000000000000..afd8352e3ab2fa1e70ffcd07ca67a708b59333a7 Binary files /dev/null and b/travail_de_groupe/jeu_appren_par_renfo/RessourcesCommunesJeuRenforcement.pdf differ diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/.vscode/settings.json b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..e73ddc2823c9032f30f6dff22576d4a86c1037b8 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "ball.h": "c" + } +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c index 0be83169cf086c36035b8877815bcbbfd5a772d1..a133204c8c37359fa7bd7ec740465d813c82de23 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.c @@ -3,6 +3,7 @@ ball_t ball; laGrange_t coefLagrange; int trajectory[NUMBERPOINT][2]; +int trajectoireAntoine[20][2]; void initBall (){ @@ -47,7 +48,7 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){ float distance= (float)(yDropPoint-canon.y); - printf("test : %f\n", y); + //printf("test : %f\n", y); trajectory[0][0]=canon.y; trajectory[0][1]=canon.x; @@ -84,4 +85,60 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){ coefLagrange.b*((float)canon.y + i*step)+ coefLagrange.a*(powf((float)canon.y + i*step,2))); } -} \ No newline at end of file +} + +//output of Lagrange interpolation method is obtained in yp +//xp is interpolation point given by user +//xd : x depart +//yd : y depart +//xt : x target +//yt : y target +// DONNE UN POINT +int calculTrajectoireAntoine(float xp, int xd, int yd, int xf, int yf, int xt, int yt){ + float x[100], y[100], yp=0, p; + int i,j,n; + n = 3; + + x[1] = xd; + x[2] = xf; + x[3] = xt; + + y[1] = yd; + y[2] = yf; + y[3] = yt; + + /* Implementing Lagrange Interpolation */ + for(i=1;i<=n;i++) + { + p=1; + for(j=1;j<=n;j++) + { + if(i!=j) + { + p = p* (xp - x[j])/(x[i] - x[j]); + } + } + yp = yp + p * y[i]; + } + printf("Interpolated value at %.3f is %.3f.\n", xp, yp); + return yp; +} + +// utilise calculTrajectoireAntoine pour +// calculer une liste de point a tracer + +void calculTrajectoireAntoine2(int xd, int yd, int xf, int yf, int xt, int yt){ + // on calcule 20 points + + int pas_de_temps = (xt-xd)/19; + int i; + for (i=0; i<19; i++){ + // x + trajectoireAntoine[i][0] = (int)(xd + i*pas_de_temps); + // y + trajectoireAntoine[i][1] = calculTrajectoireAntoine(trajectoireAntoine[i][0], xd, yd, xf, yf, xt, yt); + } +} + + + diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.h b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.h index 334afad9b47511dbdfb3af4a56d71673e2aba21a..ad39494fc70dfa0a5504eae595649f13c971b313 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.h +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/ball.h @@ -31,10 +31,15 @@ extern ball_t ball; extern laGrange_t coefLagrange; extern int trajectory[NUMBERPOINT][2]; +extern int trajectoireAntoine[20][2]; + void initBall(); void laGrange(float *, float *); float defineAngle(canon_t, int, int); //void calculationTrajectory(canon_t, int, int, int, int); void calculationTrajectory(canon_t, int, int); +int calculTrajectoireAntoine(float, int, int, int, int, int, int); +void calculTrajectoireAntoine2(int, int, int, int, int, int); + #endif \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c index 0a682387ac387f6f0700f95a44fbee409cee7740..7ef04844b6b0def61debeb61e751c790f361a862 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c @@ -239,22 +239,47 @@ void drawTrajectoireTopView(){ } void drawTrajectoireSideView(){ - canon_t canon_trajectoire_sideview; + /*canon_t canon_trajectoire_sideview; canon_trajectoire_sideview.y = drawerTerrainSideView.x + canon.y; - canon_trajectoire_sideview.x = drawerTerrainSideView.y; + canon_trajectoire_sideview.x = drawerTerrainSideView.y;*/ - drawerPointDeChute.y = terrain.y + terrain.h; + /*drawerPointDeChute.y = terrain.y + terrain.h; calculationTrajectory(canon_trajectoire_sideview, drawerPointDeChute.y, drawerPointDeChute.x - ); - - for(int i=0; i<NUMBERPOINT-1; i++){ + );*/ + + + //int resultatAntoine = 0; + //resultatAntoine = calculTrajectoireAntoine(75.0, 0, 0, 50, 60, 100, 0); + /*calculTrajectoireAntoine2(0, -200, 50, 60, 100, -200); + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[5][0], trajectoireAntoine[5][1]); + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[6][0], trajectoireAntoine[6][1]); + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[7][0], trajectoireAntoine[7][1]);*/ + + calculTrajectoireAntoine2( + terrain.x + terrain.w + 50 + canon.y, //x depart + terrain.y + terrain.h, //y depart + terrain.x + terrain.w + 50 + terrain.h/2, //x filet + terrain.y + terrain.h - 100, //y filet + drawerTerrainSideView.x + drawerTerrainSideView.w/2 + point_de_chute.y, // x target + terrain.y + terrain.h); // y target + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[5][0], trajectoireAntoine[5][1]); + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[6][0], trajectoireAntoine[6][1]); + printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[7][0], trajectoireAntoine[7][1]); + + for(int i=0; i<18; i++){ //printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]); - SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); - SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]); + SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255); + SDL_RenderDrawLine(renderer, trajectoireAntoine[i][0], trajectoireAntoine[i][1], trajectoireAntoine[i+1][0], trajectoireAntoine[i+1][1]); + //SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]); } + + + + + } void drawBall(){