Skip to content

Commit d87ec64

Browse files
committed
Refacotr PR requests
- rotate lighthouse image so it better follows the cursor - adjust whitespace - fix unit vector typo
1 parent 7cef3ab commit d87ec64

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

assets/images/lighthouse.png

20.2 KB
Loading

src/lighhouse.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
#include <le2d/event.hpp>
77
#include <le2d/renderer.hpp>
88
#include <le2d/service_locator.hpp>
9-
#include "glm/ext/vector_float2.hpp"
10-
#include "gsl/pointers"
9+
#include <optional>
1110
#include "le2d/texture.hpp"
11+
1212
namespace miracle {
1313
class Lighthouse {
1414
public:
1515
explicit Lighthouse(gsl::not_null<le::ServiceLocator const*> services);
16-
void rotate_towards_cursor(glm::vec2 const& cursor_pos);
16+
17+
void rotate_towards_cursor(glm::vec2 cursor_pos);
1718
void render(le::Renderer& renderer) const;
1819

1920
private:
20-
le::drawable::Circle m_sprite{};
21-
std::optional<le::Texture> m_texture;
2221
gsl::not_null<le::ServiceLocator const*> m_services;
22+
std::optional<le::Texture> m_texture;
23+
le::drawable::Circle m_sprite{};
2324
};
2425
} // namespace miracle

src/lighthouse.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "le2d/data_loader.hpp"
44

55
namespace miracle {
6-
76
Lighthouse::Lighthouse(gsl::not_null<le::ServiceLocator const*> services) : m_services(services) {
87
m_sprite.create(200.0f);
98

@@ -13,17 +12,18 @@ Lighthouse::Lighthouse(gsl::not_null<le::ServiceLocator const*> services) : m_se
1312
m_texture = asset_loader.load_texture("images/lighthouse.png");
1413
m_sprite.texture = &m_texture.value();
1514
}
16-
void Lighthouse::rotate_towards_cursor(glm::vec2 const& cursor_pos) {
15+
16+
void Lighthouse::rotate_towards_cursor(glm::vec2 cursor_pos) {
1717
auto const dist_sq = glm::length2((cursor_pos));
1818
if (dist_sq > 0.1f) {
1919
auto const dist = std::sqrt(dist_sq);
2020
auto const normalized = cursor_pos / dist;
21-
static constexpr auto up_v = glm::vec2(0.01f, 1.0f);
21+
static constexpr auto up_v = glm::vec2(0.0f, 1.0f);
2222
auto const dot = glm::dot(normalized, up_v);
2323
auto const angle = glm::degrees(std::acos(dot));
2424
m_sprite.transform.orientation = cursor_pos.x > 0.0f ? -angle : angle;
2525
}
2626
}
2727

2828
void Lighthouse::render(le::Renderer& renderer) const { m_sprite.draw(renderer); }
29-
} // namespace miracle
29+
} // namespace miracle

0 commit comments

Comments
 (0)