[WIP] preparing SceneManager
This commit is contained in:
parent
59fc27c864
commit
d7f7a7d095
@ -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
|
|
46
inc/hgl/graph/SceneManager.h
Normal file
46
inc/hgl/graph/SceneManager.h
Normal 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
|
@ -2,12 +2,16 @@
|
|||||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/ObjectList.h>
|
#include<hgl/type/ObjectList.h>
|
||||||
|
#include<hgl/type/IDName.h>
|
||||||
#include<hgl/graph/SceneOrient.h>
|
#include<hgl/graph/SceneOrient.h>
|
||||||
#include<hgl/graph/AABB.h>
|
#include<hgl/graph/AABB.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
|
using SceneNodeID =uint64;
|
||||||
|
using SceneNodeName =AnsiIDName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 场景节点数据类<br>
|
* 场景节点数据类<br>
|
||||||
* 从场景坐标变换(SceneOrient)类继承,
|
* 从场景坐标变换(SceneOrient)类继承,
|
||||||
@ -15,6 +19,9 @@ namespace hgl
|
|||||||
*/
|
*/
|
||||||
class SceneNode:public SceneOrient ///场景节点类
|
class SceneNode:public SceneOrient ///场景节点类
|
||||||
{
|
{
|
||||||
|
SceneNodeID NodeID; ///<节点ID
|
||||||
|
SceneNodeName NodeName; ///<节点名称
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AABB BoundingBox; ///<绑定盒
|
AABB BoundingBox; ///<绑定盒
|
||||||
@ -29,12 +36,21 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
|
||||||
|
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
SceneNode()=default;
|
SceneNode()=default;
|
||||||
SceneNode(SceneNode *);
|
SceneNode(SceneNode *);
|
||||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||||
|
|
||||||
|
friend SceneNode *CreateSceneNode(const SceneNodeName &);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
virtual ~SceneNode()=default;
|
virtual ~SceneNode()=default;
|
||||||
|
|
||||||
void Clear() override
|
void Clear() override
|
||||||
@ -140,6 +156,8 @@ namespace hgl
|
|||||||
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
||||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||||
};//class SceneNode
|
};//class SceneNode
|
||||||
|
|
||||||
|
SceneNode *CreateSceneNode(const SceneNodeName &);
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||||
|
@ -40,7 +40,7 @@ SET(LIGHT_FILES ${SG_INCLUDE_PATH}/Light.h)
|
|||||||
|
|
||||||
source_group("Light" FILES ${LIGHT_FILES})
|
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}/SceneNode.h
|
||||||
${SG_INCLUDE_PATH}/RenderNode.h
|
${SG_INCLUDE_PATH}/RenderNode.h
|
||||||
${SG_INCLUDE_PATH}/SceneMatrix.h
|
${SG_INCLUDE_PATH}/SceneMatrix.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user