-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecompose.hpp
More file actions
80 lines (65 loc) · 3.43 KB
/
decompose.hpp
File metadata and controls
80 lines (65 loc) · 3.43 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
#pragma once
#include <vector>
#include <memory>
#include "Object/Triangle/Triangle.hpp"
#include "Point/Point.hpp"
#include "Object/Object.hpp"
using TrianglePtrs = std::vector<std::shared_ptr<Triangle>>;
TrianglePtrs decomponse_pyramid(Point lowest_point, double width, double height, Color color,
double ambient, double diffuse, double specular, double reflection, double shine) {
TrianglePtrs triangle_ptrs;
Point a, b, c, d;
a = b = c = d = lowest_point;
// bottom quad
b.y += width;
c.y += width;
c.x += width;
d.x += width;
triangle_ptrs.push_back(std::make_shared<Triangle>(a, b, c, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(c, d, a, color, ambient, diffuse, specular, reflection, shine));
// top triangles
// diagonal intersection
Point e = a + (c - a) * 0.5;
e.z += height;
// rear
triangle_ptrs.push_back(std::make_shared<Triangle>(e, b, a, color, ambient, diffuse, specular, reflection, shine));
// left
triangle_ptrs.push_back(std::make_shared<Triangle>(e, a, d, color, ambient, diffuse, specular, reflection, shine));
// front
triangle_ptrs.push_back(std::make_shared<Triangle>(e, d, c, color, ambient, diffuse, specular, reflection, shine));
// right
triangle_ptrs.push_back(std::make_shared<Triangle>(e, c, b, color, ambient, diffuse, specular, reflection, shine));
return triangle_ptrs;
}
TrianglePtrs decompose_cube(Point bottom_lower_left_point, double side, Color color,
double ambient, double diffuse, double specular, double reflection, double shine) {
TrianglePtrs triangle_ptrs;
Point a, b, c, d, e, f, g, h;
a = b = c = d = e = f = g = h = bottom_lower_left_point;
d.x += side;
b.y += side;
e.z += side;
c.x += side, c.y += side;
h.x += side, h.z += side;
f.y += side, f.z += side;
g.x += side, g.y += side, g.z += side;
// bottom
triangle_ptrs.push_back(std::make_shared<Triangle>(a, b, c, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(c, d, a, color, ambient, diffuse, specular, reflection, shine));
// top
triangle_ptrs.push_back(std::make_shared<Triangle>(e, h, g, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(g, f, e, color, ambient, diffuse, specular, reflection, shine));
// left
triangle_ptrs.push_back(std::make_shared<Triangle>(e, a, d, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(d, h, e, color, ambient, diffuse, specular, reflection, shine));
// front
triangle_ptrs.push_back(std::make_shared<Triangle>(g, h, d, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(d, c, g, color, ambient, diffuse, specular, reflection, shine));
// right
triangle_ptrs.push_back(std::make_shared<Triangle>(f, g, c, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(c, b, f, color, ambient, diffuse, specular, reflection, shine));
// rear
triangle_ptrs.push_back(std::make_shared<Triangle>(a, e, f, color, ambient, diffuse, specular, reflection, shine));
triangle_ptrs.push_back(std::make_shared<Triangle>(f, b, a, color, ambient, diffuse, specular, reflection, shine));
return triangle_ptrs;
}