[WIP] refresh scene orient
This commit is contained in:
parent
8880df8862
commit
f4e16276ff
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 3213287b186fd9de237ff13c170e3bacd89dfa0e
|
||||
Subproject commit 1fd9db054591942c3f4746052def3b621a1dbaff
|
@ -15,44 +15,36 @@ namespace hgl
|
||||
{
|
||||
protected:
|
||||
|
||||
Vector3f Position; ///<坐标
|
||||
Vector3f Direction; ///<方向
|
||||
TransformManager transform_manager;
|
||||
|
||||
Transform LocalTransform; ///<当前变换(指相对上一级的变换)
|
||||
Transform WorldTransform; ///<当前到世界变换
|
||||
Matrix4f ParentMatrix; ///<上级矩阵
|
||||
|
||||
protected:
|
||||
Matrix4f LocalMatrix; ///<本地到上一级矩阵
|
||||
Matrix4f LocalToWorldMatrix; ///<本地到世界矩阵
|
||||
Matrix4f InverseLocalToWorldMatrix; ///<世界到本地矩阵
|
||||
Matrix4f InverseTransposeLocalToWorldMatrix; ///<世界到本地矩阵的转置矩阵
|
||||
|
||||
void SetWorldTransform (const Transform &); ///<设定当前节点到世界矩阵
|
||||
virtual void SetWorldMatrix(const Matrix4f &);
|
||||
|
||||
public:
|
||||
|
||||
SceneOrient();
|
||||
SceneOrient(const SceneOrient &);
|
||||
SceneOrient(const Transform &);
|
||||
SceneOrient(const Matrix4f &);
|
||||
virtual ~SceneOrient()=default;
|
||||
|
||||
void SetPosition (const Vector3f &pos){Position=pos;}
|
||||
void SetDirection (const Vector3f &dir){Direction=dir;}
|
||||
|
||||
const Vector3f & GetLocalPosition ()const {return Position;}
|
||||
const Vector3f & GetLocalDirection ()const {return Direction;}
|
||||
const Vector3f GetWorldPosition () {return WorldTransform.TransformPosition(Position);}
|
||||
const Vector3f GetWorldDirection () {return WorldTransform.TransformDirection(Direction);}
|
||||
|
||||
public:
|
||||
|
||||
void SetLocalTransform (const Transform &); ///<设定当前节点矩阵
|
||||
TransformManager * GetTransform (){return &transform_manager;} ///<取得变换管理器
|
||||
|
||||
const Transform & GetLocalTransform ()const {return LocalTransform;} ///<取得当前节点矩阵
|
||||
const Transform & GetWorldTransform ()const {return WorldTransform;} ///<取得当前节点到世界矩阵
|
||||
|
||||
Transform & GetLocalTransform () {LocalTransform.UpdateMatrix();return LocalTransform;} ///<取得当前节点矩阵
|
||||
Transform & GetWorldTransform () {WorldTransform.UpdateMatrix();return WorldTransform;} ///<取得当前节点到世界矩阵
|
||||
const Matrix4f & GetLocalMatrix ()const{return LocalMatrix;}
|
||||
const Matrix4f & GetLocalToWorldMatrix ()const{return LocalToWorldMatrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return InverseLocalToWorldMatrix;}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return InverseTransposeLocalToWorldMatrix;}
|
||||
|
||||
public:
|
||||
|
||||
virtual bool RefreshTransform (const Transform &); ///<刷新到世界空间变换
|
||||
virtual bool RefreshMatrix (const Matrix4f &); ///<刷新到世界空间变换
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -5,8 +5,9 @@ namespace hgl
|
||||
{
|
||||
SceneOrient::SceneOrient()
|
||||
{
|
||||
Position=Vector3f(0.0f);
|
||||
Direction=Vector3f(0.0f);
|
||||
LocalMatrix=Identity4f;
|
||||
|
||||
SetWorldMatrix(Identity4f);
|
||||
}
|
||||
|
||||
SceneOrient::SceneOrient(const SceneOrient &so)
|
||||
@ -14,45 +15,49 @@ namespace hgl
|
||||
hgl_cpy(*this,so);
|
||||
}
|
||||
|
||||
SceneOrient::SceneOrient(const Transform &t)
|
||||
SceneOrient::SceneOrient(const Matrix4f &mat)
|
||||
{
|
||||
SetLocalTransform(t);
|
||||
SetLocalMatrix(mat);
|
||||
}
|
||||
|
||||
void SceneOrient::SetLocalTransform(const Transform &t)
|
||||
void SceneOrient::SetLocalMatrix(const Matrix4f &mat)
|
||||
{
|
||||
if(LocalTransform==t)
|
||||
if(IsNearlyEqual(LocalMatrix,mat))
|
||||
return;
|
||||
|
||||
LocalTransform=t;
|
||||
LocalMatrix=mat;
|
||||
}
|
||||
|
||||
void SceneOrient::SetWorldTransform(const Transform &t)
|
||||
void SceneOrient::SetWorldMatrix(const Matrix4f &wm)
|
||||
{
|
||||
if(WorldTransform==t)
|
||||
return;
|
||||
|
||||
WorldTransform=t;
|
||||
LocalToWorldMatrix =wm;
|
||||
InverseLocalToWorldMatrix =inverse(LocalToWorldMatrix);
|
||||
InverseTransposeLocalToWorldMatrix =transpose(InverseLocalToWorldMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新世界变换
|
||||
* @param m 上一级local to world变换
|
||||
* 刷新世界变换矩阵
|
||||
* @param parent_matrix 上一级LocalToWorld变换矩阵
|
||||
*/
|
||||
bool SceneOrient::RefreshTransform(const Transform &t)
|
||||
bool SceneOrient::RefreshMatrix(const Matrix4f &parent_matrix)
|
||||
{
|
||||
if(!t.IsLastVersion()) //都不是最新版本
|
||||
return(false);
|
||||
if(hgl_cmp(ParentMatrix,parent_matrix)==0) //如果上一级到这一级没变,自然是可以用memcmp比较的
|
||||
return(true);
|
||||
|
||||
//理论上讲,Transform在正常转const的情况下,就已经做了UpdateMatrix()的操作,这个需要测试一下
|
||||
ParentMatrix=parent_matrix;
|
||||
|
||||
if(LocalTransform.IsIdentity())
|
||||
if(IsIdentityMatrix(LocalMatrix))
|
||||
{
|
||||
SetWorldTransform(t);
|
||||
SetWorldMatrix(parent_matrix);
|
||||
}
|
||||
else
|
||||
if(IsIdentityMatrix(parent_matrix))
|
||||
{
|
||||
SetWorldMatrix(LocalMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWorldTransform(t.TransformTransform(LocalTransform));
|
||||
SetWorldMatrix(MatrixMult(parent_matrix,LocalMatrix));
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user