From 28d4d17d6233e9ef278c82a4aba049e0ecfa2fd5 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 1 Aug 2025 09:13:41 +0800 Subject: [PATCH] =?UTF-8?q?[working]=20gizmo3DMove=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=80=83=E8=99=91=E5=A6=82=E4=BD=95=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E5=8F=98=E5=8A=A8=E4=B8=AD=E7=9A=84gizmo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMCore | 2 +- CMPlatform | 2 +- example/Gizmo/Gizmo3DMove.cpp | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMCore b/CMCore index f1a36055..dd01d191 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit f1a36055e430e110e3ac1ff643920715b9efeb2d +Subproject commit dd01d1919a119d1aeac74dd4d4994ba45c0144ad diff --git a/CMPlatform b/CMPlatform index 5c4851e5..eec230df 160000 --- a/CMPlatform +++ b/CMPlatform @@ -1 +1 @@ -Subproject commit 5c4851e586b97f96f17180ba2574f02857be298a +Subproject commit eec230df6c48d55ea11d096dba34bbd0499a0d42 diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index 5645c8f8..4befa128 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -54,11 +54,15 @@ namespace MeshComponent *sphere=nullptr; GizmoMoveAxis axis[3]{}; //X,Y,Z 三个轴 - int CurAXIS=-1; //当前鼠标选中轴 - float CurDist=0; //当前距离 + protected: - int PickAXIS=-1; //拾取轴 - float PickDist=0; //拾取辆距离轴心的距离 + int CurAXIS=-1; //当前鼠标选中轴 + float CurDist=0; //当前距离 + + int PickAXIS=-1; //拾取轴 + float PickDist=0; //拾取辆距离轴心的距离 + + TransformTranslate3f CurTranslate; public: @@ -205,10 +209,12 @@ namespace { GizmoMoveNode::OnMove(mp); - if(CurAXIS>0&&CurAXIS<3) + if(CurAXIS>=0&&CurAXIS<3) { PickAXIS=CurAXIS; PickDist=CurDist; + + CurTranslate.SetOffset(Vector3f(0,0,0)); //重置当前平移偏移 } return io::EventProcResult::Continue; @@ -269,6 +275,12 @@ namespace CurAXIS=i; CurDist=glm::length(p_ls); //计算线段上的点与原点的距离 + + if(CurAXIS==PickAXIS) //如果当前轴与拾取轴相同 + { + //如果当前轴与拾取轴相同,则计算平移偏移 + CurTranslate.SetOffset(axis_vector*(CurDist-PickDist)); + } } else {