generated from karl/cpp-template
Add empty implementation for ray intersection
This commit is contained in:
parent
ab2adf4173
commit
c72dde9b84
20
kdtree.h
20
kdtree.h
@ -37,11 +37,21 @@ struct Point {
|
|||||||
Triangle *triangle;
|
Triangle *triangle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Ray {
|
||||||
|
Ray(float origin[3], float direction[3]) : origin(origin), direction(direction) {}
|
||||||
|
|
||||||
|
float *origin;
|
||||||
|
|
||||||
|
float *direction;
|
||||||
|
};
|
||||||
|
|
||||||
class KDTree {
|
class KDTree {
|
||||||
public:
|
public:
|
||||||
KDTree(std::vector<Point *> points) { root = build(points, 0); }
|
KDTree(std::vector<Point *> 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 to_string() {
|
||||||
std::string str = "";
|
std::string str = "";
|
||||||
@ -105,6 +115,14 @@ class KDTree {
|
|||||||
build(right_of_median, depth + 1));
|
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) {
|
void to_string_recurse(std::string &str, Node *node, int depth) {
|
||||||
if (node == nullptr) { return; }
|
if (node == nullptr) { return; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user