From 4c67b94bc6bd7bd86204f3dcd814f1a585e49504 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Mon, 4 Nov 2024 18:23:43 +0200 Subject: [PATCH] store ray hittable drawables in the scene --- openVulkanoCpp/Scene/Scene.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openVulkanoCpp/Scene/Scene.hpp b/openVulkanoCpp/Scene/Scene.hpp index 84aadb1..c4babf5 100644 --- a/openVulkanoCpp/Scene/Scene.hpp +++ b/openVulkanoCpp/Scene/Scene.hpp @@ -20,6 +20,7 @@ namespace OpenVulkano public: Node* root; std::vector shapeList; + std::vector 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