[WIP] improving SceneOrient
This commit is contained in:
parent
f4e16276ff
commit
410b94a127
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 1fd9db054591942c3f4746052def3b621a1dbaff
|
||||
Subproject commit 529ad6b4037865b871f3406fa528ef1ec80d56a8
|
@ -1,9 +1,8 @@
|
||||
#ifndef 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/math/Transform.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@ -14,15 +13,23 @@ namespace hgl
|
||||
class SceneOrient ///场景定位类
|
||||
{
|
||||
protected:
|
||||
|
||||
Matrix4f parent_matrix;
|
||||
bool parent_matrix_dirty;
|
||||
|
||||
Matrix4f local_matrix;
|
||||
bool local_matrix_dirty;
|
||||
|
||||
TransformManager transform_manager;
|
||||
uint32 transform_version;
|
||||
|
||||
Matrix4f ParentMatrix; ///<上级矩阵
|
||||
uint32 local_to_world_matrix_version;
|
||||
|
||||
Matrix4f LocalMatrix; ///<本地到上一级矩阵
|
||||
Matrix4f LocalToWorldMatrix; ///<本地到世界矩阵
|
||||
Matrix4f InverseLocalToWorldMatrix; ///<世界到本地矩阵
|
||||
Matrix4f InverseTransposeLocalToWorldMatrix; ///<世界到本地矩阵的转置矩阵
|
||||
// LocalToWorld = ParentMatrix * LocalMatrix * TransformMatrix
|
||||
|
||||
Matrix4f local_to_world_matrix; ///<本地到世界矩阵
|
||||
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
||||
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
|
||||
|
||||
virtual void SetWorldMatrix(const Matrix4f &);
|
||||
|
||||
@ -33,18 +40,20 @@ namespace hgl
|
||||
SceneOrient(const Matrix4f &);
|
||||
virtual ~SceneOrient()=default;
|
||||
|
||||
void SetLocalMatrix(const Matrix4f &); ///<设置本地矩阵
|
||||
|
||||
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 LocalToWorldMatrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return InverseLocalToWorldMatrix;}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return InverseTransposeLocalToWorldMatrix;}
|
||||
const Matrix4f & GetLocalToWorldMatrix ()const{return local_to_world_matrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return inverse_local_to_world_matrix;}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return inverse_transpose_local_to_world_matrix;}
|
||||
|
||||
public:
|
||||
|
||||
virtual bool RefreshMatrix (const Matrix4f &); ///<刷新到世界空间变换
|
||||
virtual bool RefreshMatrix (const Matrix4f &); ///<刷新到世界空间变换
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -5,60 +5,88 @@ namespace hgl
|
||||
{
|
||||
SceneOrient::SceneOrient()
|
||||
{
|
||||
LocalMatrix=Identity4f;
|
||||
parent_matrix=Identity4f;
|
||||
local_matrix=Identity4f;
|
||||
|
||||
SetWorldMatrix(Identity4f);
|
||||
|
||||
parent_matrix_dirty=false;
|
||||
local_matrix_dirty=false;
|
||||
transform_version=transform_manager.GetCurrentVersion();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void SceneOrient::SetLocalMatrix(const Matrix4f &mat)
|
||||
{
|
||||
if(IsNearlyEqual(LocalMatrix,mat))
|
||||
if(IsNearlyEqual(local_matrix,mat))
|
||||
return;
|
||||
|
||||
LocalMatrix=mat;
|
||||
local_matrix=mat;
|
||||
}
|
||||
|
||||
void SceneOrient::SetWorldMatrix(const Matrix4f &wm)
|
||||
{
|
||||
LocalToWorldMatrix =wm;
|
||||
InverseLocalToWorldMatrix =inverse(LocalToWorldMatrix);
|
||||
InverseTransposeLocalToWorldMatrix =transpose(InverseLocalToWorldMatrix);
|
||||
local_to_world_matrix =wm;
|
||||
inverse_local_to_world_matrix =inverse(local_to_world_matrix);
|
||||
inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新世界变换矩阵
|
||||
* @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);
|
||||
|
||||
ParentMatrix=parent_matrix;
|
||||
parent_matrix=pm;
|
||||
|
||||
if(IsIdentityMatrix(LocalMatrix))
|
||||
{
|
||||
SetWorldMatrix(parent_matrix);
|
||||
}
|
||||
else
|
||||
if(IsIdentityMatrix(parent_matrix))
|
||||
{
|
||||
SetWorldMatrix(LocalMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWorldMatrix(MatrixMult(parent_matrix,LocalMatrix));
|
||||
}
|
||||
Matrix4f tm;
|
||||
|
||||
transform_manager.GetMatrix(tm);
|
||||
|
||||
SetWorldMatrix(parent_matrix*local_matrix*tm);
|
||||
|
||||
//if(IsIdentityMatrix(LocalMatrix))
|
||||
//{
|
||||
// SetWorldMatrix(parent_matrix);
|
||||
// return(true);
|
||||
//}
|
||||
//
|
||||
|
||||
//if(IsIdentityMatrix(parent_matrix))
|
||||
//{
|
||||
// SetWorldMatrix(LocalMatrix);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// SetWorldMatrix(parent_matrix*LocalMatrix);
|
||||
//}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user