forked from sferes2/fastsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastsim_keyboard.cpp
58 lines (48 loc) · 1.47 KB
/
fastsim_keyboard.cpp
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
#include <boost/foreach.hpp>
#include "simu_fastsim.hpp"
using namespace sferes;
struct Params {
struct simu {
SFERES_STRING(map_name, "modules/fastsim/cuisine.pbm");
SFERES_CONST float dt = 0.01;
};
};
#ifdef USE_SDL
int main(int argc, char *argv[]) {
using namespace fastsim;
typedef simu::Fastsim<Params> simu_t;
simu_t s;
s.robot().set_pos(Posture(250, 250, 0));
s.robot().use_camera();
s.robot().add_laser(Laser(M_PI / 3, 50));
s.robot().add_laser(Laser(0, 50));
s.robot().add_laser(Laser(-M_PI / 3, 50));
Map::ill_sw_t s1 = Map::ill_sw_t(new IlluminatedSwitch(1, 10, 300, 251, true));
Map::ill_sw_t s2 = Map::ill_sw_t(new IlluminatedSwitch(2, 10, 530, 150, true));
Map::ill_sw_t s3 = Map::ill_sw_t(new IlluminatedSwitch(3, 10, 200, 150, true));
Map::ill_sw_t s4 = Map::ill_sw_t(new IlluminatedSwitch(4, 10, 400, 350, true));
s.map()->add_illuminated_switch(s1);
s.map()->add_illuminated_switch(s2);
s.map()->add_illuminated_switch(s3);
s.map()->add_illuminated_switch(s4);
s.init_view();
int numkey;
while(true) {
SDL_PumpEvents();
Uint8* keys = SDL_GetKeyState(&numkey);
if (keys[SDLK_UP])
s.move_robot(1.0, 1.0);
if (keys[SDLK_DOWN])
s.move_robot(-1.0, -1.0);
if (keys[SDLK_LEFT])
s.move_robot(1.0, -1.0);
if (keys[SDLK_RIGHT])
s.move_robot(-1.0, 1.0);
s.refresh();
s.refresh_view();
}
return 0;
}
#else
# warning FASTSIM_KEYBOARD not compiled because SDL was not activated
#endif