KDTree and multiple mesh and primative rendering

This commit is contained in:
Ben Kyd
2019-08-07 05:01:43 +01:00
parent cf142ff5be
commit 17df4e0d09
19 changed files with 395 additions and 38 deletions

View File

@@ -1,3 +1,30 @@
#include "mesh.hpp"
#include <iostream>
#include "../../acceleration/kd.hpp"
#include "../ray.hpp"
#include "triangle.hpp"
Mesh::Mesh(std::vector<Triangle*> tris) {
triangles = tris;
}
void Mesh::Optimise() {
if (!optimised) {
free((void*)m_kdTree);
}
m_kdTree = BuildKDTree(triangles);
optimised = true;
}
bool Mesh::Intersect(Ray* ray, Triangle*& intersect, float& t) {
if (!optimised) {
bool hit = TraceRayMesh(*ray, this, t, intersect);
return hit;
}
return KDIntersect(m_kdTree, ray, intersect, t);
}