diff --git a/Editor/src/ComponentsPanel/TransformPanel.h b/Editor/src/ComponentsPanel/TransformPanel.h index 95881713..7eba2c65 100644 --- a/Editor/src/ComponentsPanel/TransformPanel.h +++ b/Editor/src/ComponentsPanel/TransformPanel.h @@ -30,7 +30,7 @@ public: //ImGuiHelper::DrawVec3("Rotation", &component.Rotation); ImGui::TableNextColumn(); - ComponentTableReset(component.Rotation, Nuake::Vector3(0, 0, 0)); + //ComponentTableReset(component.Rotation, Nuake::Vector3(0, 0, 0)); } ImGui::TableNextColumn(); { diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 8b1637f8..f18865b9 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -93,6 +93,7 @@ namespace Nuake { ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); ImGuizmo::SetDrawlist(); + ImGuizmo::AllowAxisFlip(false); ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); if (m_DrawGrid && !Engine::IsPlayMode) @@ -111,14 +112,19 @@ namespace Nuake { auto editorCam = Engine::GetCurrentScene()->GetCurrentCamera(); Matrix4 cameraView = editorCam->GetTransform(); Matrix4 cameraProjection = editorCam->GetPerspective(); + ImGuizmo::Manipulate( glm::value_ptr(cameraView), glm::value_ptr(cameraProjection), - CurrentOperation, CurrentMode, glm::value_ptr(transform), 0, 0 + CurrentOperation, CurrentMode, + glm::value_ptr(transform) ); if (ImGuizmo::IsUsing()) { + tc.LocalTransform = transform; + tc.GlobalTransform = transform; + //Entity currentParent = Selection.Entity; //if (parent.HasParent) //{ @@ -126,18 +132,17 @@ namespace Nuake { // transform *= inverseParent; //} - Vector3 scale; - glm::quat rotation; - Vector3 translation; - Vector3 skew; - Vector4 perspective; - glm::decompose(transform, scale, rotation, translation, skew, perspective); - - rotation = glm::conjugate(rotation); - - tc.Translation = translation; - tc.Orientation = rotation; - tc.Scale = scale; + //Vector3 scale; + //Quat rotation; + //Vector3 translation; + //Vector3 skew; + //Vector4 perspective; + //glm::decompose(transform, scale, rotation, translation, skew, perspective); + //rotation = glm::conjugate(rotation); + // + //tc.Translation = translation; + //tc.Orientation = rotation; + //tc.Scale = scale; } } } diff --git a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp index 652c777a..6d617623 100644 --- a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp +++ b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp @@ -10,7 +10,7 @@ namespace Nuake tc.Translation = glm::vec3(from.x(), from.y(), from.z()); tc.Scale = glm::vec3(1.0f); - tc.Rotation = glm::vec3(0.0f); + //tc.Rotation = glm::vec3(0.0f); glBegin(GL_LINES); glColor3f((float)(color.x()), (float)(color.y()), (float)(color.z())); diff --git a/Nuake/src/Scene/Components/RigidbodyComponent.cpp b/Nuake/src/Scene/Components/RigidbodyComponent.cpp index f11bbdb2..3038f572 100644 --- a/Nuake/src/Scene/Components/RigidbodyComponent.cpp +++ b/Nuake/src/Scene/Components/RigidbodyComponent.cpp @@ -49,7 +49,7 @@ namespace Nuake { glm::vec3 newPosition = m_Rigidbody->GetPosition(); glm::vec3 newRotation = m_Rigidbody->GetRotation(); tc->Translation = newPosition; - tc->Rotation = newRotation; + //tc->Rotation = newRotation; } void RigidBodyComponent::SyncWithTransform(TransformComponent* tc) @@ -62,7 +62,7 @@ namespace Nuake { newTransform.setOrigin(btVector3(tc->Translation.x, tc->Translation.t, tc->Translation.z)); btQuaternion quat; - quat.setEulerZYX(tc->Rotation.x, tc->Rotation.y, tc->Rotation.z); + //quat.setEulerZYX(tc->Rotation.x, tc->Rotation.y, tc->Rotation.z); newTransform.setRotation(quat); m_Rigidbody->UpdateTransform(newTransform); } diff --git a/Nuake/src/Scene/Components/TransformComponent.cpp b/Nuake/src/Scene/Components/TransformComponent.cpp index 566fcb74..bd276af5 100644 --- a/Nuake/src/Scene/Components/TransformComponent.cpp +++ b/Nuake/src/Scene/Components/TransformComponent.cpp @@ -9,7 +9,7 @@ namespace Nuake Translation = Vector3(0, 0, 0); Orientation = Quat(0, 0, 0, 0); GlobalOrientation = Orientation; - Rotation = Vector3(0, 0, 0); + //Rotation = Vector3(0, 0, 0); Scale = Vector3(1, 1, 1); } @@ -24,7 +24,7 @@ namespace Nuake Matrix4 TransformComponent::GetGlobalTransform() const { - return GlobalTransform; + return LocalTransform; } Matrix4 TransformComponent::GetLocalTransform() const diff --git a/Nuake/src/Scene/Components/TransformComponent.h b/Nuake/src/Scene/Components/TransformComponent.h index 04b8b6cf..16d3497c 100644 --- a/Nuake/src/Scene/Components/TransformComponent.h +++ b/Nuake/src/Scene/Components/TransformComponent.h @@ -6,14 +6,14 @@ namespace Nuake { class TransformComponent { public: - bool Dirty = false; + bool Dirty = true; Vector3 Translation; Quat Orientation; - Vector3 Rotation; // TODO: Should use quaternions. + //Vector3 Rotation; // TODO: Should use quaternions. Vector3 Scale; Vector3 GlobalTranslation; - Vector3 GlobalRotation; + //Vector3 GlobalRotation; Quat GlobalOrientation; Vector3 GlobalScale; @@ -32,7 +32,7 @@ namespace Nuake BEGIN_SERIALIZE(); SERIALIZE_VAL_LBL("Type", "TransformComponent"); SERIALIZE_VEC3(Translation); - SERIALIZE_VEC3(Rotation); + //SERIALIZE_VEC3(Rotation); SERIALIZE_VEC3(Scale); END_SERIALIZE(); } @@ -41,7 +41,7 @@ namespace Nuake { BEGIN_DESERIALIZE(); this->Translation = Vector3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]); - this->Rotation = Vector3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]); + //this->Rotation = Vector3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]); this->Scale = Vector3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]); return true; } diff --git a/Nuake/src/Scene/Systems/TransformSystem.cpp b/Nuake/src/Scene/Systems/TransformSystem.cpp index d5096b2f..a662ab6b 100644 --- a/Nuake/src/Scene/Systems/TransformSystem.cpp +++ b/Nuake/src/Scene/Systems/TransformSystem.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include "src/Vendors/glm/gtx/matrix_decompose.hpp" namespace Nuake { TransformSystem::TransformSystem(Scene* scene) { @@ -49,12 +49,17 @@ namespace Nuake { { TransformComponent& transform = localTransformView.get(tv); - Matrix4 localTransform = Matrix4(1.0f); - localTransform = glm::translate(localTransform, transform.Translation); - localTransform *= glm::toMat4(transform.Orientation); - localTransform = glm::scale(localTransform, transform.Scale); + if (transform.Dirty) + { + Vector3 dum; + Vector4 dum2; + glm::decompose(transform.LocalTransform, transform.Scale, transform.Orientation, transform.Translation, dum, dum2); - transform.LocalTransform = localTransform; + transform.LocalTransform = Matrix4(1); + transform.LocalTransform = glm::translate(transform.LocalTransform, transform.Translation); + + transform.Dirty = false; + } } // Calculate all global transforms diff --git a/Nuake/src/Scripting/Modules/SceneModule.h b/Nuake/src/Scripting/Modules/SceneModule.h index 2de9afb4..f1de5073 100644 --- a/Nuake/src/Scripting/Modules/SceneModule.h +++ b/Nuake/src/Scripting/Modules/SceneModule.h @@ -234,9 +234,9 @@ namespace Nuake { Entity ent = Entity((entt::entity)handle, Engine::GetCurrentScene().get()); auto& transform = ent.GetComponent(); // set the slots - wrenSetSlotDouble(vm, 1, transform.Rotation.x); - wrenSetSlotDouble(vm, 2, transform.Rotation.y); - wrenSetSlotDouble(vm, 3, transform.Rotation.z); + //wrenSetSlotDouble(vm, 1, transform.Rotation.x); + //wrenSetSlotDouble(vm, 2, transform.Rotation.y); + //wrenSetSlotDouble(vm, 3, transform.Rotation.z); // Fill the list wrenSetSlotNewList(vm, 0); @@ -255,7 +255,7 @@ namespace Nuake { float y = wrenGetSlotDouble(vm, 3); float z = wrenGetSlotDouble(vm, 4); - transform.Rotation = Vector3(x, y, z); + transform.SetRotation(x, y, z); } static void SetTranslation(WrenVM* vm)