aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-19 15:50:55 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-19 15:50:55 +0100
commita35b8998ec828877991c6da92879e37f28f64dc5 (patch)
treed9b0a9d946663e45b875ad8a989a4f07f0aba859
parent9633c6a8608175e9832f6995efc46023deebcf94 (diff)
fixed ( placedment
-rw-r--r--src/crepe/facade/SDLContext.cpp22
-rw-r--r--src/example/rendering_particle.cpp9
2 files changed, 22 insertions, 9 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 31b0a0b..dc3f362 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -12,6 +12,7 @@
#include <cmath>
#include <cstddef>
#include <functional>
+#include <iostream>
#include <memory>
#include <stdexcept>
@@ -152,16 +153,23 @@ 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) {
- 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;
+ screen_pos = (screen_pos - cam_aux_data.cam_pos
+ + cam_aux_data.zoomed_viewport / 2)
+ * cam_aux_data.render_scale
+ - size / 2 + cam_aux_data.bar_size;
} else {
- vec2 multiplier = (cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale
+ screen_pos = (screen_pos + cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale
- size / 2 + cam_aux_data.bar_size;
- screen_pos += multiplier;
}
+ cout << "HALLO" << endl;
+ cout << screen_pos.x << " " << screen_pos.y << endl;
+ cout << data.position_offset.x << " " << data.position_offset.y << endl;
+ cout << ctx.pos.x << " " << ctx.pos.y << endl;
+ cout << size.x << " " << size.y << endl;
+ cout << cam_aux_data.render_scale.x << " " << cam_aux_data.render_scale.y << endl;
+ cout << cam_aux_data.bar_size.x << " " << cam_aux_data.bar_size.y << endl;
+
return SDL_FRect{
.x = screen_pos.x,
.y = screen_pos.y,
@@ -195,6 +203,8 @@ void SDLContext::draw(const RenderContext & ctx) {
double angle = ctx.angle + data.angle_offset;
+ cout << dstrect.x << " " << dstrect.y << " " << dstrect.w << " " << dstrect.h << endl;
+
this->set_color_texture(ctx.texture, ctx.sprite.data.color);
SDL_RenderCopyExF(this->game_renderer.get(), ctx.texture.get_img(), srcrect_ptr, &dstrect,
angle, NULL, render_flip);
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
index 07cfae2..b623596 100644
--- a/src/example/rendering_particle.cpp
+++ b/src/example/rendering_particle.cpp
@@ -23,7 +23,7 @@ using namespace std;
class TestScene : public Scene {
public:
void load_scene() {
- GameObject game_object = new_object("", "", vec2{0, 0}, 45, 1);
+ GameObject game_object = new_object("", "", vec2{0, 0}, 0, 1);
Color color(255, 255, 255, 255);
@@ -38,22 +38,25 @@ public:
.size = {1, 1},
.angle_offset = 0,
.position_offset = {0, 1},
+ .world_space = false,
});
- auto & emitter
- = game_object.add_component<ParticleEmitter>(test_sprite, ParticleEmitter::Data{});
+ //auto & emitter = game_object.add_component<ParticleEmitter>(test_sprite, ParticleEmitter::Data{});
Sprite & test_sprite1
= game_object.add_component<Sprite>(img, Sprite::Data{
.color = color,
.size = {1, 1},
.position_offset = {0, -1},
+ .world_space = false,
});
auto & cam = game_object.add_component<Camera>(ivec2{1280, 720}, vec2{5, 5},
Camera::Data{
.bg_color = Color::WHITE,
+ .postion_offset = {1000,1000},
});
+
/*
game_object.add_component<Text>(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS",
Text::Data{.text_color = Color::RED}, "test TEST");