From d11b84222f0c6e1abb7261467eb1aeaf062037a6 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 17 Jul 2024 23:56:10 +0800 Subject: [PATCH] Added IdentityLocalMatrix in SceneOrient --- inc/hgl/graph/SceneOrient.h | 4 ++++ src/SceneGraph/SceneOrient.cpp | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/inc/hgl/graph/SceneOrient.h b/inc/hgl/graph/SceneOrient.h index c7ee1379..e80f2471 100644 --- a/inc/hgl/graph/SceneOrient.h +++ b/inc/hgl/graph/SceneOrient.h @@ -21,6 +21,8 @@ namespace hgl Vector3f Position; ///<坐标 Vector3f Direction; ///<方向 + bool IdentityLocalMatrix; ///<是否为空矩阵 + Matrix4f LocalMatrix; ///<当前矩阵(指相对上一级的变换矩阵) Matrix4f LocalToWorldMatrix; ///<当前到世界矩阵 @@ -43,6 +45,8 @@ namespace hgl public: + const bool IsIdentityLocalMatrix ()const{return IdentityLocalMatrix;} ///<是否为空矩阵(相对上一级没变化) + Matrix4f & SetLocalMatrix (const Matrix4f &); ///<设定当前节点矩阵 Matrix4f & SetLocalToWorldMatrix (const Matrix4f &); ///<设定当前节点到世界矩阵 diff --git a/src/SceneGraph/SceneOrient.cpp b/src/SceneGraph/SceneOrient.cpp index f5b0ad12..fffbd187 100644 --- a/src/SceneGraph/SceneOrient.cpp +++ b/src/SceneGraph/SceneOrient.cpp @@ -8,6 +8,8 @@ namespace hgl Position=Vector3f(0.0f); Direction=Vector3f(0.0f); + IdentityLocalMatrix=true; + LocalMatrix =Identity4f; LocalToWorldMatrix =Identity4f; InverseLocalMatrix =Identity4f; @@ -26,6 +28,8 @@ namespace hgl { LocalMatrix=m; + IdentityLocalMatrix=IsIdentity(m); + InverseLocalMatrix=inverse(LocalMatrix); return LocalMatrix; @@ -46,7 +50,10 @@ namespace hgl */ void SceneOrient::RefreshLocalToWorldMatrix(const Matrix4f *m) { - SetLocalToWorldMatrix(TransformMatrix(*m,LocalMatrix)); + if(IdentityLocalMatrix) + SetLocalToWorldMatrix(*m); + else + SetLocalToWorldMatrix(TransformMatrix(*m,LocalMatrix)); } }//namespace graph }//namespace hgl