generated from karl/cpp-template
27 lines
937 B
C++
27 lines
937 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
|
|
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; }
|
|
|
|
return 0;
|
|
}
|