[WIP] improving SceneOrient

This commit is contained in:
hyzboy 2024-08-25 04:03:57 +08:00
parent f4e16276ff
commit 410b94a127
3 changed files with 75 additions and 38 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 1fd9db054591942c3f4746052def3b621a1dbaff Subproject commit 529ad6b4037865b871f3406fa528ef1ec80d56a8

View File

@ -1,9 +1,8 @@
#ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE #ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE
#define HGL_GRAPH_SCENE_ORIENT_INCLUDE #define HGL_GRAPH_SCENE_ORIENT_INCLUDE
//#include<hgl/type/List.h>
#include<hgl/math/Math.h>
#include<hgl/graph/VK.h> #include<hgl/graph/VK.h>
#include<hgl/math/Transform.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
@ -15,14 +14,22 @@ namespace hgl
{ {
protected: protected:
Matrix4f parent_matrix;
bool parent_matrix_dirty;
Matrix4f local_matrix;
bool local_matrix_dirty;
TransformManager transform_manager; TransformManager transform_manager;
uint32 transform_version;
Matrix4f ParentMatrix; ///<上级矩阵 uint32 local_to_world_matrix_version;
Matrix4f LocalMatrix; ///<本地到上一级矩阵 // LocalToWorld = ParentMatrix * LocalMatrix * TransformMatrix
Matrix4f LocalToWorldMatrix; ///<本地到世界矩阵
Matrix4f InverseLocalToWorldMatrix; ///<世界到本地矩阵 Matrix4f local_to_world_matrix; ///<本地到世界矩阵
Matrix4f InverseTransposeLocalToWorldMatrix; ///<世界到本地矩阵的转置矩阵 Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
virtual void SetWorldMatrix(const Matrix4f &); virtual void SetWorldMatrix(const Matrix4f &);
@ -33,14 +40,16 @@ namespace hgl
SceneOrient(const Matrix4f &); SceneOrient(const Matrix4f &);
virtual ~SceneOrient()=default; virtual ~SceneOrient()=default;
void SetLocalMatrix(const Matrix4f &); ///<设置本地矩阵
public: public:
const Matrix4f & GetLocalMatrix ()const{return local_matrix;}
TransformManager * GetTransform (){return &transform_manager;} ///<取得变换管理器 TransformManager & GetTransform () {return transform_manager;} ///<取得变换管理器
const Matrix4f & GetLocalMatrix ()const{return LocalMatrix;} const Matrix4f & GetLocalToWorldMatrix ()const{return local_to_world_matrix;}
const Matrix4f & GetLocalToWorldMatrix ()const{return LocalToWorldMatrix;} const Matrix4f & GetInverseLocalToWorldMatrix ()const{return inverse_local_to_world_matrix;}
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return InverseLocalToWorldMatrix;} const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return inverse_transpose_local_to_world_matrix;}
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return InverseTransposeLocalToWorldMatrix;}
public: public:

View File

@ -5,60 +5,88 @@ namespace hgl
{ {
SceneOrient::SceneOrient() SceneOrient::SceneOrient()
{ {
LocalMatrix=Identity4f; parent_matrix=Identity4f;
local_matrix=Identity4f;
SetWorldMatrix(Identity4f); SetWorldMatrix(Identity4f);
parent_matrix_dirty=false;
local_matrix_dirty=false;
transform_version=transform_manager.GetCurrentVersion();
} }
SceneOrient::SceneOrient(const SceneOrient &so) SceneOrient::SceneOrient(const SceneOrient &so)
{ {
hgl_cpy(*this,so); #define SO_COPY(value) value=so.value;
SO_COPY(parent_matrix)
SO_COPY(parent_matrix_dirty)
SO_COPY(local_matrix)
SO_COPY(local_matrix_dirty)
SO_COPY(transform_manager)
SO_COPY(transform_version)
SO_COPY(local_to_world_matrix)
SO_COPY(inverse_local_to_world_matrix)
SO_COPY(inverse_transpose_local_to_world_matrix)
#undef SO_COPY
} }
SceneOrient::SceneOrient(const Matrix4f &mat) SceneOrient::SceneOrient(const Matrix4f &mat):SceneOrient()
{ {
SetLocalMatrix(mat); SetLocalMatrix(mat);
} }
void SceneOrient::SetLocalMatrix(const Matrix4f &mat) void SceneOrient::SetLocalMatrix(const Matrix4f &mat)
{ {
if(IsNearlyEqual(LocalMatrix,mat)) if(IsNearlyEqual(local_matrix,mat))
return; return;
LocalMatrix=mat; local_matrix=mat;
} }
void SceneOrient::SetWorldMatrix(const Matrix4f &wm) void SceneOrient::SetWorldMatrix(const Matrix4f &wm)
{ {
LocalToWorldMatrix =wm; local_to_world_matrix =wm;
InverseLocalToWorldMatrix =inverse(LocalToWorldMatrix); inverse_local_to_world_matrix =inverse(local_to_world_matrix);
InverseTransposeLocalToWorldMatrix =transpose(InverseLocalToWorldMatrix); inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
} }
/** /**
* *
* @param parent_matrix LocalToWorld变换矩阵 * @param parent_matrix LocalToWorld变换矩阵
*/ */
bool SceneOrient::RefreshMatrix(const Matrix4f &parent_matrix) bool SceneOrient::RefreshMatrix(const Matrix4f &pm)
{ {
if(hgl_cmp(ParentMatrix,parent_matrix)==0) //如果上一级到这一级没变自然是可以用memcmp比较的 if(hgl_cmp(pm,parent_matrix)==0) //如果上一级到这一级没变自然是可以用memcmp比较的
return(true); return(true);
ParentMatrix=parent_matrix; parent_matrix=pm;
if(IsIdentityMatrix(LocalMatrix)) Matrix4f tm;
{
SetWorldMatrix(parent_matrix); transform_manager.GetMatrix(tm);
}
else SetWorldMatrix(parent_matrix*local_matrix*tm);
if(IsIdentityMatrix(parent_matrix))
{ //if(IsIdentityMatrix(LocalMatrix))
SetWorldMatrix(LocalMatrix); //{
} // SetWorldMatrix(parent_matrix);
else // return(true);
{ //}
SetWorldMatrix(MatrixMult(parent_matrix,LocalMatrix)); //
}
//if(IsIdentityMatrix(parent_matrix))
//{
// SetWorldMatrix(LocalMatrix);
//}
//else
//{
// SetWorldMatrix(parent_matrix*LocalMatrix);
//}
return(true); return(true);
} }