ULRE/src/SceneGraph/scene/SceneNode.cpp

130 lines
2.8 KiB
C++
Raw Normal View History

2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
#include<hgl/component/SceneComponent.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 21:05:36 +08:00
//SceneNode *Duplication(SceneNode *src_node)
//{
// if(!src_node)
// return nullptr;
// SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
// node->SetRenderable(src_node->GetRenderable());
// for(SceneNode *sn:src_node->GetChildNode())
// {
// node->Add(Duplication(sn));
// }
// return node;
//}
//void SceneNode::SetRenderable(Mesh *ri)
//{
// render_obj=ri;
// if(render_obj)
// {
// SetBoundingBox(render_obj->GetBoundingBox());
// }
// else
// {
// bounding_box.SetZero();
2025-06-14 21:05:36 +08:00
// //WorldBoundingBox=
// local_bounding_box=bounding_box;
2025-06-14 21:05:36 +08:00
// }
//}
2025-06-14 02:32:15 +08:00
/**
*
*/
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
for(SceneNode *sub:child_nodes)
{
sub->SetParentMatrix(l2w);
sub->RefreshMatrix();
}
2019-05-21 21:28:33 +08:00
for(Component *com:component_set)
2025-06-14 02:32:15 +08:00
{
SceneComponent *sc=reinterpret_cast<SceneComponent *>(com);
if(!sc)
continue;
2019-05-21 21:28:33 +08:00
sc->SetParentMatrix(l2w);
sc->RefreshMatrix();
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=child_nodes.GetCount();
SceneNode **sub=child_nodes.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
local_bounding_box=local;
2025-06-14 02:32:15 +08:00
}
2019-05-21 21:28:33 +08:00
int SceneNode::GetComponents(ComponentList &comp_list,const ComponentManager *mgr)
2025-06-14 02:32:15 +08:00
{
if(!mgr)return(-1);
if(ComponentIsEmpty())return(0);
2025-06-14 02:32:15 +08:00
int result=0;
for(Component *c:component_set)
{
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);
for(Component *c:component_set)
2025-06-14 02:32:15 +08:00
{
if(c->GetManager()==mgr)
return(true);
}
2025-06-14 02:32:15 +08:00
return(false);
}
}//namespace hgl::graph