mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
FIxed gizmo
This commit is contained in:
@@ -182,48 +182,48 @@ namespace Nuake {
|
||||
if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode())
|
||||
{
|
||||
TransformComponent& tc = Selection.Entity.GetComponent<TransformComponent>();
|
||||
ParentComponent& parent = Selection.Entity.GetComponent<ParentComponent>();
|
||||
Matrix4 transform = tc.GetGlobalTransform();
|
||||
|
||||
auto editorCam = Engine::GetCurrentScene()->GetCurrentCamera();
|
||||
const auto& editorCam = Engine::GetCurrentScene()->GetCurrentCamera();
|
||||
Matrix4 cameraView = editorCam->GetTransform();
|
||||
Matrix4 cameraProjection = editorCam->GetPerspective();
|
||||
|
||||
// Imguizmo calculates the delta from the gizmo,
|
||||
ImGuizmo::Manipulate(
|
||||
glm::value_ptr(cameraView),
|
||||
glm::value_ptr(cameraProjection),
|
||||
CurrentOperation, CurrentMode,
|
||||
glm::value_ptr(transform)
|
||||
);
|
||||
Matrix4 oldTransform = transform;
|
||||
|
||||
if (ImGuizmo::IsUsing())
|
||||
{
|
||||
Vector3 globalPos = Vector3();
|
||||
Entity currentParent = Selection.Entity;
|
||||
// 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;
|
||||
ParentComponent& parent = Selection.Entity.GetComponent<ParentComponent>();
|
||||
if (parent.HasParent)
|
||||
{
|
||||
Matrix4 inverseParent = glm::inverse(parent.Parent.GetComponent<TransformComponent>().GetGlobalTransform());
|
||||
oldTransform *= inverseParent;
|
||||
localTransform = inverseParent * localTransform;
|
||||
}
|
||||
|
||||
// Decompose local transform
|
||||
Vector3 scale = Vector3();
|
||||
Quat rotation = Quat();
|
||||
Vector3 pos = Vector3();
|
||||
Vector3 skew = Vector3();
|
||||
Vector4 pesp = Vector4();
|
||||
glm::decompose(oldTransform, scale, rotation, pos, skew, pesp);
|
||||
|
||||
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(localTransform), glm::value_ptr(pos), glm::value_ptr(rotation), glm::value_ptr(scale));
|
||||
|
||||
tc.Translation = pos;
|
||||
tc.Rotation = rotation;
|
||||
//tc.Rotation = rotation;
|
||||
tc.Scale = scale;
|
||||
tc.LocalTransform = oldTransform;
|
||||
tc.LocalTransform = localTransform;
|
||||
|
||||
// Decompose global trasnform
|
||||
Vector3 gscale = Vector3();
|
||||
Quat grotation = Quat();
|
||||
Vector3 gpos = Vector3();
|
||||
Vector3 gskew = Vector3();
|
||||
Vector4 gpesp = Vector4();
|
||||
glm::decompose(transform, gscale, grotation, gpos, skew, pesp);
|
||||
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(transform), glm::value_ptr(gpos), glm::value_ptr(grotation), glm::value_ptr(gscale));
|
||||
|
||||
tc.SetGlobalPosition(gpos);
|
||||
tc.SetGlobalRotation(grotation);
|
||||
|
||||
@@ -10,5 +10,5 @@ Quat Nuake::QuatFromEuler(float x, float y, float z)
|
||||
Vector3 Nuake::QuatToDirection(const Quat& quat)
|
||||
{
|
||||
//return quat * Vector3(0, 0, -1);
|
||||
return glm::rotate(glm::inverse(quat), glm::vec3(-1.0, 0.0, 0.0));
|
||||
return glm::rotate(glm::inverse(quat), glm::vec3(0.0, 0.0, 1.0));
|
||||
}
|
||||
@@ -73,6 +73,7 @@ namespace Nuake
|
||||
|
||||
LocalTransform = Matrix4(1);
|
||||
GlobalTransform = Matrix4(1);
|
||||
this->Dirty = true;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -135,22 +135,14 @@ namespace Nuake {
|
||||
void Scene::Draw(FrameBuffer& framebuffer)
|
||||
{
|
||||
Ref<Camera> cam = nullptr;
|
||||
Matrix4 camTransform = Matrix4();
|
||||
const auto& view = m_Registry.view<TransformComponent, CameraComponent, ParentComponent>();
|
||||
for (const auto& e : view)
|
||||
{
|
||||
auto view = m_Registry.view<TransformComponent, CameraComponent, ParentComponent>();
|
||||
for (auto e : view)
|
||||
{
|
||||
auto [transform, camera, parent] = view.get<TransformComponent, CameraComponent, ParentComponent>(e);
|
||||
cam = camera.CameraInstance;
|
||||
auto [transform, camera, parent] = view.get<TransformComponent, CameraComponent, ParentComponent>(e);
|
||||
cam = camera.CameraInstance;
|
||||
|
||||
cam->Translation = transform.GetGlobalPosition();
|
||||
|
||||
//const Vector3& forward = QuatToDirection(transform.GetGlobalRotation());
|
||||
//cam->SetDirection(forward);
|
||||
|
||||
//camTransform = transform.GetGlobalTransform();
|
||||
break;
|
||||
}
|
||||
cam->Translation = transform.GetGlobalPosition();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!cam)
|
||||
@@ -158,10 +150,6 @@ namespace Nuake {
|
||||
return;
|
||||
}
|
||||
|
||||
float x = cam->GetDirection().x;
|
||||
float y = cam->GetDirection().y;
|
||||
float z = cam->GetDirection().z;
|
||||
Logger::Log("DIRECTION: (" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(z) + ")");
|
||||
mSceneRenderer->BeginRenderScene(cam->GetPerspective(), cam->GetTransform(), cam->Translation);
|
||||
mSceneRenderer->RenderScene(*this, framebuffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user