From 19993ced8e1323b3bcb9a691d26d9be8d143aab5 Mon Sep 17 00:00:00 2001 From: PgSocks Date: Wed, 22 Feb 2023 09:56:40 -0600 Subject: [PATCH] Add mouse control for turret --- src/sdl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sdl.c b/src/sdl.c index ab27553..0d9727e 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -16,9 +16,13 @@ struct { }; int color = 0; +float pitch = 0, yaw = 0; float x = 0, y = 0, z = 0; static Uint32 drive_timer_handler(Uint32 interval, void* param) { robot_drive((Robot)param, x, y, z); + robot_aim((Robot)param, pitch, yaw); + yaw *= 0.80; + pitch *= 0.80; return 75; } static Uint32 heartbeat_timer_handler(Uint32 interval, void* param) { @@ -47,6 +51,9 @@ int main(int argc, char* argv[]) { SDL_AddTimer(75, drive_timer_handler, robot); SDL_AddTimer(1000, heartbeat_timer_handler, robot); + int h, w; + SDL_GetWindowSize(win, &w, &h); + while(robot_work(robot)) { SDL_Event event; while(SDL_PollEvent(&event)) { @@ -79,8 +86,14 @@ int main(int argc, char* argv[]) { case SDL_SCANCODE_SPACE: robot_led(robot, colors[color].r, colors[color].g, colors[color].b); color = (color + 1) % 3; + break; default: break; } + break; + case SDL_MOUSEMOTION: + yaw = (float)event.motion.xrel; + pitch = (float)event.motion.yrel; + break; case SDL_WINDOWEVENT: if(event.window.event != SDL_WINDOWEVENT_CLOSE) break; case SDL_QUIT: