Moved WorldPosition to SceneMatrix

This commit is contained in:
hyzboy 2024-08-31 00:04:20 +08:00
parent 72ceffeda2
commit 8ebbd674b2
3 changed files with 38 additions and 24 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 0ac2a9431a14767c018f6f20a8ea0a3604b859ee
Subproject commit df5189ed09cab1197ddbb4e9f5a3d7959c961e3e

View File

@ -7,6 +7,20 @@ namespace hgl
{
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>
{
protected:
@ -16,6 +30,9 @@ namespace hgl
TransformManager transform_manager;
Matrix4f transform_matrix;
Vector3f OriginWorldPosition; //原始世界坐标
Vector3f FinalWorldPosition; //最终世界坐标
protected:
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
@ -23,9 +40,22 @@ namespace hgl
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_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
@ -51,7 +81,9 @@ namespace hgl
return inverse_transpose_local_to_world_matrix;
}
TransformManager &GetTransform() { return transform_manager; } ///<取得变换管理器
TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器
const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标
public:
@ -101,16 +133,6 @@ namespace hgl
/**
* <br>
* 3D空间中的位置<br>
* :<br>
* <ul>
* <li>LocalMatrix </li>
* <li>LocalToWorldMatrix 使</li>
*
* <li>transform_manager 0</li>
* </ul>
*
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix<br>
*/
class SceneOrient ///场景定位类
{
@ -118,8 +140,6 @@ namespace hgl
SceneMatrix scene_matrix;
Vector3f WorldPosition;
public:
SceneOrient()=default;
@ -130,7 +150,6 @@ namespace hgl
virtual void Clear()
{
scene_matrix.Clear();
WorldPosition=ZeroVector3f;
}
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
@ -138,9 +157,9 @@ namespace hgl
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();} ///<取得本地矩阵
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器

View File

@ -6,7 +6,6 @@ namespace hgl
SceneOrient::SceneOrient(const SceneOrient &so)
{
scene_matrix=so.scene_matrix;
WorldPosition=so.WorldPosition;
scene_matrix.UpdateNewestData();
}
@ -16,8 +15,6 @@ namespace hgl
scene_matrix.SetLocalMatrix(mat);
scene_matrix.UpdateNewestData();
WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f);
}
void SceneOrient::RefreshMatrix()
@ -27,8 +24,6 @@ namespace hgl
//是最新版本,证明没有更新,那不用刷新了
return;
}
WorldPosition=TransformPosition(GetLocalToWorldMatrix(),ZeroVector3f);
}
}//namespace graph
}//namespace hgl