Fixed editor widgets to take scale of the entity into account when they're moved
This commit is contained in:
@@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer,
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
|
||||
auto resolution = Rectangle::Rectangle(1280, 720);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.001f, 500.f);
|
||||
}
|
||||
|
||||
void EditorRenderSystem::Update(double dt)
|
||||
|
||||
@@ -204,14 +204,21 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
|
||||
if (m_CurrentSelection.Valid()) {
|
||||
if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
|
||||
glm::quat parentOrientation;
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
}
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
|
||||
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
}
|
||||
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
|
||||
glm::vec3 localTranslation = selectionOri * e.Translation;
|
||||
glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
|
||||
}
|
||||
m_EditorGUI->SetDirty(m_CurrentSelection);
|
||||
|
||||
Reference in New Issue
Block a user