More boilerplate
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <algorithm>
|
||||
#include "util/Ray.h"
|
||||
|
||||
struct AABB
|
||||
{
|
||||
@@ -42,6 +43,11 @@ struct AABB
|
||||
max = glm::vec3(std::max(max.x, transformed.x), std::max(max.y, transformed.y), std::max(max.z, transformed.z));
|
||||
}
|
||||
}
|
||||
bool intersects(Ray ray)
|
||||
{
|
||||
assert(false && "TODO");
|
||||
return false;
|
||||
}
|
||||
static AABB combine(AABB lhs, AABB rhs)
|
||||
{
|
||||
AABB result = {
|
||||
|
||||
+34
-1
@@ -1,5 +1,6 @@
|
||||
#include "BVH.h"
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
|
||||
void BVH::addModel(PModel model, glm::mat4 transform)
|
||||
{
|
||||
@@ -54,3 +55,35 @@ void BVH::generate()
|
||||
}
|
||||
hierarchy = std::move(pendingNodes[0]);
|
||||
}
|
||||
|
||||
std::optional<IntersectionInfo> BVH::traceRay(Ray ray)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<IntersectionInfo> BVH::generateIntersections(PNode& currentNode, Ray ray)
|
||||
{
|
||||
if(!currentNode->aabb.intersects(ray))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if(currentNode->model != nullptr)
|
||||
{
|
||||
auto result = currentNode->model->intersect(ray);
|
||||
if(result.has_value())
|
||||
{
|
||||
return {*result};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
auto leftResults = generateIntersections(currentNode->left, ray);
|
||||
auto rightResults = generateIntersections(currentNode->right, ray);
|
||||
|
||||
for(auto it : rightResults)
|
||||
{
|
||||
leftResults.push_back(it);
|
||||
}
|
||||
return leftResults;
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "util/Model.h"
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#include "util/Ray.h"
|
||||
|
||||
|
||||
class BVH
|
||||
{
|
||||
@@ -11,6 +13,8 @@ class BVH
|
||||
void addModels(std::vector<PModel> models, glm::mat4 transform);
|
||||
void generate();
|
||||
|
||||
std::optional<IntersectionInfo> traceRay(Ray ray);
|
||||
|
||||
private:
|
||||
DECLARE_REF(Node)
|
||||
struct Node
|
||||
@@ -24,4 +28,6 @@ class BVH
|
||||
};
|
||||
PNode hierarchy;
|
||||
std::vector<PModel> models;
|
||||
|
||||
std::vector<IntersectionInfo> generateIntersections(PNode& currentNode, Ray ray);
|
||||
};
|
||||
@@ -1,3 +1,9 @@
|
||||
#include "Scene.h"
|
||||
|
||||
Scene::Scene()
|
||||
: window(1920, 1080)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Scene::render() {}
|
||||
|
||||
+3
-1
@@ -5,9 +5,11 @@
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
void render();
|
||||
private:
|
||||
Window window;
|
||||
std::vector<uint32_t> image;
|
||||
std::vector<unsigned char> image;
|
||||
BVH bvh;
|
||||
};
|
||||
Reference in New Issue
Block a user