Fix collision radius size when zooming
This commit is contained in:
parent
1ce793c6e8
commit
df6d323e42
@ -15,6 +15,18 @@ public:
|
|||||||
WorldPos WindowToWorld(WindowPos) const;
|
WorldPos WindowToWorld(WindowPos) const;
|
||||||
WindowSize WorldToWindowSize(WorldSize) const;
|
WindowSize WorldToWindowSize(WorldSize) const;
|
||||||
WorldSize WindowToWorldSize(WindowSize) const;
|
WorldSize WindowToWorldSize(WindowSize) const;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
requires std::floating_point<T>
|
||||||
|
T WindowToWorldSize(T window_size) const {
|
||||||
|
return window_size / static_cast<T>(m_Zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
requires std::floating_point<T>
|
||||||
|
T WorldToWindowSize(T world_size) const {
|
||||||
|
return world_size * static_cast<T>(m_Zoom);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO this should be replaced with a matrix
|
// TODO this should be replaced with a matrix
|
||||||
|
@ -43,13 +43,14 @@ void GameLoop::Draw() {
|
|||||||
// draw all the entities (player etc)
|
// draw all the entities (player etc)
|
||||||
for (auto &entity : m_Game->GetEntities()) {
|
for (auto &entity : m_Game->GetEntities()) {
|
||||||
const auto &camera = m_Game->GetCamera();
|
const auto &camera = m_Game->GetCamera();
|
||||||
auto entity_pos_window = camera.WorldToWindow(entity->GetPosition());
|
auto entity_pos = camera.WorldToWindow(entity->GetPosition());
|
||||||
m_Window->DrawSprite(entity_pos_window,
|
m_Window->DrawSprite(entity_pos,
|
||||||
entity->GetSprite(),
|
entity->GetSprite(),
|
||||||
camera.GetZoom());
|
camera.GetZoom());
|
||||||
if (entity->IsCollisionBoxVisible())
|
if (entity->IsCollisionBoxVisible())
|
||||||
{
|
{
|
||||||
m_Window->DrawCircle(entity_pos_window, entity->GetCollisionRadius());
|
float collision_radius = camera.WorldToWindowSize(entity->GetCollisionRadius());
|
||||||
|
m_Window->DrawCircle(entity_pos, collision_radius);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user