From 45c799f71e6f0db1de27bdd601c0d441f0012468 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 18 Dec 2024 14:43:41 +0100 Subject: camera space working --- src/crepe/api/UIObject.h | 2 ++ src/crepe/system/InputSystem.cpp | 49 ++++++++++++++++----------------- src/crepe/system/InputSystem.h | 9 ++++-- src/test/InputTest.cpp | 59 ++++++++++++++++++++++++++++++++-------- 4 files changed, 79 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/crepe/api/UIObject.h b/src/crepe/api/UIObject.h index f7f4fba..f1318ab 100644 --- a/src/crepe/api/UIObject.h +++ b/src/crepe/api/UIObject.h @@ -20,6 +20,8 @@ public: vec2 dimensions; //! Position offset relative to this GameObjects Transform vec2 offset; + //! variable indicating if transform is relative to camera(false) or world(true) + bool world_space = false; }; } // namespace crepe diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index fca540f..12437f7 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -26,10 +26,8 @@ void InputSystem::update() { if (!curr_cam_ref) return; Camera & current_cam = curr_cam_ref; - RefVector transform_vec - = mgr.get_components_by_id(current_cam.game_object_id); - Transform & cam_transform = transform_vec.front().get(); - + Transform & cam_transform = mgr.get_components_by_id(current_cam.game_object_id).front(); + vec2 camera_origin = cam_transform.position + current_cam.data.postion_offset - (current_cam.viewport_size / 2); @@ -52,7 +50,7 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer EventManager & event_mgr = this->mediator.event_manager; vec2 adjusted_mouse; adjusted_mouse.x = event.data.mouse_data.mouse_position.x + camera_origin.x; - adjusted_mouse.x = event.data.mouse_data.mouse_position.y + camera_origin.y; + adjusted_mouse.y = event.data.mouse_data.mouse_position.y + camera_origin.y; // Check if the mouse is within the viewport if ((adjusted_mouse.x < camera_origin.x || adjusted_mouse.x > camera_origin.x + current_cam.viewport_size.x @@ -85,7 +83,7 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer .mouse_pos = adjusted_mouse, .button = event.data.mouse_data.mouse_button, }); - this->handle_click(event.data.mouse_data.mouse_button, adjusted_mouse); + this->handle_click(event.data.mouse_data.mouse_button, adjusted_mouse,current_cam); } break; } @@ -95,7 +93,7 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer .mouse_pos = adjusted_mouse, .mouse_delta = event.data.mouse_data.rel_mouse_move, }); - this->handle_move(event, adjusted_mouse); + this->handle_move(event, adjusted_mouse,current_cam); break; case EventType::MOUSE_WHEEL: @@ -153,19 +151,22 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { } } -void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos) { +void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos, const Camera & current_cam) { ComponentManager & mgr = this->mediator.component_manager; RefVector