-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewerscene.cpp
More file actions
114 lines (96 loc) · 3.02 KB
/
Copy pathviewerscene.cpp
File metadata and controls
114 lines (96 loc) · 3.02 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
106
107
108
109
110
111
112
113
114
#include "viewerscene.h"
#include "Builder/polygonmodelbuilder.h"
#include "treepolygonbuilder.h"
ViewerScene::ViewerScene()
{
srand(time(NULL));
_composite = std::shared_ptr<CompositeObject>(new CompositeObject());
_cur_camera = std::shared_ptr<Camera>(new Camera(Point3D(0, 0, 1), Point3D(0, 200, -300), Point3D(0, 1, 0)));
_light = std::shared_ptr<Light>(new Light(Vec3i<float>(0, 0, 1), Vec3i<float>(0, 0, 1), Qt::white));
std::shared_ptr<Object3D> plane = _create_plane(Point3D(-400, -100, -100), Point3D(400, 0, 700), Qt::white);
add_obj(plane);
std::shared_ptr<HondaFunctionSystem> func(new HondaFunctionSystem(0.75, 0.75));
TreeSkeletonBuilder sk_builder(func, 2);
/*TreePolygonBuilder builder(sk_builder, Qt::black);
std::shared_ptr<Object3D> tree = builder.build(std::shared_ptr<TreeSegment>(new TreeSegment({100, 0, 100}, {100, 100, 100}, 7, 6)));
add_obj(tree);*/
}
void ViewerScene::add_obj(std::shared_ptr<Object3D> obj)
{
_composite->add_obj(obj);
}
void ViewerScene::set_camera(CompObjIterator iter)
{
_cur_camera = std::dynamic_pointer_cast<Camera>(*iter);
}
std::shared_ptr<Camera> ViewerScene::get_camera()
{
return _cur_camera;
}
std::shared_ptr<Light> ViewerScene::get_light()
{
return _light;
}
std::shared_ptr<Object3D> ViewerScene::get_area()
{
return _area;
}
void ViewerScene::set_area(std::shared_ptr<Object3D> area)
{
if (_area != nullptr) {
_composite->erase(_area_idx);
}
_area_idx = _composite->add_obj(area);
_area = area;
}
CompObjIterator ViewerScene::begin()
{
return _composite->begin();
}
CompObjIterator ViewerScene::end()
{
return _composite->end();
}
void ViewerScene::clear()
{
int count = _composite->count();
for (size_t i = 1; i < count; ++i) {
_composite->erase(i);
}
_area_idx = _composite->add_obj(_area);
}
std::shared_ptr<Object3D> ViewerScene::_create_plane(Point3D a, Point3D b, QColor color)
{
double xs[] = {a.get_x(), b.get_x()};
double ys[] = {a.get_y(), b.get_y()};
double zs[] = {a.get_z(), b.get_z()};
PolygonModelBuilder builder;
builder.build_model();
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
builder.build_vert(xs[i], ys[j], zs[k]);
}
}
}
// Боковые
// Левая
builder.build_polygon(0, 1, 2, color);
builder.build_polygon(1, 2, 3, color, false);
// Правая
builder.build_polygon(4, 5, 6, color);
builder.build_polygon(5, 6, 7, color);
// Передняя
builder.build_polygon(0, 2, 6, color, false);
builder.build_polygon(0, 4, 6, color);
// Задняя
builder.build_polygon(1, 3, 7, color);
builder.build_polygon(1, 5, 7, color);
// Нижняя
builder.build_polygon(0, 1, 4, color, false);
builder.build_polygon(1, 4, 5, color);
// Верхняя
builder.build_polygon(2, 3, 6, color, false);
builder.build_polygon(3, 6, 7, color);
return builder.get_model();
}