feat: More camera controls

This commit is contained in:
2026-04-17 17:30:34 +01:00
parent 593a056696
commit ef716b7425
3 changed files with 25 additions and 4 deletions

View File

@@ -60,10 +60,16 @@ int main(int argc, char *argv[])
}
const bool *key_states = SDL_GetKeyboardState(NULL);
if (key_states[SDL_SCANCODE_W]) renderer.move_camera(vec2_unity * 30 * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_S]) renderer.move_camera(-vec2_unity * 30 * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_A]) renderer.move_camera(-vec2_unitx * 30 * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_D]) renderer.move_camera(vec2_unitx * 30 * (1.0f / 60.0f));
const float move_spd = 1.0f * renderer.get_zoom();
const float zoom_spd = 0.5f;
if (key_states[SDL_SCANCODE_W]) renderer.move_camera(+vec2_unity * move_spd * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_S]) renderer.move_camera(-vec2_unity * move_spd * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_A]) renderer.move_camera(-vec2_unitx * move_spd * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_D]) renderer.move_camera(+vec2_unitx * move_spd * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_Q]) renderer.zoom_camera(+zoom_spd * (1.0f / 60.0f));
if (key_states[SDL_SCANCODE_E]) renderer.zoom_camera(-zoom_spd * (1.0f / 60.0f));
// Clear
renderer.color(0, 0, 0, 255);

View File

@@ -19,6 +19,11 @@ static const vec2 vec2_min = { -FLT_MAX, -FLT_MAX };
static const vec2i vec2i_zero = { 0, 0 };
static const vec2i vec2i_one = { 1, 1 };
static vec2 operator+(vec2 const &v)
{
return { .x = v.x, .y = v.y };
}
static vec2 operator-(vec2 const &v)
{
return { .x = -v.x, .y = -v.y };

View File

@@ -55,6 +55,16 @@ public:
_center = _center + delta;
}
void zoom_camera(float delta)
{
_scale /= 1 + delta;
}
float get_zoom()
{
return 1.0f / _scale;
}
void color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
SDL_SetRenderDrawColor(_sdl, r, g, b, a);