-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.hpp
54 lines (40 loc) · 1.49 KB
/
Shape.hpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "Ray.hpp"
#include "Material.hpp"
struct Shape;
template<typename T>
struct Intersection {
const T* shape;
Vec3 pos;
Vec3 normal;
float distanceFromRayStartSquared;
CUDA_CALLABLE Intersection(T* shape_, Vec3 pos_, Vec3 normal_, float dist_) : shape(shape_), normal(normal_), pos(pos_), distanceFromRayStartSquared(dist_) { }
CUDA_CALLABLE Intersection() : shape(NULL), pos(0, 0, 0), normal(0, 0, 0), distanceFromRayStartSquared(1000000000) { }
CUDA_CALLABLE Intersection<Shape> toGenericShapeIntersection() {
Intersection<Shape> s;
s.pos = pos;
s.normal = normal;
s.shape = shape;
s.distanceFromRayStartSquared = distanceFromRayStartSquared;
return s;
}
CUDA_CALLABLE bool operator<(const Intersection<T>& inter) const {
return distanceFromRayStartSquared < inter.distanceFromRayStartSquared;
}
};
struct CudaTriangleIntersection {
float* triangleStart;
float intersectionS;
float intersectionT;
float distanceFromRayStartSquared;
Vec3 pos;
CUDA_CALLABLE CudaTriangleIntersection() : triangleStart(NULL), pos(0, 0, 0), distanceFromRayStartSquared(1000000000) { }
CUDA_CALLABLE bool operator<(const CudaTriangleIntersection& inter) const {
return distanceFromRayStartSquared < inter.distanceFromRayStartSquared;
}
};
struct Shape {
Color color;
Material material;
CUDA_CALLABLE virtual ~Shape() { }
};