Skip to content

Renderer: Camera Bounds #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libopenage/renderer/camera/boundaries.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright 2024-2024 the openage authors. See copying.md for legal info.

#include <tuple>

#include "boundaries.h"


namespace openage::renderer::camera {

bool CameraBoundaries::operator==(const CameraBoundaries &rhs) {
return (std::tie(x_min, x_max, y_min, y_max, z_min, z_max) == std::tie(rhs.x_min, rhs.x_max, rhs.y_min, rhs.y_max, rhs.z_min, rhs.z_max));
}

} // namespace openage::renderer::camera
2 changes: 2 additions & 0 deletions libopenage/renderer/camera/boundaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct CameraBoundaries {
float z_min;
/// The maximum boundary for the camera's Z-coordinate.
float z_max;

bool operator==(const CameraBoundaries &rhs);
};

} // namespace openage::renderer::camera
1 change: 1 addition & 0 deletions libopenage/renderer/stages/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_sources(libopenage
manager.cpp
render_entity.cpp
)
6 changes: 6 additions & 0 deletions libopenage/renderer/stages/camera/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void CameraManager::set_camera_boundaries(const CameraBoundaries &camera_boundar
this->camera_boundaries = camera_boundaries;
}

void CameraManager::poll_render_entity() {
if (render_entity->is_changed()) {
this->camera_boundaries = render_entity->get_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
6 changes: 6 additions & 0 deletions libopenage/renderer/stages/camera/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <utility>

#include "renderer/camera/camera.h"
#include "renderer/stages/camera/render_entity.h"

namespace openage::renderer {
class UniformBufferInput;
Expand Down Expand Up @@ -114,6 +115,9 @@ class CameraManager {
*/
void set_camera_boundaries(const CameraBoundaries &camera_boundaries);


void poll_render_entity();

private:
/**
* Update the camera parameters.
Expand Down Expand Up @@ -159,6 +163,8 @@ class CameraManager {
* Camera boundaries for X and Z movement. Contains minimum and maximum values for each axes.
*/
CameraBoundaries camera_boundaries;

std::shared_ptr<RenderEntity> render_entity;
};

} // namespace camera
Expand Down
21 changes: 21 additions & 0 deletions libopenage/renderer/stages/camera/render_entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024-2025 the openage authors. See copying.md for legal info.

#pragma once

#include "render_entity.h"

namespace openage::renderer::camera {

void RenderEntity::update(const CameraBoundaries& boundaries, const time::time_t time)
{
std::unique_lock lock{this->mutex};

this->camera_boundaries = camera_boundaries;
this->last_update = time;
this->changed = true;
}

const CameraBoundaries &RenderEntity::get_camera_boundaries() {
return this->camera_boundaries;
}
}
27 changes: 27 additions & 0 deletions libopenage/renderer/stages/camera/render_entity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024-2025 the openage authors. See copying.md for legal info.

#pragma once

#include "renderer/camera/boundaries.h"
#include "gamestate/definitions.h"
#include "renderer/stages/render_entity.h"


namespace openage::renderer::camera {

class RenderEntity final : public renderer::RenderEntity {
public:
RenderEntity();
~RenderEntity() = default;

void update(const CameraBoundaries& camera_boundaries, const time::time_t time = 0.0);

const CameraBoundaries& get_camera_boundaries();



private:
CameraBoundaries camera_boundaries;
};

}
Loading