Skip to content

Commit

Permalink
renderer: Add method to change camera boundaries in cam manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 7, 2024
1 parent af804e6 commit 179e1ad
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
10 changes: 10 additions & 0 deletions libopenage/presenter/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,17 @@ void Presenter::init_graphics(bool debug) {
this->camera->resize(w, h);
});

// Camera manager
this->camera_manager = std::make_shared<renderer::camera::CameraManager>(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<renderer::skybox::SkyboxRenderStage>(
Expand Down
12 changes: 12 additions & 0 deletions libopenage/renderer/demo/demo_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<renderer::camera::CameraManager>(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.
Expand Down
9 changes: 7 additions & 2 deletions libopenage/renderer/stages/camera/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

namespace openage::renderer::camera {

CameraManager::CameraManager(const std::shared_ptr<renderer::camera::Camera> &camera) :
CameraManager::CameraManager(const std::shared_ptr<renderer::camera::Camera> &camera,
const CameraBoundaries &camera_boundaries) :
camera{camera},
move_motion_directions{static_cast<int>(MoveDirection::NONE)},
zoom_motion_direction{static_cast<int>(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(),
Expand Down Expand Up @@ -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<int>(MoveDirection::NONE)) {
Eigen::Vector3f move_dir{0.0f, 0.0f, 0.0f};
Expand Down
11 changes: 10 additions & 1 deletion libopenage/renderer/stages/camera/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<renderer::camera::Camera> &camera);
CameraManager(const std::shared_ptr<renderer::camera::Camera> &camera,
const CameraBoundaries &camera_boundaries = DEFAULT_CAM_BOUNDARIES);
~CameraManager() = default;

/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 179e1ad

Please sign in to comment.