From c72dde9b8477979b42810ce45feecb003d0a10b8 Mon Sep 17 00:00:00 2001 From: karl Date: Mon, 28 Dec 2020 14:08:43 +0100 Subject: [PATCH] Add empty implementation for ray intersection --- kdtree.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kdtree.h b/kdtree.h index 9fb4387..b163a1f 100644 --- a/kdtree.h +++ b/kdtree.h @@ -37,11 +37,21 @@ struct Point { Triangle *triangle; }; +struct Ray { + Ray(float origin[3], float direction[3]) : origin(origin), direction(direction) {} + + float *origin; + + float *direction; +}; + class KDTree { public: KDTree(std::vector points) { root = build(points, 0); } - ~KDTree() = default; + ~KDTree() = default; // TODO: Delete all allocated Nodes + + Point *intersect_ray(Ray ray) { return intersect_ray_recurse(ray, root); } std::string to_string() { std::string str = ""; @@ -105,6 +115,14 @@ class KDTree { build(right_of_median, depth + 1)); } + Point *intersect_ray_recurse(Ray ray, Node *node) { + // Intersect ray with the point's splitting plane + // If there is an intersection: Recurse to both children (but the nearer one first) + // Otherwise: Recurse only to the nearer one + + return node->point; // TODO + } + void to_string_recurse(std::string &str, Node *node, int depth) { if (node == nullptr) { return; }