From 8ebbd674b2573011d16d7852cd990227bad9dcbe Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 31 Aug 2024 00:04:20 +0800 Subject: [PATCH] Moved WorldPosition to SceneMatrix --- CMCore | 2 +- inc/hgl/graph/SceneOrient.h | 55 +++++++++++++++++++++++----------- src/SceneGraph/SceneOrient.cpp | 5 ---- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/CMCore b/CMCore index 0ac2a943..df5189ed 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 0ac2a9431a14767c018f6f20a8ea0a3604b859ee +Subproject commit df5189ed09cab1197ddbb4e9f5a3d7959c961e3e diff --git a/inc/hgl/graph/SceneOrient.h b/inc/hgl/graph/SceneOrient.h index 48271dc5..4c10e851 100644 --- a/inc/hgl/graph/SceneOrient.h +++ b/inc/hgl/graph/SceneOrient.h @@ -7,6 +7,20 @@ namespace hgl { namespace graph { + /** + * 场景节点矩阵类
+ * + * 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。
+ * 构成说明:
+ * + * + * LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix
+ */ class SceneMatrix :public VersionData { protected: @@ -16,6 +30,9 @@ namespace hgl TransformManager transform_manager; Matrix4f transform_matrix; + Vector3f OriginWorldPosition; //原始世界坐标 + Vector3f FinalWorldPosition; //最终世界坐标 + protected: Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵 @@ -23,9 +40,22 @@ namespace hgl void MakeNewestData(Matrix4f &local_to_world_matrix) override ///<生成最新的数据(需要派生类重载) { - transform_manager.GetMatrix(transform_matrix); + local_to_world_matrix=parent_matrix*local_matrix; - local_to_world_matrix=parent_matrix*local_matrix*transform_matrix; + OriginWorldPosition=TransformPosition(local_to_world_matrix,ZeroVector3f); + + if(transform_manager.IsEmpty()) + { + FinalWorldPosition=OriginWorldPosition; + } + else + { + transform_manager.GetMatrix(transform_matrix,OriginWorldPosition); + + local_to_world_matrix*=transform_matrix; + + FinalWorldPosition=TransformPosition(local_to_world_matrix,ZeroVector3f); + } inverse_local_to_world_matrix =inverse(local_to_world_matrix); inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix); @@ -51,7 +81,9 @@ namespace hgl return inverse_transpose_local_to_world_matrix; } - TransformManager &GetTransform() { return transform_manager; } ///<取得变换管理器 + TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器 + + const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标 public: @@ -101,16 +133,6 @@ namespace hgl /** * 方向定位数据基类
- * 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。
- * 构成说明:
- * - * - * LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix
*/ class SceneOrient ///场景定位类 { @@ -118,8 +140,6 @@ namespace hgl SceneMatrix scene_matrix; - Vector3f WorldPosition; - public: SceneOrient()=default; @@ -130,7 +150,6 @@ namespace hgl virtual void Clear() { scene_matrix.Clear(); - WorldPosition=ZeroVector3f; } void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵 @@ -138,9 +157,9 @@ namespace hgl public: - const uint32 GetLocalToWorldMatrixVersion()const { return scene_matrix.GetNewestVersion(); } ///<取得版本号 + const uint32 GetLocalToWorldMatrixVersion()const {return scene_matrix.GetNewestVersion();} ///<取得版本号 - const Vector3f & GetWorldPosition() const { return WorldPosition; } ///<取得世界坐标 + const Vector3f & GetWorldPosition() const {return scene_matrix.GetWorldPosition();} ///<取得世界坐标 const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵 TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器 diff --git a/src/SceneGraph/SceneOrient.cpp b/src/SceneGraph/SceneOrient.cpp index 003792d3..c7d49a07 100644 --- a/src/SceneGraph/SceneOrient.cpp +++ b/src/SceneGraph/SceneOrient.cpp @@ -6,7 +6,6 @@ namespace hgl SceneOrient::SceneOrient(const SceneOrient &so) { scene_matrix=so.scene_matrix; - WorldPosition=so.WorldPosition; scene_matrix.UpdateNewestData(); } @@ -16,8 +15,6 @@ namespace hgl scene_matrix.SetLocalMatrix(mat); scene_matrix.UpdateNewestData(); - - WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f); } void SceneOrient::RefreshMatrix() @@ -27,8 +24,6 @@ namespace hgl //是最新版本,证明没有更新,那不用刷新了 return; } - - WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f); } }//namespace graph }//namespace hgl