Skip to content

Commit e5a7616

Browse files
committed
[cube] Store center of the cube instead of recalculating it every time
1 parent 3bb0e9d commit e5a7616

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/inexor/vulkan-renderer/world/cube.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Cube : public std::enable_shared_from_this<Cube> {
6767
Type m_type{Type::EMPTY};
6868
float m_size{32};
6969
glm::vec3 m_position{0.0f, 0.0f, 0.0f};
70+
glm::vec3 m_center{0.0f, 0.0f, 0.0f};
7071

7172
/// Root cube is empty.
7273
std::weak_ptr<Cube> m_parent{};
@@ -126,7 +127,7 @@ class Cube : public std::enable_shared_from_this<Cube> {
126127
[[nodiscard]] std::size_t count_geometry_cubes() const noexcept;
127128

128129
[[nodiscard]] glm::vec3 center() const noexcept {
129-
return m_position + 0.5f * m_size;
130+
return m_center;
130131
}
131132

132133
[[nodiscard]] glm::vec3 position() const noexcept {

src/vulkan-renderer/world/cube.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ void Cube::rotate<3>(const RotationAxis::Type &axis) {
171171
}
172172
}
173173

174-
Cube::Cube(const float size, const glm::vec3 &position) : m_size(size), m_position(position) {}
174+
Cube::Cube(const float size, const glm::vec3 &position)
175+
: m_size(size), m_position(position), m_center(position + 0.5f * size) {}
175176

176177
Cube::Cube(std::weak_ptr<Cube> parent, const std::uint8_t index, const float size, const glm::vec3 &position)
177178
: Cube(size, position) {

0 commit comments

Comments
 (0)