Add mouse control for turret
This commit is contained in:
@@ -16,9 +16,13 @@ struct {
|
|||||||
};
|
};
|
||||||
int color = 0;
|
int color = 0;
|
||||||
|
|
||||||
|
float pitch = 0, yaw = 0;
|
||||||
float x = 0, y = 0, z = 0;
|
float x = 0, y = 0, z = 0;
|
||||||
static Uint32 drive_timer_handler(Uint32 interval, void* param) {
|
static Uint32 drive_timer_handler(Uint32 interval, void* param) {
|
||||||
robot_drive((Robot)param, x, y, z);
|
robot_drive((Robot)param, x, y, z);
|
||||||
|
robot_aim((Robot)param, pitch, yaw);
|
||||||
|
yaw *= 0.80;
|
||||||
|
pitch *= 0.80;
|
||||||
return 75;
|
return 75;
|
||||||
}
|
}
|
||||||
static Uint32 heartbeat_timer_handler(Uint32 interval, void* param) {
|
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(75, drive_timer_handler, robot);
|
||||||
SDL_AddTimer(1000, heartbeat_timer_handler, robot);
|
SDL_AddTimer(1000, heartbeat_timer_handler, robot);
|
||||||
|
|
||||||
|
int h, w;
|
||||||
|
SDL_GetWindowSize(win, &w, &h);
|
||||||
|
|
||||||
while(robot_work(robot)) {
|
while(robot_work(robot)) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(SDL_PollEvent(&event)) {
|
while(SDL_PollEvent(&event)) {
|
||||||
@@ -79,8 +86,14 @@ int main(int argc, char* argv[]) {
|
|||||||
case SDL_SCANCODE_SPACE:
|
case SDL_SCANCODE_SPACE:
|
||||||
robot_led(robot, colors[color].r, colors[color].g, colors[color].b);
|
robot_led(robot, colors[color].r, colors[color].g, colors[color].b);
|
||||||
color = (color + 1) % 3;
|
color = (color + 1) % 3;
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
yaw = (float)event.motion.xrel;
|
||||||
|
pitch = (float)event.motion.yrel;
|
||||||
|
break;
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if(event.window.event != SDL_WINDOWEVENT_CLOSE) break;
|
if(event.window.event != SDL_WINDOWEVENT_CLOSE) break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
|
|||||||
Reference in New Issue
Block a user