Moved WorldPosition to SceneMatrix
This commit is contained in:
parent
72ceffeda2
commit
8ebbd674b2
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 0ac2a9431a14767c018f6f20a8ea0a3604b859ee
|
Subproject commit df5189ed09cab1197ddbb4e9f5a3d7959c961e3e
|
@ -7,6 +7,20 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 场景节点矩阵类<br>
|
||||||
|
*
|
||||||
|
* 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。<br>
|
||||||
|
* 构成说明:<br>
|
||||||
|
* <ul>
|
||||||
|
* <li>LocalMatrix 一般用于描述当前节点相对上一级的变换矩阵</li>
|
||||||
|
* <li>LocalToWorldMatrix 最终用于描述当前节点相对于世界的变换矩阵,在渲染时使用</li>
|
||||||
|
*
|
||||||
|
* <li>transform_manager 用于管理当前节点所有的变换情况,如果本节点不存在额外变换,数量为0。</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix<br>
|
||||||
|
*/
|
||||||
class SceneMatrix :public VersionData<Matrix4f>
|
class SceneMatrix :public VersionData<Matrix4f>
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -16,6 +30,9 @@ namespace hgl
|
|||||||
TransformManager transform_manager;
|
TransformManager transform_manager;
|
||||||
Matrix4f transform_matrix;
|
Matrix4f transform_matrix;
|
||||||
|
|
||||||
|
Vector3f OriginWorldPosition; //原始世界坐标
|
||||||
|
Vector3f FinalWorldPosition; //最终世界坐标
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
||||||
@ -23,9 +40,22 @@ namespace hgl
|
|||||||
|
|
||||||
void MakeNewestData(Matrix4f &local_to_world_matrix) override ///<生成最新的数据(需要派生类重载)
|
void MakeNewestData(Matrix4f &local_to_world_matrix) override ///<生成最新的数据(需要派生类重载)
|
||||||
{
|
{
|
||||||
transform_manager.GetMatrix(transform_matrix);
|
local_to_world_matrix=parent_matrix*local_matrix;
|
||||||
|
|
||||||
local_to_world_matrix=parent_matrix*local_matrix*transform_matrix;
|
OriginWorldPosition=TransformPosition(local_to_world_matrix,ZeroVector3f);
|
||||||
|
|
||||||
|
if(transform_manager.IsEmpty())
|
||||||
|
{
|
||||||
|
FinalWorldPosition=OriginWorldPosition;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transform_manager.GetMatrix(transform_matrix,OriginWorldPosition);
|
||||||
|
|
||||||
|
local_to_world_matrix*=transform_matrix;
|
||||||
|
|
||||||
|
FinalWorldPosition=TransformPosition(local_to_world_matrix,ZeroVector3f);
|
||||||
|
}
|
||||||
|
|
||||||
inverse_local_to_world_matrix =inverse(local_to_world_matrix);
|
inverse_local_to_world_matrix =inverse(local_to_world_matrix);
|
||||||
inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
|
inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
|
||||||
@ -51,7 +81,9 @@ namespace hgl
|
|||||||
return inverse_transpose_local_to_world_matrix;
|
return inverse_transpose_local_to_world_matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformManager &GetTransform() { return transform_manager; } ///<取得变换管理器
|
TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器
|
||||||
|
|
||||||
|
const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -101,16 +133,6 @@ namespace hgl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 方向定位数据基类<br>
|
* 方向定位数据基类<br>
|
||||||
* 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。<br>
|
|
||||||
* 构成说明:<br>
|
|
||||||
* <ul>
|
|
||||||
* <li>LocalMatrix 一般用于描述当前节点相对上一级的变换矩阵</li>
|
|
||||||
* <li>LocalToWorldMatrix 最终用于描述当前节点相对于世界的变换矩阵,在渲染时使用</li>
|
|
||||||
*
|
|
||||||
* <li>transform_manager 用于管理当前节点所有的变换情况,如果本节点不存在额外变换,数量为0。</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix<br>
|
|
||||||
*/
|
*/
|
||||||
class SceneOrient ///场景定位类
|
class SceneOrient ///场景定位类
|
||||||
{
|
{
|
||||||
@ -118,8 +140,6 @@ namespace hgl
|
|||||||
|
|
||||||
SceneMatrix scene_matrix;
|
SceneMatrix scene_matrix;
|
||||||
|
|
||||||
Vector3f WorldPosition;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SceneOrient()=default;
|
SceneOrient()=default;
|
||||||
@ -130,7 +150,6 @@ namespace hgl
|
|||||||
virtual void Clear()
|
virtual void Clear()
|
||||||
{
|
{
|
||||||
scene_matrix.Clear();
|
scene_matrix.Clear();
|
||||||
WorldPosition=ZeroVector3f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
|
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
|
||||||
@ -138,9 +157,9 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const uint32 GetLocalToWorldMatrixVersion()const { return scene_matrix.GetNewestVersion(); } ///<取得版本号
|
const uint32 GetLocalToWorldMatrixVersion()const {return scene_matrix.GetNewestVersion();} ///<取得版本号
|
||||||
|
|
||||||
const Vector3f & GetWorldPosition() const { return WorldPosition; } ///<取得世界坐标
|
const Vector3f & GetWorldPosition() const {return scene_matrix.GetWorldPosition();} ///<取得世界坐标
|
||||||
const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵
|
const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵
|
||||||
|
|
||||||
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器
|
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器
|
||||||
|
@ -6,7 +6,6 @@ namespace hgl
|
|||||||
SceneOrient::SceneOrient(const SceneOrient &so)
|
SceneOrient::SceneOrient(const SceneOrient &so)
|
||||||
{
|
{
|
||||||
scene_matrix=so.scene_matrix;
|
scene_matrix=so.scene_matrix;
|
||||||
WorldPosition=so.WorldPosition;
|
|
||||||
|
|
||||||
scene_matrix.UpdateNewestData();
|
scene_matrix.UpdateNewestData();
|
||||||
}
|
}
|
||||||
@ -16,8 +15,6 @@ namespace hgl
|
|||||||
scene_matrix.SetLocalMatrix(mat);
|
scene_matrix.SetLocalMatrix(mat);
|
||||||
|
|
||||||
scene_matrix.UpdateNewestData();
|
scene_matrix.UpdateNewestData();
|
||||||
|
|
||||||
WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneOrient::RefreshMatrix()
|
void SceneOrient::RefreshMatrix()
|
||||||
@ -27,8 +24,6 @@ namespace hgl
|
|||||||
//是最新版本,证明没有更新,那不用刷新了
|
//是最新版本,证明没有更新,那不用刷新了
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f);
|
|
||||||
}
|
}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user