ULRE/src/SceneGraph/scene/SceneNode.cpp

124 lines
2.5 KiB
C++
Raw Normal View History

2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/Mesh.h>
2025-06-14 02:32:15 +08:00
namespace hgl::graph
2019-05-21 21:28:33 +08:00
{
2025-06-14 02:32:15 +08:00
SceneNode *Duplication(SceneNode *src_node)
2019-05-21 21:28:33 +08:00
{
2025-06-14 02:32:15 +08:00
if(!src_node)
return nullptr;
2024-07-31 00:11:04 +08:00
2025-06-14 02:32:15 +08:00
SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
2024-07-31 00:11:04 +08:00
2025-06-14 02:32:15 +08:00
node->SetRenderable(src_node->GetRenderable());
2024-10-06 02:30:59 +08:00
2025-06-14 02:32:15 +08:00
for(SceneNode *sn:src_node->GetChildNode())
{
node->Add(Duplication(sn));
2024-07-31 00:11:04 +08:00
}
2025-06-14 02:32:15 +08:00
return node;
}
2025-06-14 02:32:15 +08:00
void SceneNode::SetRenderable(Mesh *ri)
{
render_obj=ri;
2025-06-14 02:32:15 +08:00
if(render_obj)
{
SetBoundingBox(render_obj->GetBoundingBox());
}
2025-06-14 02:32:15 +08:00
else
2019-05-21 21:28:33 +08:00
{
2025-06-14 02:32:15 +08:00
BoundingBox.SetZero();
//WorldBoundingBox=
LocalBoundingBox=BoundingBox;
}
}
/**
*
*/
void SceneNode::RefreshMatrix()
{
SceneOrient::RefreshMatrix();
// if (scene_matrix.IsNewestVersion()) //自己不变,不代表下面不变
2025-06-14 02:32:15 +08:00
//return;
2025-06-14 02:32:15 +08:00
const Matrix4f &l2w=scene_matrix.GetLocalToWorldMatrix();
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
const int count=ChildNode.GetCount();
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
SceneNode **sub=ChildNode.GetData();
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
for(int i=0;i<count;i++)
{
(*sub)->SetParentMatrix(l2w);
(*sub)->RefreshMatrix();
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
sub++;
2019-05-21 21:28:33 +08:00
}
2025-06-14 02:32:15 +08:00
}
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
/**
*
*/
void SceneNode::RefreshBoundingBox()
{
int count=ChildNode.GetCount();
SceneNode **sub=ChildNode.GetData();
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
AABB local,world;
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
(*sub)->RefreshBoundingBox();
local=(*sub)->GetLocalBoundingBox();
++sub;
for(int i=1;i<count;i++)
{
2019-05-26 00:20:40 +08:00
(*sub)->RefreshBoundingBox();
2025-06-14 02:32:15 +08:00
local.Enclose((*sub)->GetLocalBoundingBox());
2019-05-26 00:20:40 +08:00
++sub;
2025-06-14 02:32:15 +08:00
}
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
LocalBoundingBox=local;
}
2019-05-21 21:28:33 +08:00
2025-06-14 02:32:15 +08:00
int SceneNode::GetComponents(ArrayList<Component *> &comp_list,const ComponentManager *mgr)
{
if(!mgr)return(-1);
if(ComponentIsEmpty())return(0);
2025-06-14 02:32:15 +08:00
int result=0;
2025-06-14 02:32:15 +08:00
for(Component *c:ComponentSet)
{
2025-06-14 02:32:15 +08:00
if(c->GetManager()==mgr)
{
2025-06-14 02:32:15 +08:00
comp_list.Add(c);
++result;
}
}
2025-06-14 02:32:15 +08:00
return result;
}
2025-06-14 02:32:15 +08:00
bool SceneNode::HasComponent(const ComponentManager *mgr)
{
if(!mgr)return(false);
if(ComponentIsEmpty())return(false);
2025-06-14 02:32:15 +08:00
for(Component *c:ComponentSet)
{
if(c->GetManager()==mgr)
return(true);
}
2025-06-14 02:32:15 +08:00
return(false);
}
}//namespace hgl::graph