Skip to content

Commit 273255e

Browse files
committed
fixing transformations
1 parent f9ef8fc commit 273255e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

runtime/Sources/Core/Graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace mlx
143143
m_pixelput_called = false;
144144
}
145145
Sprite& new_sprite = p_scene->CreateSprite(texture);
146-
new_sprite.SetCenter(Vec2f{ texture->GetWidth() / 2.0f, texture->GetHeight() / 2.0f });
146+
new_sprite.SetCenter(Vec2f{ texture->GetWidth() * 0.5f, texture->GetHeight() * 0.5f });
147147
new_sprite.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
148148
new_sprite.SetScale(Vec2f{ scale_x, scale_y });
149149
new_sprite.SetRotation(angle);

runtime/Sources/Renderer/RenderPasses/2DPass.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,29 @@ namespace mlx
100100
for(auto& drawable : drawables)
101101
{
102102
// Check every textures and update modified ones to GPU before starting the render pass
103-
drawable->Update(cmd);
104103
if(!drawable->IsSetInit())
105104
drawable->UpdateDescriptorSet(p_texture_set);
105+
drawable->Update(cmd);
106106
}
107107

108108
m_pipeline.BindPipeline(cmd, 0, {});
109109
for(auto& drawable : drawables)
110110
{
111111
DrawableData drawable_data;
112112
drawable_data.color = drawable->GetColor();
113+
114+
Mat4f rotation_matrix = Mat4f::Identity();
115+
rotation_matrix.ApplyTranslation(Vec3f{ -drawable->GetCenter(), 0.0f });
116+
rotation_matrix.ApplyRotation(drawable->GetRotation());
117+
rotation_matrix.ApplyTranslation(Vec3f{ drawable->GetCenter(), 0.0f });
118+
119+
Mat4f translation_matrix = Mat4f::Identity().ApplyTranslation(Vec3f{ drawable->GetPosition(), 0.0f });
120+
Mat4f scale_matrix = Mat4f::Identity().ApplyScale(Vec3f{ drawable->GetScale(), 1.0f });
121+
113122
drawable_data.model_matrix = Mat4f::Identity();
114-
drawable_data.model_matrix.ApplyTranslation(Vec3f{ -drawable->GetCenter() / 2.0f, 0.0f });
115-
drawable_data.model_matrix.ApplyRotation(drawable->GetRotation());
116-
drawable_data.model_matrix.ApplyTranslation(Vec3f{ drawable->GetPosition() + drawable->GetCenter() / 2.0f, 0.0f });
117-
drawable_data.model_matrix.ApplyScale(Vec3f{ drawable->GetScale(), 1.0f });
123+
drawable_data.model_matrix.ConcatenateTransform(rotation_matrix);
124+
drawable_data.model_matrix.ConcatenateTransform(scale_matrix);
125+
drawable_data.model_matrix.ConcatenateTransform(translation_matrix);
118126

119127
drawable->Bind(frame_index, cmd);
120128

0 commit comments

Comments
 (0)