2
2
#include < SDL2/SDL.h>
3
3
#include " Actor.hpp"
4
4
#include < iostream>
5
- using namespace std ;
6
5
7
- SDL_Window* win = NULL ;
8
- SDL_Surface* surface = NULL ;
9
- SDL_Renderer* render = NULL ;
6
+ const int WIDTH = 8 ; // metres
7
+ const int HEIGHT = 6 ; // metres
8
+ const int SCALE = 100 ;
10
9
11
- const int WIDTH = 800 ;
12
- const int HEIGHT = 600 ;
13
-
14
- void init () {
10
+ void init (SDL_Window* win, SDL_Renderer* render, std::vector<Actor> &actors) {
15
11
SDL_Init (SDL_INIT_VIDEO);
16
- win = SDL_CreateWindow (" SYCL Crowd Simulation" , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
12
+ win = SDL_CreateWindow (" SYCL Crowd Simulation" , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SCALE , HEIGHT * SCALE , SDL_WINDOW_SHOWN);
17
13
render = SDL_CreateRenderer (win, -1 , SDL_RENDERER_ACCELERATED);
14
+
15
+ actors.push_back (Actor{{1 ,2 }, {3 ,4 }, {5 ,6 }, 3 , 4 });
18
16
}
19
17
20
- void draw () {
18
+ void drawCircle (SDL_Renderer* render, SDL_Point center, int radius, SDL_Color color) {
19
+ SDL_SetRenderDrawColor (render, color.r , color.g , color.b , color.a );
20
+ for (int w = 0 ; w < radius * 2 ; w++) {
21
+ for (int h = 0 ; h < radius * 2 ; h++) {
22
+ int dx = radius - w;
23
+ int dy = radius - h;
24
+ if ((dx*dx + dy*dy) <= (radius * radius)) {
25
+ SDL_RenderDrawPoint (render, center.x + dx, center.y + dy);
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ void draw (SDL_Renderer* render, std::vector<Actor> &actors) {
21
32
SDL_SetRenderDrawColor (render, 255 , 255 , 255 , 255 );
22
33
SDL_RenderClear (render);
23
34
35
+
36
+
24
37
SDL_RenderPresent (render);
25
38
}
26
39
27
- void close () {
40
+ void close (SDL_Window* win ) {
28
41
SDL_DestroyWindow (win);
29
42
SDL_Quit ();
30
43
}
31
44
32
45
int main () {
33
- init ();
46
+ SDL_Window* win = NULL ;
47
+ SDL_Surface* surface = NULL ;
48
+ SDL_Renderer* render = NULL ;
49
+
50
+ std::vector<Actor> actors;
51
+
52
+ init (win, render, actors);
34
53
35
- draw ();
54
+ draw (render, actors );
36
55
37
56
Actor test = Actor ({0 , 2 }, {3 , 4 }, {5 ,6 }, 12 , 3 );
38
57
@@ -46,9 +65,9 @@ int main() {
46
65
}
47
66
}
48
67
49
- draw ();
68
+ draw (render, actors );
50
69
}
51
70
52
- close ();
71
+ close (win );
53
72
return 0 ;
54
73
}
0 commit comments