ULRE/src/SceneGraph/scene/SceneNode.cpp

126 lines
2.9 KiB
C++
Raw Normal View History

2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/Mesh.h>
2019-05-21 21:28:33 +08:00
namespace hgl
{
namespace graph
{
2024-10-06 02:30:59 +08:00
SceneNode *Duplication(SceneNode *src_node)
2024-07-31 00:11:04 +08:00
{
2024-10-06 02:30:59 +08:00
if(!src_node)
return nullptr;
2024-07-31 00:11:04 +08:00
2024-10-06 02:30:59 +08:00
SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
2024-07-31 00:11:04 +08:00
2024-10-06 02:30:59 +08:00
node->SetRenderable(src_node->GetRenderable());
2024-07-31 00:11:04 +08:00
for(SceneNode *sn:src_node->GetChildNode())
2024-07-31 00:11:04 +08:00
{
2024-10-06 02:30:59 +08:00
node->Add(Duplication(sn));
2024-07-31 00:11:04 +08:00
}
2024-10-06 02:30:59 +08:00
return node;
2024-07-31 00:11:04 +08:00
}
2025-05-18 02:03:16 +08:00
void SceneNode::SetRenderable(Mesh *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
/**
*
2019-05-21 21:28:33 +08:00
*/
void SceneNode::RefreshMatrix()
2019-05-21 21:28:33 +08:00
{
SceneOrient::RefreshMatrix();
// if (scene_matrix.IsNewestVersion()) //自己不变,不代表下面不变
//return;
const Matrix4f &l2w=scene_matrix.GetLocalToWorldMatrix();
2019-05-21 21:28:33 +08:00
const int count=ChildNode.GetCount();
2019-05-21 21:28:33 +08:00
SceneNode **sub=ChildNode.GetData();
2019-05-21 21:28:33 +08:00
for(int i=0;i<count;i++)
{
(*sub)->SetParentMatrix(l2w);
(*sub)->RefreshMatrix();
2019-05-21 21:28:33 +08:00
sub++;
}
}
/**
*
*/
void SceneNode::RefreshBoundingBox()
{
int count=ChildNode.GetCount();
SceneNode **sub=ChildNode.GetData();
2019-05-21 21:28:33 +08:00
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
}
2025-04-23 00:27:43 +08:00
int SceneNode::GetComponents(ArrayList<Component *> &comp_list,const ComponentManager *mgr)
{
if(!mgr)return(-1);
if(ComponentIsEmpty())return(0);
int result=0;
for(Component *c:ComponentList)
{
if(c->GetManager()==mgr)
{
comp_list.Add(c);
++result;
}
}
return result;
}
bool SceneNode::HasComponent(const ComponentManager *mgr)
{
if(!mgr)return(false);
if(ComponentIsEmpty())return(false);
for(Component *c:ComponentList)
{
if(c->GetManager()==mgr)
return(true);
}
return(false);
}
2019-05-21 21:28:33 +08:00
}//namespace graph
}//namespace hgl