ULRE/src/SceneGraph/SceneNode.cpp

131 lines
3.2 KiB
C++
Raw Normal View History

2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKRenderable.h>
2019-05-21 21:28:33 +08:00
namespace hgl
{
namespace graph
{
void SceneNode::SetRenderable(Renderable *ri)
{
render_obj=ri;
if(render_obj)
{
SetBoundingBox(render_obj->GetBoundingBox());
}
else
{
2023-09-28 15:02:57 +08:00
BoundingBox.SetZero();
//WorldBoundingBox=
LocalBoundingBox=BoundingBox;
}
}
2019-05-21 21:28:33 +08:00
/**
*
* @param root_matrix
2019-05-21 21:28:33 +08:00
*/
void SceneNode::RefreshMatrix(const Matrix4f *root_matrix)
{
if(root_matrix)
RefreshLocalToWorldMatrix(root_matrix);
else
SetLocalToWorldMatrix(LocalMatrix);
2019-05-21 21:28:33 +08:00
const int count=SubNode.GetCount();
SceneNode **sub=SubNode.GetData();
for(int i=0;i<count;i++)
{
(*sub)->RefreshMatrix(&LocalToWorldMatrix);
sub++;
}
}
/**
*
*/
void SceneNode::RefreshBoundingBox()
{
int count=SubNode.GetCount();
SceneNode **sub=SubNode.GetData();
AABB local,world;
2019-05-21 21:28:33 +08:00
2019-05-26 00:20:40 +08:00
(*sub)->RefreshBoundingBox();
local=(*sub)->GetLocalBoundingBox();
++sub;
for(int i=1;i<count;i++)
2019-05-21 21:28:33 +08:00
{
(*sub)->RefreshBoundingBox();
2019-05-26 00:20:40 +08:00
local.Enclose((*sub)->GetLocalBoundingBox());
2019-05-21 21:28:33 +08:00
2019-05-26 00:20:40 +08:00
++sub;
2019-05-21 21:28:33 +08:00
}
2019-05-26 00:20:40 +08:00
LocalBoundingBox=local;
2019-05-21 21:28:33 +08:00
}
2021-04-30 18:56:20 +08:00
///**
//* 从当前节点展开输出到一个渲染列表
//* @param rl 渲染列表
//* @param func 过滤函数
//* @param func_data 过滤函数用辅助数据
//* @return 成功与否
//*/
//bool SceneNode::ExpendToList(RenderList *rl,FilterSceneNodeFunc func,void *func_data)
//{
// if(!rl)return(false);
// if(func)
// if(!func(this,func_data))
// return(false);
// {
// int count=renderable_instances.GetCount();
// if(count>0)
// rl->Add(this);
// }
// {
// int count=SubNode.GetCount();
// SceneNode **sub=SubNode.GetData();
// for(int i=0;i<count;i++)
// {
// (*sub)->ExpendToList(rl,func,func_data); //展开子节点
// ++sub;
// }
// }
// return(true);
//}
///**
//* 从当前节点展开输出到一个渲染列表
//* @param rl 渲染列表
//* @param cam 摄像机
//* @param comp_func 渲染列表远近比较函数
//*/
//bool SceneNode::ExpendToList(RenderList *rl,Camera *cam,RenderListCompFunc comp_func)
//{
// if(!rl||!cam)return(false);
// if(!ExpendToList(rl))
// return(false);
// if(comp_func)
// {
// }
// return(true);
//}
2019-05-21 21:28:33 +08:00
}//namespace graph
}//namespace hgl