Skip to content
Snippets Groups Projects
Commit 8a67bed2 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

fonction lagrangeInterpolation (pour trajectoire) + commentaires et clean

parent 5b97eba0
No related branches found
No related tags found
No related merge requests found
#include "ball.h"
ball_t ball;
laGrange_t coefLagrange;
int trajectory[NUMBERPOINT][2];
int trajectoireAntoine[20][2];
ball_t ball;
int trajectoireAntoine[NUMBERPOINT_TRAJEC][2];
void initBall (){
}
double f(int x, float xc, float yc, float xf, float yf, float xt, float yt){
double returnValue = yf * ((x - xc)/(xf - xc)) * ((x - xt)/(xf - xt)) + yc * ((x - xf)/(xc - xf)) * ((x - xt)/(xc - xt)) + yt * ((x - xc)/(xt - xc)) * ((x - xf)/(xt - xf));
return returnValue;
}
void laGrange (float beta[3],float Z[3]){ // y , x
printf("x canon : %f, x chute : %f, x filet : %f\n", Z[0], Z[1], Z[2]);
printf("y canon : %f, y chute : %f, y filet : %f\n", beta[0], beta[1], beta[2]);
coefLagrange.a= Z[0]/((beta[0]-beta[1])*(beta[0]-beta[2]))
+Z[1]/((beta[1]-beta[0])*(beta[1]-beta[2]))
+Z[2]/((beta[2]-beta[0])*(beta[2]-beta[1]));
coefLagrange.b= -(Z[0]*(beta[1]+beta[2]))/((beta[0]-beta[1])*(beta[0]-beta[2]))
-(Z[1]*(beta[0]+beta[2]))/((beta[1]-beta[0])*(beta[1]-beta[2]))
-(Z[2]*(beta[0]+beta[1]))/((beta[2]-beta[0])*(beta[2]-beta[1]));
coefLagrange.c= (Z[0]*beta[1]*beta[2])/((beta[0]-beta[1])*(beta[0]-beta[2]))
+(Z[1]*beta[0]*beta[2])/((beta[1]-beta[0])*(beta[1]-beta[2]))
+(Z[2]*beta[0]*beta[1])/((beta[2]-beta[0])*(beta[2]-beta[1]));
void initBall()
{
}
float defineAngle (canon_t canon, int xDropPoint, int yDropPoint){
float defineAngle(int canonX, int canonY, int xDropPoint, int yDropPoint)
{
float distance;
float angleSin;
distance= sqrtf( powf((float)(xDropPoint-canon.x),2)+powf((float)(yDropPoint-canon.y),2));
angleSin = asinf(distance/(xDropPoint-canon.x));
distance = sqrtf(powf((float)(xDropPoint - canonX), 2) + powf((float)(yDropPoint - canonY), 2));
angleSin = asinf(distance / (xDropPoint - canonX));
return angleSin;
}
void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
int i;
float setUp[2][3];
float distance= (float)(yDropPoint-canon.y);
//printf("test : %f\n", y);
trajectory[0][0]=canon.y;
trajectory[0][1]=canon.x;
trajectory[NUMBERPOINT-1][0]=yDropPoint;
trajectory[NUMBERPOINT-1][1]=xDropPoint;
setUp[1][0]=(float)canon.y;
setUp[0][0]=canon.x;
setUp[1][1]=(float)yDropPoint;
setUp[0][1]=xDropPoint;
//setUp[0][2]=(13.40/2);// distance du filet dans le repère de frappe
//filet X
//terrain.w = 5.20 * zoom;
// setUp[0][2] = terrain.x + terrain.w + 50 + (13.40 * zoom)/2 -2;
setUp[0][2] = 50 + 5.20 * 40 + 50 + (13.40 * 40)/2 - 2;
//filet Y
// drawerTerrainSideView.y - 1,55 * zoom
// drawerTerrainSideView.y = terrain.y + terrain.h;
//terrain.h = 13.40 * zoom
//setUp[1][2] = 1.55*40; /// hauteur du filet
setUp[1][2] = 50 + 13.40 * 40 - 3.55 * 40;
laGrange(setUp[1],setUp[0]); //laGrange(y, x);
//printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c);
float step= distance / (NUMBERPOINT-1);
for (i=1; i<NUMBERPOINT-1; i++){
trajectory[i][0]=(int)((float)canon.y + i*step);
trajectory[i][1]=(int)(coefLagrange.c+
coefLagrange.b*((float)canon.y + i*step)+
coefLagrange.a*(powf((float)canon.y + i*step,2)));
}
}
//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;
/*
* Fonction qui prend une valeur de x et 3 points. Elle
* renvoie la coordonnée y liée à la valeur de x sur la
* courbe passant par les 3 points.
* Valeur de x : float xp
* Point n°1 (départ) : int xd, int yd
* Point n°2 (filet ) : int xf, int yf
* Point n°3 (target) : int xt, int yt
*/
int lagrangeInterpolation(float xp, int xd, int yd, int xf, int yf, int xt, int yt)
{
float x[4], y[4], yp = 0, p;
int i, j, n;
// nombre de points pour trouver la courbe
n = 3;
// coordonnées x des 3 points
x[1] = xd;
x[2] = xf;
x[3] = xt;
// coordonnées y des 3 points
y[1] = yd;
y[2] = yf;
y[3] = yt;
/* Implementing Lagrange Interpolation */
for(i=1;i<=n;i++)
// implementation de l'interpolation de Lagrange
for (i = 1; i <= n; i++)
{
p=1;
for(j=1;j<=n;j++)
p = 1;
for (j = 1; j <= n; j++)
{
if(i!=j)
if (i != j)
{
p = p* (xp - x[j])/(x[i] - x[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);
// affichage pouvant servir
// printf("Interpolated value at %.3f is %.3f.\n", xp, yp);
// valeur de y associée à xp sur la courbe
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;
/*
* Fonction qui prend en paramètres 3 points et retourne met dans le
* tableau à 2 dimensions trajectoireAntoine la liste des points de
* la courbe qui passe par ces 3 points. Le pas de temps est defini
* par NUMBERPOINT_TRAJEC.
*/
void calculTrajectoireAntoine2(int xd, int yd, int xf, int yf, int xt, int yt)
{
// pas de temps
int pas_de_temps = (xt - xd) / (NUMBERPOINT_TRAJEC - 1);
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);
}
// point de départ
trajectoireAntoine[0][0] = xd;
trajectoireAntoine[0][1] = yd;
// on cherche les pas de temps pour tous les pas de temps
// sauf départ et arrivée
for (i = 1; i < NUMBERPOINT_TRAJEC - 1; i++)
{
// calcul du x
trajectoireAntoine[i][0] = (int)(xd + i * pas_de_temps);
// calcul du y
trajectoireAntoine[i][1] = lagrangeInterpolation(trajectoireAntoine[i][0], xd, yd, xf, yf, xt, yt);
}
// point d'arrivée
trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][0] = xt;
trajectoireAntoine[NUMBERPOINT_TRAJEC - 1][1] = yt;
}
......@@ -5,41 +5,31 @@
#include <time.h>
#include <stdio.h>
#include <math.h>
#include "canon.h"
#define NUMBERPOINT 200
#define NUMBERPOINT_TRAJEC 50
typedef enum {
false,true
}booleen_t;
typedef enum
{
false,
true
} booleen_t;
typedef struct ball {
int x;
int y;
typedef struct ball
{
int x;
int y;
int z;
float angle;
float speed;
}ball_t;
typedef struct laGrange{
float a;
float b;
float c;
}laGrange_t;
float speed;
} ball_t;
extern ball_t ball;
extern laGrange_t coefLagrange;
extern int trajectory[NUMBERPOINT][2];
extern int trajectoireAntoine[20][2];
extern int trajectoireAntoine[NUMBERPOINT_TRAJEC][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);
void initBall();
float defineAngle(int, int, int, int);
int calculTrajectoireAntoine(float, int, int, int, int, int, int);
int lagrangeInterpolation(float, int, int, int, int, int, int);
void calculTrajectoireAntoine2(int, int, int, int, int, int);
#endif
\ No newline at end of file
#endif
\ No newline at end of file
......@@ -8,40 +8,44 @@ int window_height = 700;
TTF_Font *robotoFont;
int zoom = 40;
//terrain devrait etre un .c et .h comme canon
// on aurait un SDL_Rect en terrain TopView et SideView
//là mélange bizarre mais fonctionnel
// terrain devrait etre un .c et .h comme canon
// on aurait un SDL_Rect en terrain TopView et SideView
// là mélange bizarre mais fonctionnel
SDL_Rect terrain;
SDL_Rect drawerTerrainSideView; // drawerTerrain pour les deux vues
SDL_Rect filet;
//drawerFilet
// drawerFilet
//canon est un .c
// canon est un .c
SDL_Rect drawerCanon;
//point de chute devrait etre un .c et .h
// point de chute devrait etre un .c et .h
SDL_Rect point_de_chute;
SDL_Rect drawerPointDeChute;
int zone_chute = -1;
void createWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
void createWindow()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Couldn't create window.");
exit(EXIT_FAILURE);
}
window = SDL_CreateWindow("Badminton learning", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_RESIZABLE);
if (window == NULL){
if (window == NULL)
{
printf("Couldn't create window");
exit(EXIT_FAILURE);
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL){
if (renderer == NULL)
{
printf("Couldn't create renderer.");
exit(EXIT_FAILURE);
}
......@@ -51,10 +55,11 @@ void createWindow(){
exit(EXIT_FAILURE);
}
robotoFont = TTF_OpenFont("assets/Roboto-Black.ttf", 50);
robotoFont = TTF_OpenFont("assets/Roboto-Black.ttf", 50);
}
void endSDL(){
void endSDL()
{
TTF_CloseFont(robotoFont);
TTF_Quit();
SDL_DestroyRenderer(renderer);
......@@ -62,51 +67,60 @@ void endSDL(){
SDL_Quit();
}
void initTerrain(){
void initTerrain()
{
terrain.x = 50;
terrain.y = 50;
terrain.y = 50;
terrain.h = 13.40 * zoom;
terrain.w = 5.20 * zoom;
}
void initPointDeChute(){
void initPointDeChute()
{
point_de_chute.w = 5;
point_de_chute.h = 5;
srand(time(NULL));
point_de_chute.x = (int)rand()%terrain.w;
point_de_chute.y = (int)rand()%(terrain.h/2);
point_de_chute.x = (int)rand() % terrain.w;
point_de_chute.y = (int)rand() % (terrain.h / 2);
}
int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){
int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH)
{
int z = -1;
// pdc = point de chute
int pdc_y = terrainY + terrainH/2 + point_de_chute.y;
//en haut à gauche => 1
if(point_de_chute.x<terrainW/2 && pdc_y<terrainY+(3*terrainH)/4){
int pdc_y = terrainY + terrainH / 2 + point_de_chute.y;
// en haut à gauche => 1
if (point_de_chute.x < terrainW / 2 && pdc_y < terrainY + (3 * terrainH) / 4)
{
z = 1;
}
//en haut à droite => 2
else if(point_de_chute.x>=terrainW/2 && pdc_y<terrainY+(3*terrainH)/4){
// en haut à droite => 2
else if (point_de_chute.x >= terrainW / 2 && pdc_y < terrainY + (3 * terrainH) / 4)
{
z = 2;
}
//en bas à gauche => 3
else if(point_de_chute.x<terrainW/2 && pdc_y>=terrainY+(3*terrainH)/4){
// en bas à gauche => 3
else if (point_de_chute.x < terrainW / 2 && pdc_y >= terrainY + (3 * terrainH) / 4)
{
z = 3;
}
//en bas à droite => 4
else{
// en bas à droite => 4
else
{
z = 4;
}
return z;
}
void newCanon(){
void newCanon()
{
srand(time(NULL));
canon.x = (int)rand()%terrain.w;
canon.y = (int)rand()%(terrain.h/2);
canon.x = (int)rand() % terrain.w;
canon.y = (int)rand() % (terrain.h / 2);
}
void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int a){
void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int a)
{
SDL_Color color = {r, g, b, a};
SDL_Surface *surface = TTF_RenderText_Solid(robotoFont, text, color);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
......@@ -116,216 +130,175 @@ void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int
SDL_DestroyTexture(texture);
}
void drawTerrainTopView(){
//filet
void drawTerrainTopView()
{
// filet
filet.x = terrain.x;
filet.h = 4;
filet.y = terrain.y + terrain.h/2 - filet.h/2;
filet.y = terrain.y + terrain.h / 2 - filet.h / 2;
filet.w = terrain.w;
//terrain en blanc
// terrain en blanc
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &terrain);
//filet en vert
// filet en vert
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &filet);
//decoupage des zones
// decoupage des zones
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
//verticale zone haut
SDL_RenderDrawLine(renderer, terrain.x+terrain.w/2, terrain.y, terrain.x+terrain.w/2, terrain.y+terrain.h/2);
//horizontale zone haut
SDL_RenderDrawLine(renderer, terrain.x, terrain.y+terrain.h/4, terrain.x+terrain.w, terrain.y+terrain.h/4);
//verticale bas
SDL_RenderDrawLine(renderer, terrain.x+terrain.w/2, terrain.y+terrain.h/2, terrain.x+terrain.w/2, terrain.y+terrain.h);
//horizontale bas
SDL_RenderDrawLine(renderer, terrain.x, terrain.y+(3*terrain.h)/4, terrain.x+terrain.w, terrain.y+(3*terrain.h)/4);
// verticale zone haut
SDL_RenderDrawLine(renderer, terrain.x + terrain.w / 2, terrain.y, terrain.x + terrain.w / 2, terrain.y + terrain.h / 2);
// horizontale zone haut
SDL_RenderDrawLine(renderer, terrain.x, terrain.y + terrain.h / 4, terrain.x + terrain.w, terrain.y + terrain.h / 4);
// verticale bas
SDL_RenderDrawLine(renderer, terrain.x + terrain.w / 2, terrain.y + terrain.h / 2, terrain.x + terrain.w / 2, terrain.y + terrain.h);
// horizontale bas
SDL_RenderDrawLine(renderer, terrain.x, terrain.y + (3 * terrain.h) / 4, terrain.x + terrain.w, terrain.y + (3 * terrain.h) / 4);
}
void drawTerrainSideView(){
//terrain
void drawTerrainSideView()
{
// terrain
drawerTerrainSideView.x = terrain.x + terrain.w + 50;
drawerTerrainSideView.y = terrain.y + terrain.h;
drawerTerrainSideView.y = terrain.y + terrain.h;
drawerTerrainSideView.h = 4;
drawerTerrainSideView.w = 13.40 * zoom;
//filet
// filet
filet.w = 4;
filet.x = drawerTerrainSideView.x + drawerTerrainSideView.w/2 - filet.w/2;
filet.x = drawerTerrainSideView.x + drawerTerrainSideView.w / 2 - filet.w / 2;
filet.h = -1.55 * zoom;
filet.y = drawerTerrainSideView.y;
//terrain en blanc
filet.y = drawerTerrainSideView.y;
// terrain en blanc
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &drawerTerrainSideView);
//filet en vert
// filet en vert
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &filet);
}
void drawCanonTopView(){
//canon
drawerCanon.w = canon.width;
void drawCanonTopView()
{
// canon
drawerCanon.w = canon.width;
drawerCanon.h = canon.length;
drawerCanon.x = terrain.x + canon.x;
drawerCanon.y = terrain.y + canon.y;
//canon en noir
// canon en noir
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &drawerCanon);
}
void drawPointDeChuteTopView(){
//point de chute de la balle
void drawPointDeChuteTopView()
{
// point de chute de la balle
drawerPointDeChute.x = terrain.x + point_de_chute.x;
drawerPointDeChute.y = terrain.y + terrain.h/2 + point_de_chute.y;
drawerPointDeChute.y = terrain.y + terrain.h / 2 + point_de_chute.y;
drawerPointDeChute.w = point_de_chute.w;
drawerPointDeChute.h = point_de_chute.h;
//point de chute de la balle
// point de chute de la balle
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &drawerPointDeChute);
}
void drawCanonSideView(){
//canon
drawerCanon.w = canon.length;
void drawCanonSideView()
{
// canon
drawerCanon.w = canon.length;
drawerCanon.h = canon.height;
drawerCanon.x = drawerTerrainSideView.x + canon.y;
drawerCanon.y = drawerTerrainSideView.y - canon.height;
//canon en noir
// canon en noir
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &drawerCanon);
}
void drawPointDeChuteSideView(){
//point de chute de la balle
drawerPointDeChute.x = drawerTerrainSideView.x + drawerTerrainSideView.w/2 + point_de_chute.y;
void drawPointDeChuteSideView()
{
// point de chute de la balle
drawerPointDeChute.x = drawerTerrainSideView.x + drawerTerrainSideView.w / 2 + point_de_chute.y;
drawerPointDeChute.y = drawerTerrainSideView.y;
drawerPointDeChute.w = point_de_chute.w;
drawerPointDeChute.h = point_de_chute.h;
//point de chute de la balle
// point de chute de la balle
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &drawerPointDeChute);
}
void drawInformations(){
void drawInformations()
{
int texte_width = 200;
int texte_height = 40;
char str[20];
char str2[20];
char zoneChuteChaine[20] = "zone chute :";
char zoneCanonChaine[20] = "zone canon :";
drawString("informations :", window_width-texte_width, texte_height*0, texte_width, texte_height, 255, 255, 255, 255);
drawString("e : new point chute", window_width-texte_width, texte_height*1, texte_width, texte_height, 255, 255, 255, 255);
drawString("informations :", window_width - texte_width, texte_height * 0, texte_width, texte_height, 255, 255, 255, 255);
drawString("e : new point chute", window_width - texte_width, texte_height * 1, texte_width, texte_height, 255, 255, 255, 255);
sprintf(str2, "%d", zone_chute);
strcat(zoneChuteChaine, str2);
drawString(zoneChuteChaine, window_width-texte_width, texte_height*2, texte_width, texte_height, 255, 255, 255, 255);
drawString("r : new canon", window_width-texte_width, texte_height*4, texte_width, texte_height, 255, 255, 255, 255);
drawString(zoneChuteChaine, window_width - texte_width, texte_height * 2, texte_width, texte_height, 255, 255, 255, 255);
drawString("r : new canon", window_width - texte_width, texte_height * 4, texte_width, texte_height, 255, 255, 255, 255);
sprintf(str, "%d", canon.zone);
strcat(zoneCanonChaine, str);
drawString(zoneCanonChaine, window_width-texte_width, texte_height*5, texte_width, texte_height, 255, 255, 255, 255);
drawString(zoneCanonChaine, window_width - texte_width, texte_height * 5, texte_width, texte_height, 255, 255, 255, 255);
}
void drawTrajectoireTopView(){
void drawTrajectoireTopView()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderDrawLine(renderer, terrain.x+canon.x, terrain.y+canon.y, drawerPointDeChute.x, drawerPointDeChute.y);
SDL_RenderDrawLine(renderer, terrain.x + canon.x, terrain.y + canon.y, drawerPointDeChute.x, drawerPointDeChute.y);
}
void drawTrajectoireSideView(){
/*canon_t canon_trajectoire_sideview;
canon_trajectoire_sideview.y = drawerTerrainSideView.x + canon.y;
canon_trajectoire_sideview.x = drawerTerrainSideView.y;*/
/*drawerPointDeChute.y = terrain.y + terrain.h;
calculationTrajectory(canon_trajectoire_sideview,
drawerPointDeChute.y,
drawerPointDeChute.x
);*/
//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]);*/
void drawTrajectoireSideView()
{
// crée la liste des points de la trajectoire
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]);
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
);
// parcours la liste des points de la trajectoire et l'affiche
for (int i = 0; i < NUMBERPOINT_TRAJEC - 1; i++)
{
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]);
SDL_RenderDrawLine(renderer, trajectoireAntoine[i][0], trajectoireAntoine[i][1], trajectoireAntoine[i + 1][0], trajectoireAntoine[i + 1][1]);
}
}
void drawBall(){
/*int i;
SDL_Rect rect_life;
SDL_Rect rect_mana;
rect_life.h = 50;
rect_life.w = 50;
rect_life.x = 100;
rect_life.y = 100;
rect_mana.h = 50;
rect_mana.w = 50;
rect_mana.x = 100;
rect_mana.y = 200;*/
//draw hero life
/*SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for(i=0; i<hero.life; i++){
SDL_RenderFillRect(renderer, &rect_life);
rect_life.x = rect_life.x + rect_life.w + 20;
}
//draw hero mana
*/
}
void mainLoop(){
void mainLoop()
{
createWindow();
initCanon();
initTerrain();
initPointDeChute();
pthread_t eventThread;
if (pthread_create(&eventThread, NULL, eventLoop, NULL) != 0){
if (pthread_create(&eventThread, NULL, eventLoop, NULL) != 0)
{
printf("Couldn't create thread.");
exit(EXIT_FAILURE);
}
while (running){
while (running)
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
//top view
// top view
drawTerrainTopView();
drawCanonTopView();
drawPointDeChuteTopView();
......@@ -333,16 +306,16 @@ void mainLoop(){
canon.zone = getZone(terrain.x, terrain.y, terrain.w, terrain.h);
zone_chute = getZoneChute(terrain.x, terrain.y, terrain.w, terrain.h);
//side view
// side view
drawTerrainSideView();
drawCanonSideView();
drawPointDeChuteSideView();
drawTrajectoireSideView();
//
drawInformations();
SDL_RenderPresent(renderer);
}
endSDL();
}
\ No newline at end of file
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment