-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawTrace.c
61 lines (46 loc) · 1.37 KB
/
drawTrace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "defines.h"
void drawTrace(Position oldPosition, Position position, SDL_Surface* ecran)
{
/* AFFICHAGE NOUVEAU POINT */
//# SDL_Surface *mouseTrace = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 32, 0, 255, 0, 0);
Uint32 color = SDL_MapRGB(ecran->format, 180, 0, 0);
// Hide real cursor
drawDot(ecran, position.x, position.y, color);
// Blit onto main surface
//# SDL_BlitSurface(mouseTrace, NULL, ecran, &dst);
/* AFFICHAGE MOITIE (completion) */
if (!seCroisent(position, oldPosition)){
// calc milieu
// afficher milieu
// draw gauche
// draw droite
Position milieu;
milieu.x = (position.x + oldPosition.x)/2;
milieu.y = (position.y + oldPosition.y)/2;
drawDot(ecran, milieu.x, milieu.y, color);
drawTrace(position, milieu, ecran);
drawTrace(milieu, oldPosition, ecran);
}
}
void drawDot(SDL_Surface* ecran, int x, int y, Uint32 color)
{
SDL_Rect dst;
dst.w = 5;
dst.h = 3;
dst.x = LARGEUR - x;
dst.y = y;
SDL_FillRect(ecran, &dst, color);
dst.w = 3;
dst.h = 5;
dst.x += 1;
dst.y -= 1;
SDL_FillRect(ecran, &dst, color);
}
int seCroisent(Position p1, Position p2){
Position vecteur;
vecteur.x = p2.x - p1.x;
vecteur.y = p2.y - p1.y;
int normeCarre = vecteur.x * vecteur.x + vecteur.y * vecteur.y;
return normeCarre < 25;
// return ((p1.x-p2.x <= 5 || p1.y - p2.y <= 5) || (p2.x-p1.x <= 5 || p2.y - p1.y <= 5));
}