feat: More camera controls
This commit is contained in:
14
src/main.cpp
14
src/main.cpp
@@ -60,10 +60,16 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool *key_states = SDL_GetKeyboardState(NULL);
|
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));
|
const float move_spd = 1.0f * renderer.get_zoom();
|
||||||
if (key_states[SDL_SCANCODE_A]) renderer.move_camera(-vec2_unitx * 30 * (1.0f / 60.0f));
|
const float zoom_spd = 0.5f;
|
||||||
if (key_states[SDL_SCANCODE_D]) renderer.move_camera(vec2_unitx * 30 * (1.0f / 60.0f));
|
|
||||||
|
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
|
// Clear
|
||||||
renderer.color(0, 0, 0, 255);
|
renderer.color(0, 0, 0, 255);
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ static const vec2 vec2_min = { -FLT_MAX, -FLT_MAX };
|
|||||||
static const vec2i vec2i_zero = { 0, 0 };
|
static const vec2i vec2i_zero = { 0, 0 };
|
||||||
static const vec2i vec2i_one = { 1, 1 };
|
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)
|
static vec2 operator-(vec2 const &v)
|
||||||
{
|
{
|
||||||
return { .x = -v.x, .y = -v.y };
|
return { .x = -v.x, .y = -v.y };
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ public:
|
|||||||
_center = _center + delta;
|
_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)
|
void color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(_sdl, r, g, b, a);
|
SDL_SetRenderDrawColor(_sdl, r, g, b, a);
|
||||||
|
|||||||
Reference in New Issue
Block a user