-
Notifications
You must be signed in to change notification settings - Fork 0
/
capi.cpp
29 lines (25 loc) · 984 Bytes
/
capi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// Created by viktorm on 2020-06-03.
//
#include "capi.h"
[[maybe_unused]] bounding_volume_hierarchy *create(float *bounds, int count) {
static_assert(sizeof(Bounds) == 6 * 4);
count /= 6;
bounding_volume_hierarchy* bvh = new bounding_volume_hierarchy(reinterpret_cast<Bounds *>(bounds), count);
bvh->build_radix_tree();
bvh->build_bounding_volume();
return bvh;
}
[[maybe_unused]] bool intersection(bounding_volume_hierarchy *bvh, float *ray) {
static_assert(sizeof(Ray) == 6 * 4);
return bvh->intersection(*reinterpret_cast<Ray *>(ray));
}
[[maybe_unused]] void intersection_batch(bounding_volume_hierarchy *bvh, float *ray, uint8_t * out, int count) {
static_assert(sizeof(Ray) == 6 * 4);
count /= 6;
std::vector<Ray> rays(reinterpret_cast<Ray *>(ray), reinterpret_cast<Ray *>(ray) + count);
return bvh->intersection_batch(rays, out, count);
}
[[maybe_unused]] void destroy(bounding_volume_hierarchy *bvh) {
delete bvh;
}