From 442e52e17cdbfbc4f6915c7dd928de68d23d2799 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 29 Aug 2024 13:37:13 +0800 Subject: [PATCH] [BUG] gizmoMove rootNote's ScaleMatrix's Z is non-work. --- CMCore | 2 +- example/Gizmo/Gizmo3DMove.cpp | 2 +- example/Gizmo/GizmoTest.cpp | 4 ++-- inc/hgl/graph/SceneNode.h | 7 ++++++- inc/hgl/graph/SceneOrient.h | 20 +++++++++++++++++--- src/SceneGraph/SceneNode.cpp | 4 ++-- src/SceneGraph/SceneOrient.cpp | 10 ++++++---- 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/CMCore b/CMCore index 45e02b7c..97743adb 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 45e02b7c7206ac459692d693c1b840f8378906d3 +Subproject commit 97743adb3f36fdda659b584e6ff93773b2a85f2a diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index 235b999b..9803a975 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -82,7 +82,7 @@ bool InitGizmoMoveStaticMesh() } { - SceneNode *root_node=new SceneNode(); + SceneNode *root_node=new SceneNode(scale(1,1,2)); //.////// XY有效,Z无效。。。在查为什么 root_node->CreateSubNode(sphere); diff --git a/example/Gizmo/GizmoTest.cpp b/example/Gizmo/GizmoTest.cpp index cb650dc1..730184b5 100644 --- a/example/Gizmo/GizmoTest.cpp +++ b/example/Gizmo/GizmoTest.cpp @@ -149,8 +149,8 @@ public: // root.SetLocalTransform(tm); //} - root.RefreshMatrix(); - render_list->UpdateLocalToWorld(); + //root.RefreshMatrix(); + //render_list->UpdateLocalToWorld(); SceneAppFramework::BuildCommandBuffer(index); } diff --git a/inc/hgl/graph/SceneNode.h b/inc/hgl/graph/SceneNode.h index cf51a9d0..cc023101 100644 --- a/inc/hgl/graph/SceneNode.h +++ b/inc/hgl/graph/SceneNode.h @@ -37,8 +37,13 @@ namespace hgl virtual ~SceneNode()=default; - void Clear() + void Clear() override { + SceneOrient::Clear(); + + BoundingBox.SetZero(); + LocalBoundingBox.SetZero(); + SubNode.Clear(); render_obj=nullptr; } diff --git a/inc/hgl/graph/SceneOrient.h b/inc/hgl/graph/SceneOrient.h index c2e81042..b9e4fed5 100644 --- a/inc/hgl/graph/SceneOrient.h +++ b/inc/hgl/graph/SceneOrient.h @@ -33,6 +33,14 @@ namespace hgl public: + void Clear() + { + parent_matrix=Identity4f; + local_matrix=Identity4f; + transform_matrix=Identity4f; + UpdateVersion(); + } + const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵 const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵 @@ -49,9 +57,7 @@ namespace hgl SceneMatrix():VersionData(Identity4f) { - parent_matrix=Identity4f; - local_matrix=Identity4f; - transform_matrix=Identity4f; + Clear(); } SceneMatrix(SceneMatrix &so):VersionData(so.GetLocalToWorldMatrix()) @@ -63,11 +69,13 @@ namespace hgl inverse_local_to_world_matrix=so.inverse_local_to_world_matrix; inverse_transpose_local_to_world_matrix=so.inverse_transpose_local_to_world_matrix; + UpdateVersion(); } SceneMatrix(const Matrix4f &mat):VersionData(Identity4f) { SetLocalMatrix(mat); + UpdateVersion(); } void SetLocalMatrix(const Matrix4f &mat) @@ -117,6 +125,12 @@ namespace hgl SceneOrient(const Matrix4f &); virtual ~SceneOrient()=default; + virtual void Clear() + { + scene_matrix.Clear(); + WorldPosition=ZeroVector3f; + } + void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵 void SetParentMatrix (const Matrix4f &mat){scene_matrix.SetParentMatrix(mat);} ///<设置上级到世界空间变换矩阵 diff --git a/src/SceneGraph/SceneNode.cpp b/src/SceneGraph/SceneNode.cpp index e3a278d1..eeb7d46a 100644 --- a/src/SceneGraph/SceneNode.cpp +++ b/src/SceneGraph/SceneNode.cpp @@ -44,8 +44,8 @@ namespace hgl */ void SceneNode::RefreshMatrix() { - if (scene_matrix.IsNewestVersion()) - return; +// if (scene_matrix.IsNewestVersion()) //自己不变,不代表下面不变 + //return; const Matrix2f &l2w=scene_matrix.GetLocalToWorldMatrix(); diff --git a/src/SceneGraph/SceneOrient.cpp b/src/SceneGraph/SceneOrient.cpp index 1daf4884..003792d3 100644 --- a/src/SceneGraph/SceneOrient.cpp +++ b/src/SceneGraph/SceneOrient.cpp @@ -7,13 +7,17 @@ namespace hgl { scene_matrix=so.scene_matrix; WorldPosition=so.WorldPosition; + + scene_matrix.UpdateNewestData(); } SceneOrient::SceneOrient(const Matrix4f &mat):SceneOrient() { scene_matrix.SetLocalMatrix(mat); + + scene_matrix.UpdateNewestData(); - WorldPosition=TransformPosition(mat,ZeroVector3f); + WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f); } void SceneOrient::RefreshMatrix() @@ -24,9 +28,7 @@ namespace hgl return; } - const Matrix4f &l2w=scene_matrix.GetNewestVersionData(); - - WorldPosition=TransformPosition(l2w,ZeroVector3f); + WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f); } }//namespace graph }//namespace hgl