[WIP] refresh scene orient
This commit is contained in:
2
CMCore
2
CMCore
Submodule CMCore updated: 3213287b18...1fd9db0545
@@ -15,44 +15,36 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Vector3f Position; ///<坐标
|
TransformManager transform_manager;
|
||||||
Vector3f Direction; ///<方向
|
|
||||||
|
|
||||||
Transform LocalTransform; ///<当前变换(指相对上一级的变换)
|
Matrix4f ParentMatrix; ///<上级矩阵
|
||||||
Transform WorldTransform; ///<当前到世界变换
|
|
||||||
|
|
||||||
protected:
|
Matrix4f LocalMatrix; ///<本地到上一级矩阵
|
||||||
|
Matrix4f LocalToWorldMatrix; ///<本地到世界矩阵
|
||||||
|
Matrix4f InverseLocalToWorldMatrix; ///<世界到本地矩阵
|
||||||
|
Matrix4f InverseTransposeLocalToWorldMatrix; ///<世界到本地矩阵的转置矩阵
|
||||||
|
|
||||||
void SetWorldTransform (const Transform &); ///<设定当前节点到世界矩阵
|
virtual void SetWorldMatrix(const Matrix4f &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SceneOrient();
|
SceneOrient();
|
||||||
SceneOrient(const SceneOrient &);
|
SceneOrient(const SceneOrient &);
|
||||||
SceneOrient(const Transform &);
|
SceneOrient(const Matrix4f &);
|
||||||
virtual ~SceneOrient()=default;
|
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:
|
public:
|
||||||
|
|
||||||
void SetLocalTransform (const Transform &); ///<设定当前节点矩阵
|
TransformManager * GetTransform (){return &transform_manager;} ///<取得变换管理器
|
||||||
|
|
||||||
const Transform & GetLocalTransform ()const {return LocalTransform;} ///<取得当前节点矩阵
|
const Matrix4f & GetLocalMatrix ()const{return LocalMatrix;}
|
||||||
const Transform & GetWorldTransform ()const {return WorldTransform;} ///<取得当前节点到世界矩阵
|
const Matrix4f & GetLocalToWorldMatrix ()const{return LocalToWorldMatrix;}
|
||||||
|
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return InverseLocalToWorldMatrix;}
|
||||||
Transform & GetLocalTransform () {LocalTransform.UpdateMatrix();return LocalTransform;} ///<取得当前节点矩阵
|
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return InverseTransposeLocalToWorldMatrix;}
|
||||||
Transform & GetWorldTransform () {WorldTransform.UpdateMatrix();return WorldTransform;} ///<取得当前节点到世界矩阵
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual bool RefreshTransform (const Transform &); ///<刷新到世界空间变换
|
virtual bool RefreshMatrix (const Matrix4f &); ///<刷新到世界空间变换
|
||||||
};//class SceneOrient
|
};//class SceneOrient
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@@ -5,8 +5,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
SceneOrient::SceneOrient()
|
SceneOrient::SceneOrient()
|
||||||
{
|
{
|
||||||
Position=Vector3f(0.0f);
|
LocalMatrix=Identity4f;
|
||||||
Direction=Vector3f(0.0f);
|
|
||||||
|
SetWorldMatrix(Identity4f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneOrient::SceneOrient(const SceneOrient &so)
|
SceneOrient::SceneOrient(const SceneOrient &so)
|
||||||
@@ -14,45 +15,49 @@ namespace hgl
|
|||||||
hgl_cpy(*this,so);
|
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;
|
return;
|
||||||
|
|
||||||
LocalTransform=t;
|
LocalMatrix=mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneOrient::SetWorldTransform(const Transform &t)
|
void SceneOrient::SetWorldMatrix(const Matrix4f &wm)
|
||||||
{
|
{
|
||||||
if(WorldTransform==t)
|
LocalToWorldMatrix =wm;
|
||||||
return;
|
InverseLocalToWorldMatrix =inverse(LocalToWorldMatrix);
|
||||||
|
InverseTransposeLocalToWorldMatrix =transpose(InverseLocalToWorldMatrix);
|
||||||
WorldTransform=t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新世界变换
|
* 刷新世界变换矩阵
|
||||||
* @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()) //都不是最新版本
|
if(hgl_cmp(ParentMatrix,parent_matrix)==0) //如果上一级到这一级没变,自然是可以用memcmp比较的
|
||||||
return(false);
|
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
|
else
|
||||||
{
|
{
|
||||||
SetWorldTransform(t.TransformTransform(LocalTransform));
|
SetWorldMatrix(MatrixMult(parent_matrix,LocalMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
Reference in New Issue
Block a user