Skip to content

Commit

Permalink
fixing rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Nov 14, 2024
1 parent f27e5ef commit f401b36
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions runtime/Includes/Core/Graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace mlx
Text& new_text = p_scene->CreateText(str);
new_text.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
new_text.SetColor(std::move(vec_color));
new_text.SetCenter(Vec2f{ 0.0f, 0.0f });
}
else if(!p_scene->IsTextAtGivenDrawLayer(str, m_draw_layer))
p_scene->BringToDrawLayer(text.Get(), m_draw_layer);
Expand All @@ -72,10 +71,10 @@ namespace mlx
m_pixelput_called = false;
}
Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetCenter(Vec2f{ texture->GetWidth() / 2.0f, texture->GetHeight() / 2.0f });
new_sprite.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
new_sprite.SetScale(Vec2f{ scale, scale });
new_sprite.SetRotation(angle);
new_sprite.SetCenter(Vec2f{ texture->GetWidth() / 2.0f, texture->GetHeight() / 2.0f });
}
else if(!p_scene->IsTextureAtGivenDrawLayer(texture, m_draw_layer))
p_scene->BringToDrawLayer(sprite.Get(), m_draw_layer);
Expand Down
2 changes: 1 addition & 1 deletion runtime/Includes/Graphics/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace mlx
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
Vec2f m_position = Vec2f{ 0.0f, 0.0f };
Vec2f m_scale = Vec2f{ 1.0f, 1.0f };
Vec2f m_center;
Vec2f m_center = Vec2f{ 0.0f, 0.0f };
DrawableType m_type;
};
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/Includes/Maths/Mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ namespace mlx
static constexpr Mat4 ConcatenateTransform(const Mat4& left, const Mat4& right);
static constexpr Mat4 Identity();
static constexpr Mat4 LookAt(const Vec3<T>& eye, const Vec3<T>& target, const Vec3<T>& up = Vec3<T>::Up());
static constexpr Mat4 Ortho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0);
static Mat4 Perspective(RadianAngle<T> angle, T ratio, T zNear, T zFar);
static constexpr Mat4 Ortho(T left, T right, T top, T bottom, T z_near = -1.0, T zFar = 1.0);
static Mat4 Perspective(RadianAngle<T> angle, T ratio, T z_near, T z_far);
static constexpr Mat4 Rotate(const Quat<T>& rotation);
static constexpr Mat4 Scale(const Vec3<T>& scale);
static constexpr Mat4 Translate(const Vec3<T>& translation);
Expand Down
9 changes: 5 additions & 4 deletions runtime/Includes/Maths/Quaternions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ namespace mlx
template<typename U> constexpr explicit Quat(const Quat<U>& quat);
constexpr Quat(const Quat&) = default;
constexpr Quat(Quat&&) = default;
~Quat() = default;

RadianAngle<T> AngleBetween(const Quat& vec) const;
constexpr bool ApproxEqual(const Quat& quat, T maxDifference = std::numeric_limits<T>::epsilon()) const;
constexpr bool ApproxEqual(const Quat& quat, T max_difference = std::numeric_limits<T>::epsilon()) const;

Quat& ComputeW();
constexpr Quat& Conjugate();
Expand Down Expand Up @@ -68,16 +67,18 @@ namespace mlx
constexpr bool operator>=(const Quat& quat) const;

static RadianAngle<T> AngleBetween(const Quat& lhs, const Quat& rhs);
static constexpr bool ApproxEqual(const Quat& lhs, const Quat& rhs, T maxDifference = std::numeric_limits<T>::epsilon());
static constexpr bool ApproxEqual(const Quat& lhs, const Quat& rhs, T max_difference = std::numeric_limits<T>::epsilon());
static constexpr Quat Identity();
static constexpr Quat Lerp(const Quat& from, const Quat& to, T interpolation);
static Quat LookAt(const Vec3<T>& forward, const Vec3<T>& up);
static Quat Normalize(const Quat& quat, T* length = nullptr);
static Quat RotationBetween(const Vec3<T>& from, const Vec3<T>& to);
static Quat RotateTowards(const Quat& from, const Quat& to, RadianAngle<T> maxRotation);
static Quat RotateTowards(const Quat& from, const Quat& to, RadianAngle<T> max_rotation);
static Quat Mirror(Quat quat, const Vec3<T>& axis);
static Quat Slerp(const Quat& from, const Quat& to, T interpolation);
static constexpr Quat Zero();

~Quat() = default;
};

using Quatd = Quat<double>;
Expand Down
8 changes: 4 additions & 4 deletions runtime/Sources/Renderer/RenderPasses/2DPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ namespace mlx
DrawableData drawable_data;
drawable_data.color = drawable->GetColor();
drawable_data.model_matrix = Mat4f::Identity();
drawable_data.model_matrix.SetTranslation(Vec3f{ drawable->GetPosition(), 0.0f });
drawable_data.model_matrix.SetScale(Vec3f{ drawable->GetScale(), 1.0f });
drawable_data.model_matrix.SetRotation(drawable->GetRotation());
//drawable_data.model_matrix = Mat4f::Translate(-Vec3f{ drawable->GetCenter(), 0.0f }) * Mat4f::Rotate(drawable->GetRotation()) * drawable_data.model_matrix;
drawable_data.model_matrix.ApplyTranslation(Vec3f{ -drawable->GetCenter() / 2.0f, 0.0f });
drawable_data.model_matrix.ApplyRotation(drawable->GetRotation());
drawable_data.model_matrix.ApplyTranslation(Vec3f{ drawable->GetPosition() + drawable->GetCenter(), 0.0f });
drawable_data.model_matrix.ApplyScale(Vec3f{ drawable->GetScale(), 1.0f });

drawable->Bind(frame_index, cmd);

Expand Down

0 comments on commit f401b36

Please sign in to comment.