Skip to content

Commit e1956dd

Browse files
committed
Renderer: Camera Bounds#
1 parent cfeb492 commit e1956dd

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// Copyright 2024-2024 the openage authors. See copying.md for legal info.
22

3+
#include <tuple>
4+
35
#include "boundaries.h"
46

57

68
namespace openage::renderer::camera {
79

10+
bool CameraBoundaries::operator==(const CameraBoundaries &rhs) {
11+
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));
12+
}
813

914
} // namespace openage::renderer::camera

libopenage/renderer/camera/boundaries.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct CameraBoundaries {
2020
float z_min;
2121
/// The maximum boundary for the camera's Z-coordinate.
2222
float z_max;
23+
24+
bool operator==(const CameraBoundaries &rhs);
2325
};
2426

2527
} // namespace openage::renderer::camera
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_sources(libopenage
22
manager.cpp
3+
render_entity.cpp
34
)

libopenage/renderer/stages/camera/manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ void CameraManager::set_camera_boundaries(const CameraBoundaries &camera_boundar
7272
this->camera_boundaries = camera_boundaries;
7373
}
7474

75+
void CameraManager::poll_render_entity() {
76+
if (render_entity->is_changed()) {
77+
this->camera_boundaries = render_entity->get_camera_boundaries();
78+
}
79+
}
80+
7581
void CameraManager::update_motion() {
7682
if (this->move_motion_directions != static_cast<int>(MoveDirection::NONE)) {
7783
Eigen::Vector3f move_dir{0.0f, 0.0f, 0.0f};

libopenage/renderer/stages/camera/manager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <utility>
77

88
#include "renderer/camera/camera.h"
9+
#include "renderer/stages/camera/render_entity.h"
910

1011
namespace openage::renderer {
1112
class UniformBufferInput;
@@ -114,6 +115,9 @@ class CameraManager {
114115
*/
115116
void set_camera_boundaries(const CameraBoundaries &camera_boundaries);
116117

118+
119+
void poll_render_entity();
120+
117121
private:
118122
/**
119123
* Update the camera parameters.
@@ -159,6 +163,8 @@ class CameraManager {
159163
* Camera boundaries for X and Z movement. Contains minimum and maximum values for each axes.
160164
*/
161165
CameraBoundaries camera_boundaries;
166+
167+
std::shared_ptr<RenderEntity> render_entity;
162168
};
163169

164170
} // namespace camera
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024-2025 the openage authors. See copying.md for legal info.
2+
3+
#pragma once
4+
5+
#include "render_entity.h"
6+
7+
namespace openage::renderer::camera {
8+
9+
void RenderEntity::update(const CameraBoundaries& boundaries, const time::time_t time)
10+
{
11+
std::unique_lock lock{this->mutex};
12+
13+
this->camera_boundaries = camera_boundaries;
14+
this->last_update = time;
15+
this->changed = true;
16+
}
17+
18+
const CameraBoundaries &RenderEntity::get_camera_boundaries() {
19+
return this->camera_boundaries;
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2024-2025 the openage authors. See copying.md for legal info.
2+
3+
#pragma once
4+
5+
#include "renderer/camera/boundaries.h"
6+
#include "gamestate/definitions.h"
7+
#include "renderer/stages/render_entity.h"
8+
9+
10+
namespace openage::renderer::camera {
11+
12+
class RenderEntity final : public renderer::RenderEntity {
13+
public:
14+
RenderEntity();
15+
~RenderEntity() = default;
16+
17+
void update(const CameraBoundaries& camera_boundaries, const time::time_t time = 0.0);
18+
19+
const CameraBoundaries& get_camera_boundaries();
20+
21+
22+
23+
private:
24+
CameraBoundaries camera_boundaries;
25+
};
26+
27+
}

0 commit comments

Comments
 (0)