From ea5e62b4ca8fbe214605abdab486bf6dcc1cc540 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 18 Dec 2024 11:31:54 +0100 Subject: added particle begin lifespan rendering, added world_space to sprite so that coordinates are in camera_space or world_sapce --- src/crepe/facade/SDLContext.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index fffbe34..35f82d8 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,9 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { = (ctx.sprite.aspect_ratio == 0) ? ctx.texture.get_ratio() : ctx.sprite.aspect_ratio; vec2 size = data.size; + vec2 screen_pos = ctx.pos + data.position_offset; + + if (data.size.x == 0 && data.size.y != 0) { size.x = data.size.y * aspect_ratio; } @@ -145,10 +149,15 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { } size *= cam_aux_data.render_scale * ctx.img_scale * data.scale_offset; - vec2 screen_pos = (ctx.pos + data.position_offset - cam_aux_data.cam_pos - + (cam_aux_data.zoomed_viewport) / 2) - * cam_aux_data.render_scale - - size / 2 + cam_aux_data.bar_size; + if (ctx.sprite.data.world_space) { + cout << "world_space" << endl; + vec2 multiplier = cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; + screen_pos += multiplier; + } else { + cout << "camera space" << endl; + vec2 multiplier = (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; + screen_pos += multiplier; + } return SDL_FRect{ .x = screen_pos.x, -- cgit v1.2.3 From 3f176dace320b9bb72675cf9b6fd77fe6d35c539 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 18 Dec 2024 11:32:41 +0100 Subject: make format --- src/crepe/facade/SDLContext.cpp | 8 +++++--- src/example/rendering_particle.cpp | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 35f82d8..ed702b0 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -140,7 +140,6 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { vec2 size = data.size; vec2 screen_pos = ctx.pos + data.position_offset; - if (data.size.x == 0 && data.size.y != 0) { size.x = data.size.y * aspect_ratio; } @@ -151,11 +150,14 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { if (ctx.sprite.data.world_space) { cout << "world_space" << endl; - vec2 multiplier = cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; + vec2 multiplier = cam_aux_data.cam_pos + + (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; screen_pos += multiplier; } else { cout << "camera space" << endl; - vec2 multiplier = (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; + vec2 multiplier = (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; screen_pos += multiplier; } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 1c8072e..0fe24df 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -36,13 +36,14 @@ public: .angle_offset = 0, .position_offset = {0, 0}, }); - auto & emitter = game_object.add_component(test_sprite, ParticleEmitter::Data{}); + auto & emitter + = game_object.add_component(test_sprite, ParticleEmitter::Data{}); auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{400, 400}, Camera::Data{ .bg_color = Color::WHITE, }); - cam.data.postion_offset = {1000,1000}; + cam.data.postion_offset = {1000, 1000}; } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From aaca31b3495060b46f178d476636563279fc1c23 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 18 Dec 2024 13:27:54 +0100 Subject: implemented wouter feedback --- src/crepe/facade/SDLContext.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index ed702b0..0d5eb01 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -11,9 +11,7 @@ #include #include #include -#include #include -#include #include #include @@ -149,13 +147,11 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { size *= cam_aux_data.render_scale * ctx.img_scale * data.scale_offset; if (ctx.sprite.data.world_space) { - cout << "world_space" << endl; vec2 multiplier = cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; screen_pos += multiplier; } else { - cout << "camera space" << endl; vec2 multiplier = (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; screen_pos += multiplier; -- cgit v1.2.3