-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.hpp
More file actions
105 lines (88 loc) · 2.45 KB
/
Copy pathShape.hpp
File metadata and controls
105 lines (88 loc) · 2.45 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef SHAPE_HPP
#define SHAPE_HPP
class Shape;
class Material;
#include "Transform.hpp"
#include "Ray.hpp"
#include "Material.hpp"
#include "BoundingBox3.hpp"
typedef struct Hit {
Vector3 position, normal;
Ray ray;
fixed32 t;
Shape* shape;
Hit();
Hit(Shape*);
operator bool() const;
} Hit;
class Shape {
public:
Material* material;
Hit virtual intersectRay(Ray) = 0;
void virtual generateSubshapes() {};
void virtual generateBoundingBox() {};
BoundingBox3 getBoundingBox();
private:
};
class Sphere : public Shape, public BoundingBoxedShape {
public:
Transform transform;
fixed32 radius;
Sphere(Vector3 position, fixed32 radius);
Sphere(Vector3 position);
Sphere(fixed32 radius);
Sphere();
Hit intersectRay(Ray) override;
void generateBoundingBox() override;
BoundingBox3 getBoundingBox() const override;
private:
BoundingBox3 boundingBox;
};
class Plane : public Shape {
public:
Vector3 position, normal;
Plane(Vector3 pos, Vector3 norm);
Plane(Vector3 pos);
Plane();
Hit intersectRay(Ray) override;
};
class Triangle : public Plane {
public:
Vector3 v1, v2, v3;
Triangle(Vector3 v1, Vector3 v2, Vector3 v3);
Triangle();
Hit intersectRay(Ray) override;
};
class Disc : public Plane {
public:
fixed32 radius;
Disc(Vector3 pos, Vector3 norm, fixed32 rad);
Disc(Vector3 pos, fixed32 rad);
Disc(Vector3 pos, Vector3 norm);
Disc(Vector3 pos);
Disc(fixed32 rad);
Disc();
Hit intersectRay(Ray) override;
};
class Cylinder : public Disc, public BoundingBoxedShape {
public:
fixed32 height;
Cylinder(Vector3 pos, Vector3 norm, fixed32 rad, fixed32 height);
Cylinder(Vector3 pos, Vector3 norm, fixed32 rad);
Cylinder(Vector3 pos, Vector3 norm);
Cylinder(Vector3 pos, fixed32 rad, fixed32 height);
Cylinder(Vector3 pos, fixed32 rad);
Cylinder(Vector3 pos);
Cylinder(fixed32 rad, fixed32 height);
Cylinder(fixed32 rad);
Cylinder();
Hit intersectRay(Ray) override;
void generateSubshapes() override;
void generateBoundingBox() override;
BoundingBox3 getBoundingBox() const override;
private:
Disc d1;
Disc d2;
BoundingBox3 boundingBox;
};
#endif