adding transformations

This commit is contained in:
2024-11-13 12:17:59 +01:00
parent eaf5be3061
commit e29ea92202
18 changed files with 141 additions and 130 deletions

View File

@@ -27,14 +27,17 @@ namespace mlx
return *sprite;
}
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
NonOwningPtr<Sprite> Scene::GetSpriteFromTexturePositionScaleRotation(NonOwningPtr<Texture> texture, const Vec2f& position, float scale, float rotation) const
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position](std::shared_ptr<Drawable> drawable)
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position, scale, rotation](std::shared_ptr<Drawable> drawable)
{
if(!drawable || drawable->GetType() != DrawableType::Sprite)
return false;
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture && drawable->GetPosition() == position;
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture &&
drawable->GetPosition() == position &&
drawable->GetScale() == Vec2f{ scale, scale } &&
drawable->GetRotation() == EulerAnglesf{ 0.0f, 0.0f, rotation };
});
return static_cast<Sprite*>(it != m_drawables.end() ? it->get() : nullptr);
}