Skip to content

Commit

Permalink
Merge pull request #244 from adriengivry/fix/gizmo-behaviour
Browse files Browse the repository at this point in the history
Fixing UpdateLocalMatrix computation order if transform has parent + …
  • Loading branch information
maxbrundev committed May 29, 2023
2 parents ba9fcb9 + 3ef741b commit a56596b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* @licence: MIT
*/

#include <OvUI/Widgets/Texts/Text.h>
#include <OvUI/Widgets/Drags/DragMultipleFloats.h>

#include "OvCore/ECS/Components/CTransform.h"

OvCore::ECS::Components::CTransform::CTransform(ECS::Actor& p_owner, OvMaths::FVector3 p_localPosition, OvMaths::FQuaternion p_localRotation, OvMaths::FVector3 p_localScale) :
Expand Down
12 changes: 6 additions & 6 deletions Sources/Overload/OvEditor/src/OvEditor/Core/GizmoBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ OvMaths::FVector2 OvEditor::Core::GizmoBehaviour::GetScreenDirection(const OvMat
void OvEditor::Core::GizmoBehaviour::ApplyTranslation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const
{
auto unitsPerPixel = 0.001f * m_distanceToActor;
auto originPosition = m_originalTransform.GetLocalPosition();
auto originPosition = m_originalTransform.GetWorldPosition();

auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);

Expand All @@ -123,13 +123,13 @@ void OvEditor::Core::GizmoBehaviour::ApplyTranslation(const OvMaths::FMatrix4& p
translationCoefficient = SnapValue(translationCoefficient, OvEditor::Settings::EditorSettings::TranslationSnapUnit);
}

m_target->transform.SetLocalPosition(originPosition + GetRealDirection() * translationCoefficient);
m_target->transform.SetWorldPosition(originPosition + GetRealDirection(true) * translationCoefficient);
}

void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const
{
auto unitsPerPixel = 0.2f;
auto originRotation = m_originalTransform.GetLocalRotation();
auto originRotation = m_originalTransform.GetWorldRotation();

auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);
screenDirection = OvMaths::FVector2(-screenDirection.y, screenDirection.x);
Expand All @@ -143,13 +143,13 @@ void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_vi
}

auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient));
m_target->transform.SetLocalRotation(originRotation * rotationToApply);
m_target->transform.SetWorldRotation(originRotation * rotationToApply);
}

void OvEditor::Core::GizmoBehaviour::ApplyScale(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const
{
auto unitsPerPixel = 0.01f;
auto originScale = m_originalTransform.GetLocalScale();
auto originScale = m_originalTransform.GetWorldScale();

auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);

Expand All @@ -168,7 +168,7 @@ void OvEditor::Core::GizmoBehaviour::ApplyScale(const OvMaths::FMatrix4& p_viewM
newScale.y = std::max(newScale.y, 0.0001f);
newScale.z = std::max(newScale.z, 0.0001f);

m_target->transform.SetLocalScale(newScale);
m_target->transform.SetWorldScale(newScale);
}

void OvEditor::Core::GizmoBehaviour::ApplyOperation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Overload/OvMaths/src/OvMaths/FTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void OvMaths::FTransform::UpdateWorldMatrix()

void OvMaths::FTransform::UpdateLocalMatrix()
{
m_localMatrix = HasParent() ? m_worldMatrix * FMatrix4::Inverse(m_parent->m_worldMatrix) : m_worldMatrix;
m_localMatrix = HasParent() ? FMatrix4::Inverse(m_parent->m_worldMatrix) * m_worldMatrix : m_worldMatrix;
PreDecomposeLocalMatrix();

Notifier.NotifyChildren(Internal::TransformNotifier::ENotification::TRANSFORM_CHANGED);
Expand Down

0 comments on commit a56596b

Please sign in to comment.