diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-25 19:39:11 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-25 19:39:11 +0100 |
commit | 9aca3626e31a7549f8c436672d4f479bd64c0057 (patch) | |
tree | 9255aa25ceea4d50cc50474bc27a50a007ce008d /src | |
parent | b570225f5166b18fdd881fc53cd7013669067ca1 (diff) |
fixed a rezing and camera origin is now middlepoint
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/Camera.h | 4 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 2 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 13 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 2 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 5 |
5 files changed, 14 insertions, 12 deletions
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 083dc19..137c8ed 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -32,14 +32,16 @@ public: Vector2 pos = {0, 0}; //! screen the display size in pixels ( output resolution ) + //Vector2 screen = {720, 480}; Vector2 screen = {1080, 720}; //! viewport is the area of the world visible through the camera (in world units) + //Vector2 viewport = {720, 480}; Vector2 viewport = {2000, 1000}; //! scale scaling factor from world units to pixel coordinates //! Zoom level of the camera view. - double zoom = 1.5f; + double zoom = 1.0f; public: /** diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 13eabd1..b6c2ccf 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -33,7 +33,7 @@ public: * * Only messages with equal or higher priority than this value will be logged. */ - Log::Level level = Log::Level::INFO; + Log::Level level = Log::Level::DEBUG; /** * \brief Colored log output * 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 diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index fad174e..36997be 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -24,7 +24,7 @@ using namespace std; int main(int argc, char * argv[]) { ComponentManager mgr; - GameObject game_object = mgr.new_object("", "", Vector2{1000, 500}, 0, 1); + GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 1); RenderSystem sys{mgr}; ParticleSystem psys{mgr}; AnimatorSystem asys{mgr}; @@ -62,7 +62,8 @@ int main(int argc, char * argv[]) { }); */ - game_object.add_component<Camera>(Color::WHITE); + auto & cam = game_object.add_component<Camera>(Color::WHITE); + cam.pos = {500, 200}; /* game_object |