aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-25 19:39:11 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-25 19:39:11 +0100
commit9aca3626e31a7549f8c436672d4f479bd64c0057 (patch)
tree9255aa25ceea4d50cc50474bc27a50a007ce008d /src/crepe/facade
parentb570225f5166b18fdd881fc53cd7013669067ca1 (diff)
fixed a rezing and camera origin is now middlepoint
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp13
-rw-r--r--src/crepe/facade/SDLContext.h2
2 files changed, 7 insertions, 8 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 778e746..de7d08f 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -8,6 +8,7 @@
#include <cmath>
#include <cstddef>
#include <functional>
+#include <iostream>
#include <memory>
#include <stdexcept>
@@ -124,8 +125,8 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos,
pixel_width *= img_scale;
pixel_height *= img_scale;
- int pixel_x = static_cast<int>((pos.x - cam_pos.x - pixel_width / 2));
- int pixel_y = static_cast<int>((pos.y - cam_pos.y - pixel_height / 2));
+ int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->viewport.w / 2 - pixel_width / 2));
+ int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->viewport.h / 2 - pixel_height / 2));
return SDL_Rect{
.x = pixel_x,
@@ -168,10 +169,10 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform,
void SDLContext::set_camera(const Camera & cam, Vector2 & scale) {
// resize window
- if (this->viewport.w != (int) cam.screen.x && this->viewport.h != (int) cam.screen.y) {
+ if (this->viewport.w != (int) cam.screen.x || this->viewport.h != (int) cam.screen.y) {
SDL_SetWindowSize(this->game_window.get(), (int) cam.screen.x, (int) cam.screen.y);
- this->viewport.h = cam.screen.y;
- this->viewport.w = cam.screen.x;
+ this->viewport.h = (int)cam.screen.y;
+ this->viewport.w = (int)cam.screen.x;
}
double screen_aspect = cam.screen.x / cam.screen.y;
@@ -185,7 +186,6 @@ void SDLContext::set_camera(const Camera & cam, Vector2 & scale) {
// calculate black bars
if (screen_aspect > viewport_aspect) {
// lettorboxing
- view.h = static_cast<int>(cam.screen.y / cam.zoom);
view.w = static_cast<int>(cam.screen.y * viewport_aspect);
view.x = static_cast<int>(cam.screen.x - view.w) / 2;
view.y = 0;
@@ -196,7 +196,6 @@ void SDLContext::set_camera(const Camera & cam, Vector2 & scale) {
view.x = 0;
view.y = static_cast<int>(cam.screen.y - view.h) / 2;
}
-
// set drawing area
SDL_RenderSetViewport(this->game_renderer.get(), &view);
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 03f9ec9..3e9b8db 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -179,7 +179,7 @@ private:
//! viewport for the camera window
//todo change this so that it becomes a vec2 for only width and height
- SDL_Rect viewport = {0, 0, 1280, 720};
+ SDL_Rect viewport = {0, 0, 1200, 1200};
};
} // namespace crepe