diff --git a/platform/sdl3/main.c b/platform/sdl3/main.c index e1c633b..0efdf3c 100644 --- a/platform/sdl3/main.c +++ b/platform/sdl3/main.c @@ -16,6 +16,8 @@ static SDL_Texture *texture = NULL; static SDL_Surface *front = NULL; static SDL_Surface *back = NULL; +static bool focused = true; + static void die(const char *fmt, ...) { static char error[1024]; @@ -42,6 +44,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) if (!window) die(SDL_GetError()); + SDL_SetWindowRelativeMouseMode(window, focused); + SDL_SetWindowMinimumSize(window, YETI_FRAMEBUFFER_WIDTH, YETI_FRAMEBUFFER_HEIGHT); renderer = SDL_CreateRenderer(window, NULL); @@ -84,8 +88,8 @@ SDL_AppResult SDL_AppIterate(void *appstate) { const bool *keys = SDL_GetKeyboardState(NULL); - yeti.keyboard.state.up = keys[SDL_SCANCODE_UP]; - yeti.keyboard.state.down = keys[SDL_SCANCODE_DOWN]; + yeti.keyboard.state.up = keys[SDL_SCANCODE_UP] || keys[SDL_SCANCODE_W]; + yeti.keyboard.state.down = keys[SDL_SCANCODE_DOWN] || keys[SDL_SCANCODE_S]; yeti.keyboard.state.left = keys[SDL_SCANCODE_LEFT]; yeti.keyboard.state.right = keys[SDL_SCANCODE_RIGHT]; yeti.keyboard.state.a = keys[SDL_SCANCODE_RCTRL]; @@ -114,6 +118,22 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { case SDL_EVENT_QUIT: return SDL_APP_SUCCESS; + + case SDL_EVENT_KEY_DOWN: + if (event->key.scancode == SDL_SCANCODE_ESCAPE) + { + focused = !focused; + SDL_SetWindowRelativeMouseMode(window, focused); + } + break; + + case SDL_EVENT_MOUSE_MOTION: + if (focused) + { + yeti.camera->p += fl2f(event->motion.yrel); + yeti.camera->t += fl2f(event->motion.xrel); + } + break; } return SDL_APP_CONTINUE;