diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-30 15:43:36 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-30 15:43:36 +0100 |
commit | ad4f8acfb252b8be3a3fbb74ed97b32e498a26a4 (patch) | |
tree | f6a0e61199df8136c3e9f18adc46071a32301903 | |
parent | 4159c7187e17d6318e33d8a0c014ba042ae8261b (diff) |
zoomed viewport
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 14 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 0ba1db4..6d79c73 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -118,9 +118,9 @@ SDL_FRect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, cons vec2 size = { (sprite.height * sprite.aspect_ratio), sprite.height}; - size *= scale * img_scale * cam.zoom ; + size *= scale * img_scale; - vec2 screen_pos = (pos - cam_pos + cam.viewport_size / 2) * scale - size / 2 + bar_size; + vec2 screen_pos = (pos - cam_pos + (cam.viewport_size / cam.zoom ) / 2) * scale - size / 2 + bar_size; cout << size.x << " " << size.y << endl; cout << pos.x << " " << pos.y << endl; @@ -161,7 +161,7 @@ void SDLContext::set_camera(const Camera & cam) { } double screen_aspect = static_cast<double>(cam.screen.x) / cam.screen.y; - double viewport_aspect = cam.viewport_size.x / cam.viewport_size.y; + double viewport_aspect = (cam.viewport_size.x / cam.zoom ) / (cam.viewport_size.y / cam.zoom); SDL_FRect black_bars[2]; @@ -169,18 +169,18 @@ void SDLContext::set_camera(const Camera & cam) { if (screen_aspect > viewport_aspect) { // pillarboxing cout << "pillarboxing" << endl; - float render_scale = cam.screen.y / cam.viewport_size.y; - float adj_width = cam.viewport_size.x * render_scale; + float render_scale = cam.screen.y / (cam.viewport_size.y / cam.zoom); + float adj_width = (cam.viewport_size.x / cam.zoom )* render_scale; float bar_width = (cam.screen.x - adj_width) / 2; black_bars[0] = {0, 0, bar_width, (float) cam.screen.y}; black_bars[1] = {(cam.screen.x - bar_width), 0, bar_width, (float) cam.screen.y}; bar_size = {bar_width,0}; - scale.x = scale.y = cam.screen.y / cam.viewport_size.y; + scale.x = scale.y = render_scale; } else { // letterboxing cout << "letterboxing" << endl; - float render_scale = cam.screen.x / cam.viewport_size.x; + float render_scale = cam.screen.x / (cam.viewport_size.x * cam.zoom); float adj_height = cam.viewport_size.y * render_scale; float bar_height = (cam.screen.y - adj_height) / 2; black_bars[0] = {0, 0, (float) cam.screen.x, bar_height}; diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index f5b9ab3..b4bfeb2 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -33,7 +33,7 @@ int main(int argc, char * argv[]) { auto img = Texture("asset/texture/test_ap43.png"); Sprite & test_sprite = game_object.add_component<Sprite>( - img, color, Sprite::FlipSettings{true, true}, 1, 1, 3000); + img, color, Sprite::FlipSettings{true, true}, 1, 1, 300); //game_object.add_component<Animator>(test_sprite, 4, 1, 0).active = true; game_object.add_component<Animator>(test_sprite, 1, 1, 0).active = true; @@ -61,8 +61,8 @@ int main(int argc, char * argv[]) { */ auto & cam = game_object.add_component<Camera>(Color::WHITE, ivec2{1280, 720}, - vec2{8000,6000}, 1.0f); - cam.offset.x = 4000; + vec2{400,300}, 0.5f); + cam.offset.x = 0; /* game_object |