#pragma once #include namespace hgl { namespace graph { /** * 场景节点矩阵类
* * 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。
* 构成说明:
* * * LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TransformMatrix
*/ class SceneMatrix :public VersionData { protected: Matrix4f parent_matrix; Matrix4f local_matrix; TransformManager transform_manager; Matrix4f transform_matrix; Vector3f OriginWorldPosition; //原始世界坐标 Vector3f FinalWorldPosition; //最终世界坐标 protected: Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵 Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵 void MakeNewestData(Matrix4f &local_to_world_matrix) override; ///<生成最新的数据(需要派生类重载) public: void Clear(); const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵 const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵 const Matrix4f &GetInverseLocalToWorldMatrix(){UpdateNewestData();return inverse_local_to_world_matrix;} ///<取得世界到本地矩阵 const Matrix4f &GetInverseTransposeLocalToWorldMatrix() ///<取得世界到本地矩阵的转置矩阵 { UpdateNewestData(); return inverse_transpose_local_to_world_matrix; } TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器 const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标 public: SceneMatrix():VersionData(Identity4f){Clear();} SceneMatrix(SceneMatrix &so); SceneMatrix(const Matrix4f &mat):VersionData(Identity4f) { SetLocalMatrix(mat); UpdateVersion(); } void SetLocalMatrix(const Matrix4f &mat) { //if (IsNearlyEqual(local_matrix,mat)) if(!hgl_cmp(local_matrix,mat)) return; local_matrix=mat; UpdateVersion(); } void SetParentMatrix(const Matrix4f &pm) { //if (IsNearlyEqual(parent_matrix,pm)) if(!hgl_cmp(parent_matrix,pm)) return; parent_matrix=pm; UpdateVersion(); } };//class SceneMatrix }//namespace graph }//namespace hgl