-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primitives.h
96 lines (76 loc) · 1.69 KB
/
Primitives.h
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
#pragma once
namespace Tmpl8 {
class Material
{
public:
Material(vec4 color, MaterialType type);
vec4 color;
float reflection, refraction;
MaterialType type;
};
class Primitive
{
public:
Primitive(Material* material);
int id;
Material* material;
BoundingBox* boundingBox;
virtual void intersect(Ray* ray) = 0;
virtual vec3 getNormal(vec3 point) = 0;
virtual void translate(vec3 vector) = 0;
};
class Sphere : public Primitive
{
public:
Sphere(Material* material, vec3 position, float radius);
void intersect(Ray* ray);
vec3 getNormal(vec3 point);
void translate(vec3 vector);
private:
vec3 position;
float radius, radius2;
};
class Triangle : public Primitive
{
public:
Triangle(Material* material, vec3 a, vec3 b, vec3 c);
void intersect(Ray* ray);
vec3 getNormal(vec3 point);
void translate(vec3 vector);
private:
vec3 a, b, c;
vec3 normal;
};
class Plane : public Primitive
{
public:
Plane(Material* material, vec3 position, vec3 direction, float size = 10);
void intersect(Ray* ray);
vec3 getNormal(vec3 point);
void translate(vec3 vector);
private:
vec3 position, direction;
};
class Cylinder : public Primitive
{
public:
Cylinder(Material* material, vec3 position, vec3 upVector, float radius, float height);
void intersect(Ray* ray);
vec3 getNormal(vec3 point);
void translate(vec3 vector);
private:
vec3 position, upVector;
float radius, height;
};
class Torus : public Primitive
{
public:
Torus(Material* material, float R, float r, vec3 position, vec3 axis);
void intersect(Ray* ray);
vec3 getNormal(vec3 point);
void translate(vec3 vector);
private:
float R, r;
vec3 position, axis;
};
}