[WIP] preparing SceneManager

This commit is contained in:
hyzboy 2024-09-06 01:04:28 +08:00
parent 59fc27c864
commit d7f7a7d095
4 changed files with 65 additions and 39 deletions

View File

@ -1,38 +0,0 @@
#ifndef HGL_GRAPH_SCENE_INFO_INCLUDE
#define HGL_GRAPH_SCENE_INFO_INCLUDE
#include<hgl/math/Matrix.h>
#include<hgl/CompOperator.h>
namespace hgl
{
namespace graph
{
/**
* MVP矩阵
*/
struct MVPMatrix
{
Matrix4f model; ///< model: Local to World
//Matrix4f normal; ///<transpose(inverse(mat3(model)));
Matrix3x4f normal; ///<这里用3x4在Shader中是3x3(但实际它是3x4保存)
Matrix4f mv; ///< view * model
Matrix4f mvp; ///< projection * view * model
public:
void Set(const Matrix4f &local_to_world,const Matrix4f &view_projection,const Matrix4f &view)
{
model =local_to_world;
normal =transpose(inverse(model));
mv =view*model;
mvp =view_projection*model;
}
CompOperatorMemcmp(const MVPMatrix &);
};//struct MVPMatrix
constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_SCENE_INFO_INCLUDE

View File

@ -0,0 +1,46 @@
#pragma once
#include<hgl/graph/SceneNode.h>
namespace hgl
{
namespace graph
{
template<typename T> class ObjectAllocator
{
template<typename OBJECT,typename ID,typename NAME> class IDNameObjectMap
{
ObjectList<OBJECT> obj_list;
Map<ID,OBJECT *> obj_map_by_id;
Map<NAME,OBJECT *> obj_map_by_name;
public:
virtual ~IDNameObjectMap()=default;
};//class NodeManager;
/**
* <Br>
*
*/
class SceneManager
{
SceneNode *root_node;
public:
SceneNode *GetSceneRoot() {return root_node;}
const SceneNode *GetSceneRoot()const{return root_node;}
const uint GetNodeCount()const { return node_list.GetCount(); }
public:
};//class SceneManager
}//namespace graph
}//namespace hgl

View File

@ -2,12 +2,16 @@
#define HGL_GRAPH_SCENE_NODE_INCLUDE
#include<hgl/type/ObjectList.h>
#include<hgl/type/IDName.h>
#include<hgl/graph/SceneOrient.h>
#include<hgl/graph/AABB.h>
namespace hgl
{
namespace graph
{
using SceneNodeID =uint64;
using SceneNodeName =AnsiIDName;
/**
* <br>
* (SceneOrient)
@ -15,6 +19,9 @@ namespace hgl
*/
class SceneNode:public SceneOrient ///场景节点类
{
SceneNodeID NodeID; ///<节点ID
SceneNodeName NodeName; ///<节点名称
protected:
AABB BoundingBox; ///<绑定盒
@ -29,12 +36,21 @@ namespace hgl
public:
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
private:
SceneNode()=default;
SceneNode(SceneNode *);
SceneNode( Renderable *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
friend SceneNode *CreateSceneNode(const SceneNodeName &);
public:
virtual ~SceneNode()=default;
void Clear() override
@ -140,6 +156,8 @@ namespace hgl
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
};//class SceneNode
SceneNode *CreateSceneNode(const SceneNodeName &);
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE

View File

@ -40,7 +40,7 @@ SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h)
source_group("Light" FILES ${LIGHT_FILES})
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneInfo.h
SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneManager.h
${SG_INCLUDE_PATH}/SceneNode.h
${SG_INCLUDE_PATH}/RenderNode.h
${SG_INCLUDE_PATH}/SceneMatrix.h