diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 534d1a39..38133729 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -204,7 +204,7 @@ namespace Nuake { // Since imguizmo returns a transform in global space and we want the local transform, // we need to multiply by the inverse of the parent's global transform in order to revert // the changes from the parent transform. - Matrix4 localTransform = transform; + Matrix4 localTransform = Matrix4(transform); ParentComponent& parent = Selection.Entity.GetComponent(); if (parent.HasParent) { @@ -221,43 +221,41 @@ namespace Nuake { Vector4 pesp = Vector4(); glm::decompose(localTransform, scale, rotation, pos, skew, pesp); - float newScale[3]; float newRot[3]; float rotates[3]; float newPos[3]; ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(localTransform), newPos, newRot, newScale); - rotates[0] = -newRot[0]; - rotates[1] = -newRot[1]; + rotates[0] = newRot[0]; + rotates[1] = newRot[1]; rotates[2] = newRot[2]; + + auto newnewScale = Vector3(newScale[0], newScale[1], newScale[2]); + glm::mat3 rotationMatrix2 = glm::mat3(localTransform); + glm::quat rotationQuaternion = glm::normalize(glm::quat(rotationMatrix2)); auto rott = QuatFromEuler(rotates[0], rotates[1], rotates[2]); - - - - const Matrix4& rotationMatrix = glm::mat4_cast(glm::conjugate(rott)); - const Matrix4& scaleMatrix = glm::scale(Matrix4(1.0f), scale); + const Matrix4& rotationMatrix = glm::mat4_cast(rott); + const Matrix4& scaleMatrix = glm::scale(Matrix4(1.0f), newnewScale); const Matrix4& translationMatrix = glm::translate(Matrix4(1.0f), pos); const Matrix4& newLocalTransform = translationMatrix * rotationMatrix * scaleMatrix; //assert(newLocalTransform == localTransform); tc.Translation = pos; - tc.Rotation = glm::normalize(glm::conjugate(rotation)); - tc.Scale = scale; + tc.Rotation = rotationQuaternion; + tc.Scale = newnewScale; tc.LocalTransform = newLocalTransform; tc.Dirty = true; - - // Decompose global trasnform - //Vector3 gscale = Vector3(); - //Quat grotation = Quat(); - //Vector3 gpos = Vector3(); - //Vector3 gskew = Vector3(); - //Vector4 gpesp = Vector4(); - //glm::decompose(transform, gscale, grotation, gpos, gskew, gpesp); - // - ////glm::quat rotationQuaternionG = glm::quat_cast(transform); + Vector3 gscale = Vector3(); + Quat grotation = Quat(); + Vector3 gpos = Vector3(); + Vector3 gskew = Vector3(); + Vector4 gpesp = Vector4(); + glm::decompose(transform, gscale, grotation, gpos, gskew, gpesp); + + //glm::quat rotationQuaternionG = glm::quat_cast(transform); //tc.SetGlobalPosition(gpos); //tc.SetGlobalRotation(glm::conjugate(grotation)); //tc.SetGlobalScale(gscale); diff --git a/Nuake/src/Core/Maths.cpp b/Nuake/src/Core/Maths.cpp index 9009df68..e1edc573 100644 --- a/Nuake/src/Core/Maths.cpp +++ b/Nuake/src/Core/Maths.cpp @@ -37,12 +37,12 @@ Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle) Quat Nuake::QuatFromEuler(float x, float y, float z) { - glm::quat yawQuat = glm::angleAxis(Rad(y), glm::vec3(0.0f, 1.0f, 0.0f)); - glm::quat rollQuat = glm::angleAxis(Rad(z), glm::vec3(0.0f, 0.0f, 1.0f)); - glm::quat pitchQuat = glm::angleAxis(Rad(x), glm::vec3(1.0f, 0.0f, 0.0f)); - glm::quat orientation = yawQuat * pitchQuat * rollQuat; + glm::quat pitchQuat = glm::angleAxis(Rad(x), glm::vec3(1.0f, 0.0f, 0.0f)); + glm::quat yawQuat = glm::angleAxis(Rad(y), glm::vec3(0.0f, 1.0f, 0.0f)); + glm::quat rollQuat = glm::angleAxis(Rad(z), glm::vec3(0.0f, 0.0f, -1.0f)); + glm::quat orientation = yawQuat * pitchQuat * rollQuat; - return glm::normalize(orientation); + return glm::normalize(orientation); return Quat(Vector3(Rad(x), Rad(y), Rad(z))); diff --git a/Nuake/src/Scene/Systems/TransformSystem.cpp b/Nuake/src/Scene/Systems/TransformSystem.cpp index cd7cfaa4..3e5b69b9 100644 --- a/Nuake/src/Scene/Systems/TransformSystem.cpp +++ b/Nuake/src/Scene/Systems/TransformSystem.cpp @@ -47,14 +47,11 @@ namespace Nuake auto& localRot = glm::normalize(transform.GetLocalRotation()); auto& localScale = transform.GetLocalScale(); const Matrix4& translationMatrix = glm::translate(Matrix4(1.0f), localTranslate); - const Matrix4& rotationMatrix = glm::mat4_cast(localRot); const Matrix4& scaleMatrix = glm::scale(Matrix4(1.0f), localScale); const Matrix4& newLocalTransform = translationMatrix * rotationMatrix * scaleMatrix; - - - //localRot *= -1.0f; - //if(localRot.y != 0) + // localRot *= -1.0f; + // if(localRot.y != 0) // assert(newLocalTransform == transform.GetLocalTransform()); transform.SetLocalTransform(newLocalTransform); @@ -67,7 +64,6 @@ namespace Nuake for (auto e : transformView) { auto [parent, transform] = transformView.get(e); - if (!parent.HasParent) { // If no parents, then globalTransform is local transform. @@ -99,7 +95,7 @@ namespace Nuake NameComponent& nameComponent = parentComponent.Parent.GetComponent(); parentComponent = parentComponent.Parent.GetComponent(); } - + transform.SetGlobalPosition(globalPosition); transform.SetGlobalRotation(globalOrientation); transform.SetGlobalScale(globalScale);