Saga
Saga Game Engine
Loading...
Searching...
No Matches
bvh.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4#include <vector>
5#include <set>
6#include "boundingBox.h"
7#include <optional>
8#include <memory>
10
11namespace Saga {
12
20 public:
24 struct TriangleData {
25 glm::vec3 triangle[3];
26 Entity entity;
27 };
28
36
41 void computeBound();
42 };
43
49 using TracedData = std::tuple<TriangleData*, float>;
50 private:
54 struct Node {
55 BoundingBox box;
59 std::vector<BoundedShapeData*> shapes;
60
64 std::vector<std::shared_ptr<Node>> children;
65 };
66 public:
72 void build(const std::vector<TriangleData> &triangles);
73
74
86 std::optional<TracedData> traceEllipsoid(glm::vec3 pos, glm::vec3 dir, glm::vec3 scale);
87
88 private:
96 static const int NUM_TRIANGLES_PER_LEAF = 10;
97
106 void build(std::shared_ptr<Node> node, std::vector<BoundedShapeData*> &shapes);
107
108 std::shared_ptr<Node> root;
109 std::vector<BoundedShapeData> allShapes;
110
123 void traceEllipsoid(glm::vec3 pos, glm::vec3 dir, glm::vec3 scale,
124 std::shared_ptr<Node> node, std::optional<TracedData> &result);
125 };
126
127
128};
A tree of bounding volumes, with leaf nodes containing a collection of triangles. Useful as a space-a...
Definition: bvh.h:19
void build(const std::vector< TriangleData > &triangles)
Build a BoundingVolumeHierarchy based on a collection of TriangleData.
std::tuple< TriangleData *, float > TracedData
Information about a trace operation on this datastructure, including a pointer to the first TriangleD...
Definition: bvh.h:49
std::optional< TracedData > traceEllipsoid(glm::vec3 pos, glm::vec3 dir, glm::vec3 scale)
Trace an ellipsoid through the Bounding Volume Hierarchy, reporting the first intersection if it exis...
Definition: bvh.cpp:105
Definition: app.cpp:8
Represents a bounding box.
Definition: boundingBox.h:13
Data on a bounded triangle, which includes the triangle itself and its BoundingBox.
Definition: bvh.h:33
void computeBound()
Recompute the bounding box of the triangle inside the data field. Call this function after assigning ...
Definition: bvh.cpp:130
BoundingBox box
triangle's bounding box.
Definition: bvh.h:34
TriangleData data
triangle's information.
Definition: bvh.h:35
Data on a single triangles in the structure.
Definition: bvh.h:24
glm::vec3 triangle[3]
coordinates of the triangle, in CCW order.
Definition: bvh.h:25
Entity entity
the entity the triangle is attached to.
Definition: bvh.h:26