kdtree/main.cpp
karl bf96bbf26f Some bugfixes and intersection test in Main
It seems to work, at least to some extent!
2020-12-28 17:39:58 +01:00

26 lines
895 B
C++

#include "kdtree.h"
#include <iostream>
int main() {
// 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));
// 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());
// Create and print the KDTree resulting from these points
KDTree tree = KDTree(points);
std::cout << tree.to_string();
// Intersection check
Triangle *intersection =
tree.intersect_ray(Ray(new float[3]{0.5, 0.5, -1.0}, new float[3]{0.0, 0.1, 1.0}));
if (intersection != nullptr) { std::cout << "Hit!" << std::endl; }
return 0;
}