From e050d27f8377d052faefd376c092864e5fb1a00f Mon Sep 17 00:00:00 2001 From: heinezen Date: Thu, 7 Nov 2024 22:54:10 +0100 Subject: [PATCH] renderer: Add method to change camera boundaries in cam manager. --- libopenage/presenter/presenter.cpp | 10 ++++++++++ libopenage/renderer/demo/demo_3.cpp | 12 ++++++++++++ libopenage/renderer/stages/camera/manager.cpp | 9 +++++++-- libopenage/renderer/stages/camera/manager.h | 11 ++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/libopenage/presenter/presenter.cpp b/libopenage/presenter/presenter.cpp index 33c798bcef..ffb215135f 100644 --- a/libopenage/presenter/presenter.cpp +++ b/libopenage/presenter/presenter.cpp @@ -121,7 +121,17 @@ void Presenter::init_graphics(bool debug) { this->camera->resize(w, h); }); + // Camera manager this->camera_manager = std::make_shared(this->camera); + // TODO: Make boundaries dynamic based on map size. + this->camera_manager->set_camera_boundaries( + renderer::camera::CameraBoundaries{ + renderer::camera::X_MIN, + renderer::camera::X_MAX, + renderer::camera::Y_MIN, + renderer::camera::Y_MAX, + renderer::camera::Z_MIN, + renderer::camera::Z_MAX}); // Skybox this->skybox_renderer = std::make_shared( diff --git a/libopenage/renderer/demo/demo_3.cpp b/libopenage/renderer/demo/demo_3.cpp index 9c294285f9..7de6372303 100644 --- a/libopenage/renderer/demo/demo_3.cpp +++ b/libopenage/renderer/demo/demo_3.cpp @@ -52,6 +52,18 @@ void renderer_demo_3(const util::Path &path) { // it is updated each frame before the render stages auto cam_manager = std::make_shared(camera); + // Set boundaries for camera movement in the scene + // this restricts camera movement to the area defined by the boundaries + // i.e. the map terrain in this case + cam_manager->set_camera_boundaries( + camera::CameraBoundaries{ + 12.25f, + 22.25f, + 0.0f, + 20.0f, + 2.25f, + 12.25f}); + // Render stages // every stage use a different subrenderer that manages renderables, // shaders, textures & more. diff --git a/libopenage/renderer/stages/camera/manager.cpp b/libopenage/renderer/stages/camera/manager.cpp index 207fdab319..d3cbd3f3b2 100644 --- a/libopenage/renderer/stages/camera/manager.cpp +++ b/libopenage/renderer/stages/camera/manager.cpp @@ -10,13 +10,14 @@ namespace openage::renderer::camera { -CameraManager::CameraManager(const std::shared_ptr &camera) : +CameraManager::CameraManager(const std::shared_ptr &camera, + const CameraBoundaries &camera_boundaries) : camera{camera}, move_motion_directions{static_cast(MoveDirection::NONE)}, zoom_motion_direction{static_cast(ZoomDirection::NONE)}, move_motion_speed{0.2f}, zoom_motion_speed{0.05f}, - camera_boundaries{X_MIN, X_MAX, Y_MIN, Y_MAX, Z_MIN, Z_MAX} { + camera_boundaries{camera_boundaries} { this->uniforms = this->camera->get_uniform_buffer()->new_uniform_input( "view", camera->get_view_matrix(), @@ -67,6 +68,10 @@ void CameraManager::zoom_frame(ZoomDirection direction, float speed) { } } +void CameraManager::set_camera_boundaries(const CameraBoundaries &camera_boundaries) { + this->camera_boundaries = camera_boundaries; +} + void CameraManager::update_motion() { if (this->move_motion_directions != static_cast(MoveDirection::NONE)) { Eigen::Vector3f move_dir{0.0f, 0.0f, 0.0f}; diff --git a/libopenage/renderer/stages/camera/manager.h b/libopenage/renderer/stages/camera/manager.h index 689f917416..36d605e959 100644 --- a/libopenage/renderer/stages/camera/manager.h +++ b/libopenage/renderer/stages/camera/manager.h @@ -49,8 +49,10 @@ class CameraManager { * Create a new camera manager. * * @param camera Camera to manage. + * @param camera_boundaries Boundaries for the camera movement in the scene. */ - CameraManager(const std::shared_ptr &camera); + CameraManager(const std::shared_ptr &camera, + const CameraBoundaries &camera_boundaries = DEFAULT_CAM_BOUNDARIES); ~CameraManager() = default; /** @@ -105,6 +107,13 @@ class CameraManager { */ void set_zoom_motion_speed(float speed); + /** + * Set boundaries for camera movement in the scene. + * + * @param camera_boundaries XYZ boundaries for the camera movement. + */ + void set_camera_boundaries(const CameraBoundaries &camera_boundaries); + private: /** * Update the camera parameters.