ULRE/src/SceneGraph/scene/SceneNode.cpp

93 lines
2.1 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
{
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
}
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
/**
*
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
}
}//namespace graph
}//namespace hgl