store ray hittable drawables in the scene

This commit is contained in:
ohyzha
2024-11-04 18:23:43 +02:00
parent 4c9f0ab2ee
commit 4c67b94bc6

View File

@@ -20,6 +20,7 @@ namespace OpenVulkano
public:
Node* root;
std::vector<Drawable*> shapeList;
std::vector<Drawable*> rayHittableDrawables;
Camera* camera;
public:
@@ -55,11 +56,21 @@ namespace OpenVulkano
return root;
}
void RegisterHittableDrawable(Drawable* drawable)
{
drawable->SetIsHittable(true);
RegisterDrawable(drawable);
}
void RegisterDrawable(Drawable* drawable)
{
if (drawable->GetScene() != this) drawable->SetScene(this);
if (Utils::Contains(shapeList, drawable)) return; // Prevent duplicate entries
shapeList.push_back(drawable);
if (drawable->IsHittable())
{
rayHittableDrawables.push_back(drawable);
}
if (shapeList.size() > 1 && shapeList[shapeList.size() - 2]->GetDrawPhase() < drawable->GetDrawPhase())
{
std::sort(shapeList.begin(), shapeList.end(),
@@ -70,12 +81,14 @@ namespace OpenVulkano
void RemoveDrawable(Drawable* drawable)
{
Utils::Remove(shapeList, drawable);
Utils::Remove(rayHittableDrawables, drawable);
drawable->SetScene(nullptr);
}
virtual void SetCamera(Camera* camera)
{
this->camera = camera;
camera->scene = this;
}
Camera* GetCamera() const