Fix collision radius size when zooming
This commit is contained in:
parent
1ce793c6e8
commit
df6d323e42
@ -16,6 +16,18 @@ public:
|
||||
WindowSize WorldToWindowSize(WorldSize) 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:
|
||||
// TODO this should be replaced with a matrix
|
||||
float m_Zoom = 1.0f;
|
||||
|
@ -43,13 +43,14 @@ void GameLoop::Draw() {
|
||||
// draw all the entities (player etc)
|
||||
for (auto &entity : m_Game->GetEntities()) {
|
||||
const auto &camera = m_Game->GetCamera();
|
||||
auto entity_pos_window = camera.WorldToWindow(entity->GetPosition());
|
||||
m_Window->DrawSprite(entity_pos_window,
|
||||
auto entity_pos = camera.WorldToWindow(entity->GetPosition());
|
||||
m_Window->DrawSprite(entity_pos,
|
||||
entity->GetSprite(),
|
||||
camera.GetZoom());
|
||||
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