29 { |
29 { |
30 color = vec4(ex_color, 1); |
30 color = vec4(ex_color, 1); |
31 } |
31 } |
32 )"; |
32 )"; |
33 |
33 |
34 static constexpr glm::vec3 o = {0, 0, 0}; |
34 std::vector<glm::vec3> sphere(const int d2) |
35 static constexpr glm::vec3 c1 = {1, -1, 1}; |
35 { |
36 static constexpr glm::vec3 c2 = {1, -1, -1}; |
36 std::vector<glm::vec3> result; |
37 static constexpr glm::vec3 c3 = {-1, -1, -1}; |
37 result.reserve(12 * d2 * d2); |
38 static constexpr glm::vec3 c4 = {-1, -1, 1}; |
38 for (int i = 0; i < d2; ++i) |
39 |
39 { |
40 static constexpr glm::vec3 markerGeometry[] = { |
40 const float alpha = i * math::pi / d2; |
41 o, c1, c2, |
41 const float alpha_2 = (i + 1) * math::pi / d2; |
42 o, c2, c3, |
42 for (int j = -d2; j < d2; ++j) |
43 o, c3, c4, |
43 { |
44 o, c4, c1, |
44 const float beta = j * math::pi / d2; |
45 }; |
45 const float beta_2 = (j + 1) * math::pi / d2; |
|
46 const float x1 = cos(beta) * sin(alpha); |
|
47 const float x2 = cos(beta) * sin(alpha_2); |
|
48 const float x3 = cos(beta_2) * sin(alpha_2); |
|
49 const float x4 = cos(beta_2) * sin(alpha); |
|
50 const float z1 = sin(beta) * sin(alpha); |
|
51 const float z2 = sin(beta) * sin(alpha_2); |
|
52 const float z3 = sin(beta_2) * sin(alpha_2); |
|
53 const float z4 = sin(beta_2) * sin(alpha); |
|
54 const float y1 = cos(alpha); |
|
55 const float y2 = cos(alpha_2); |
|
56 result.push_back({x1, y1, z1}); |
|
57 result.push_back({x2, y2, z2}); |
|
58 result.push_back({x3, y2, z3}); |
|
59 result.push_back({x1, y1, z1}); |
|
60 result.push_back({x3, y2, z3}); |
|
61 result.push_back({x4, y1, z4}); |
|
62 } |
|
63 } |
|
64 return result; |
|
65 } |
46 |
66 |
47 VertexProgram::VertexProgram(QObject *parent) : |
67 VertexProgram::VertexProgram(QObject *parent) : |
48 AbstractBasicShaderProgram{parent} |
68 AbstractBasicShaderProgram{parent} |
49 { |
69 { |
50 } |
70 } |
102 |
122 |
103 void VertexProgram::build(const Document *document) |
123 void VertexProgram::build(const Document *document) |
104 { |
124 { |
105 constexpr glm::vec3 color = {0.0, 1.0, 1.0}; |
125 constexpr glm::vec3 color = {0.0, 1.0, 1.0}; |
106 this->data.clear(); |
126 this->data.clear(); |
|
127 const std::vector<glm::vec3> sphere = ::sphere(8 / 2); |
107 document->applyToVertices([&](const glm::vec3&, const VertexMap::VertexInfo& info) |
128 document->applyToVertices([&](const glm::vec3&, const VertexMap::VertexInfo& info) |
108 { |
129 { |
109 reserveMore(this->data, ::countof(::markerGeometry)); |
130 reserveMore(this->data, sphere.size()); |
110 for (const glm::vec3& point : ::markerGeometry) |
131 for (const glm::vec3& point : sphere) |
111 { |
132 { |
112 const glm::vec3 transformed = info.transform * glm::vec4{point, 1}; |
133 const glm::vec3 transformed = glm::scale(info.transform, glm::vec3{0.5, 0.5, 0.5}) * glm::vec4{point, 1}; |
113 this->data.push_back({transformed, color}); |
134 this->data.push_back({transformed, color}); |
114 } |
135 } |
115 }); |
136 }); |
116 this->buffer.bind(); |
137 this->buffer.bind(); |
117 this->buffer.allocate(this->vertexData(), this->vertexCount() * this->vertexSize()); |
138 this->buffer.allocate(this->vertexData(), this->vertexCount() * this->vertexSize()); |