-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_provider_example.h
83 lines (69 loc) · 2.54 KB
/
view_provider_example.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
#ifndef VIEW_PROVIDER_EXAMPLE_H_
#define VIEW_PROVIDER_EXAMPLE_H_
#include <cmath>
#include "view_provider.h"
class ViewProviderExample : public ViewProvider {
private:
void rotate(double &x, double &y, const double &angle) {
double x_new = x * cos(angle) - y * sin(angle);
double y_new = x * sin(angle) + y * cos(angle);
x = x_new;
y = y_new;
}
public:
std::vector<ViewConfiguration> provides() {
std::vector<ViewConfiguration> views;
// Take top and bottom
views.push_back(ViewConfiguration(
CameraPosition(0, 2, 0, 0, 0, 0, -1, 2, 0),
"A"));
views.push_back(ViewConfiguration(
CameraPosition(0, -2, 0, 0, 0, 0, 1, -2, 0),
"Z"));
// Rotate around
// We will rotate the point by 45 deg each step
double delta = M_PI / 4;
std::string name = "A";
for (int step = 0; step < 8; ++step) {
// Starting point
double pos_x = 2, pos_y = 0, pos_z = 0;
double up_x = 2, up_y = 1, up_z = 0;
rotate(pos_x, pos_z, step * delta);
rotate(up_x, up_z, step * delta);
++name[0];
views.push_back(ViewConfiguration(
CameraPosition(pos_x, pos_y, pos_z, 0, 0, 0, up_x - pos_x, up_y - pos_y, up_z - pos_z),
name));
}
for (int step = 0; step < 8; ++step) {
// Starting point
double pos_x = 2, pos_y = 0, pos_z = 0;
double up_x = 2, up_y = 1, up_z = 0;
// Go up
rotate(pos_x, pos_y, delta);
rotate(up_x, up_y, delta);
rotate(pos_x, pos_z, step * delta);
rotate(up_x, up_z, step * delta);
++name[0];
views.push_back(ViewConfiguration(
CameraPosition(pos_x, pos_y, pos_z, 0, 0, 0, up_x - pos_x, up_y - pos_y, up_z - pos_z),
name));
}
for (int step = 0; step < 8; ++step) {
// Starting point
double pos_x = 2, pos_y = 0, pos_z = 0;
double up_x = 2, up_y = 1, up_z = 0;
// Go down
rotate(pos_x, pos_y, -delta);
rotate(up_x, up_y, -delta);
rotate(pos_x, pos_z, step * delta);
rotate(up_x, up_z, step * delta);
++name[0];
views.push_back(ViewConfiguration(
CameraPosition(pos_x, pos_y, pos_z, 0, 0, 0, up_x - pos_x, up_y - pos_y, up_z - pos_z),
name));
}
return views;
}
};
#endif