2020-12-28 13:55:57 +01:00
|
|
|
#include "kdtree.h"
|
2020-12-09 13:09:35 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main() {
|
2020-12-28 17:38:49 +01:00
|
|
|
// Testing triangles
|
|
|
|
Triangle t1 = Triangle(Vector(0.0, 0.0, 0.0), Vector(2.0, 0.0, 0.0), Vector(0.0, 2.0, 0.0));
|
|
|
|
Triangle t2 = Triangle(Vector(0.5, 0.0, 0.0), Vector(1.0, 1.0, 0.0), Vector(1.0, 1.0, 1.0));
|
2020-12-09 13:09:35 +01:00
|
|
|
|
2020-12-28 17:38:49 +01:00
|
|
|
// Create list of all points from triangles
|
|
|
|
std::vector<Point *> points = t1.create_point_objects();
|
|
|
|
std::vector<Point *> other_points = t2.create_point_objects();
|
|
|
|
points.insert(points.end(), other_points.begin(), other_points.end());
|
2020-12-28 13:55:57 +01:00
|
|
|
|
2020-12-28 17:38:49 +01:00
|
|
|
// Create and print the KDTree resulting from these points
|
2020-12-28 13:55:57 +01:00
|
|
|
KDTree tree = KDTree(points);
|
|
|
|
std::cout << tree.to_string();
|
|
|
|
|
2020-12-28 17:38:49 +01:00
|
|
|
// Intersection check
|
2021-01-16 22:21:08 +01:00
|
|
|
Vector result(0, 0, 0);
|
|
|
|
const Triangle *intersection =
|
|
|
|
tree.intersect_ray(Ray(new float[3]{0.5, 0.5, -1.0}, new float[3]{0.0, 0.1, 1.0}), result);
|
2020-12-28 17:38:49 +01:00
|
|
|
|
|
|
|
if (intersection != nullptr) { std::cout << "Hit!" << std::endl; }
|
2020-12-28 16:00:29 +01:00
|
|
|
|
2020-12-09 13:09:35 +01:00
|
|
|
return 0;
|
|
|
|
}
|