diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/Camera.h | 12 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 11 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 3 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 3 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 4 |
5 files changed, 18 insertions, 15 deletions
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 151e5d9..1505107 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -28,17 +28,19 @@ public: //! Background color of the camera view. Color bg_color; - //! pos The position of the camera in world units - vec2 pos = {0,0}; + //! offset postion from the game object transform component + vec2 offset = {0, 0}; + + //! pos the postion of the camera in world space this will be filled with + //pos = transform + offset + vec2 pos = {0, 0}; //! screen the display size in pixels ( output resolution ) - ivec2 screen = {1080,720}; + ivec2 screen = {1080, 720}; //! viewport is the area of the world visible through the camera (in world units) - //vec2 viewport = {1000, 2000}; ivec2 viewport = {500, 1000}; - //! scale scaling factor from world units to pixel coordinates //! Zoom level of the camera view. double zoom = 1.0f; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 72542e8..4887d35 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -40,7 +40,7 @@ SDLContext::SDLContext() { auto & cfg = Config::get_instance().win_set; SDL_Window * tmp_window = SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - cfg.def_size.x,cfg.def_size.y, 0); + cfg.def_size.x, cfg.def_size.y, 0); if (!tmp_window) { throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError())); } @@ -134,7 +134,7 @@ void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, const do | (SDL_FLIP_VERTICAL * sprite.flip.flip_y)); SDL_Rect srcrect = this->get_src_rect(sprite); - SDL_Rect dstrect = this->get_dst_rect(sprite, pos, cam , img_scale); + SDL_Rect dstrect = this->get_dst_rect(sprite, pos, cam, img_scale); SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect, &dstrect, angle, NULL, render_flip); @@ -147,8 +147,7 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, const | (SDL_FLIP_VERTICAL * sprite.flip.flip_y)); SDL_Rect srcrect = this->get_src_rect(sprite); - SDL_Rect dstrect - = this->get_dst_rect(sprite, transform.position, cam, transform.scale); + SDL_Rect dstrect = this->get_dst_rect(sprite, transform.position, cam, transform.scale); SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect, &dstrect, transform.rotation, NULL, render_flip); @@ -157,9 +156,9 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, const void SDLContext::set_camera(const Camera & cam) { // resize window - int w,h; + int w, h; SDL_GetWindowSize(this->game_window.get(), &w, &h); - if ( w != cam.screen.x || h != cam.screen.y) { + if (w != cam.screen.x || h != cam.screen.y) { SDL_SetWindowSize(this->game_window.get(), cam.screen.x, cam.screen.y); } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 2e40b6f..35d667d 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -9,9 +9,9 @@ #include <memory> #include <string> +#include "../api/Camera.h" #include "../api/Sprite.h" #include "../api/Transform.h" -#include "../api/Camera.h" #include "types.h" @@ -172,7 +172,6 @@ private: //! renderer for the crepe engine std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer; - }; } // namespace crepe diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index beed9ce..9a8c1ba 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -28,8 +28,11 @@ void RenderSystem::update_camera() { for (Camera & cam : cameras) { if (!cam.active) continue; + const Transform & transform + = mgr.get_components_by_id<Transform>(cam.game_object_id).front().get(); this->context.set_camera(cam); this->curr_cam_ref = &cam; + this->curr_cam_ref->pos = transform.position + this->curr_cam_ref->offset; } } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 3589cad..ec71260 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -32,8 +32,8 @@ int main(int argc, char * argv[]) { Color color(255, 255, 255, 255); auto img = Texture("asset/texture/test_ap43.png"); - Sprite & test_sprite = game_object.add_component<Sprite>(img, color, - FlipSettings{true, true}); + Sprite & test_sprite + = game_object.add_component<Sprite>(img, color, FlipSettings{true, true}); test_sprite.order_in_layer = 5; test_sprite.height = 195; |