kdtree/main.cpp

27 lines
937 B
C++
Raw Permalink Normal View History

2020-12-28 13:55:57 +01:00
#include "kdtree.h"
2020-12-09 13:09:35 +01:00
#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));
2020-12-09 13:09:35 +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
// 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();
// Intersection check
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);
if (intersection != nullptr) { std::cout << "Hit!" << std::endl; }
2020-12-09 13:09:35 +01:00
return 0;
}