ULRE/src/SceneGraph/SceneNode.cpp

121 lines
3.0 KiB
C++
Raw Normal View History

2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
2019-05-25 00:50:04 +08:00
#include<hgl/graph/RenderList.h>
2019-05-21 21:28:33 +08:00
//#include<hgl/graph/Frustum.h>
namespace hgl
{
namespace graph
{
/**
*
* @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
for(int i=0;i<count;i++)
{
(*sub)->RefreshBoundingBox();
if(i==0)
local=(*sub)->GetLocalBoundingBox();
else
local.Enclose((*sub)->GetLocalBoundingBox());
2019-05-21 21:28:33 +08:00
sub++;
}
2019-05-25 17:46:31 +08:00
2019-05-21 21:28:33 +08:00
}
/**
*
* @param rl
* @param func
* @param func_data
* @return
*/
bool SceneNode::ExpendToList(RenderList *rl,FilterSceneNodeFunc func,void *func_data)const
{
if(!rl)return(false);
if(func)
if(!func(this,func_data))
return(false);
if(CanRenderable())
rl->Add((RenderableNode *)this); //增加当前节点
2019-05-21 21:28:33 +08:00
int count=SubNode.GetCount();
SceneNode **sub=SubNode.GetData();
for(int i=0;i<count;i++)
{
(*sub)->ExpendToList(rl,func,func_data); //展开子节点
sub++;
}
return(true);
}
2019-05-25 00:50:04 +08:00
//bool SceneNode::ExpendToList(RenderList *rl,const Matrix4f &proj,const Matrix4f &mv,RenderListCompFunc comp_func)const
//{
// if(!rl)return(false);
2019-05-21 21:28:33 +08:00
2019-05-25 00:50:04 +08:00
//}
2019-05-21 21:28:33 +08:00
/**
*
* @param rl
* @param cam
* @param comp_func
*/
bool SceneNode::ExpendToList(RenderList *rl,Camera *cam,RenderListCompFunc comp_func)const
{
if(!rl||!cam)return(false);
// Frustum f;
// MakeCameraFrustum(&f,cam);
// if(!ExpendToList(rl,&f))
if(!ExpendToList(rl))
return(false);
if(comp_func)
{
}
return(true);
}
}//namespace graph
}//namespace hgl