This commit is contained in:
Emma Broman
2020-06-30 13:50:20 +02:00
parent f247b714bd
commit 6b4c329a29
4 changed files with 113 additions and 53 deletions
+34
View File
@@ -31,8 +31,10 @@
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
namespace {
@@ -353,5 +355,37 @@ void renderBox(const glm::vec2& position, const glm::vec2& size, const glm::vec4
shdr.program->deactivate();
}
VertexXYZ convertToXYZ(const Vertex& v) {
return VertexXYZ{ v.xyz[0], v.xyz[1], v.xyz[2] };
}
std::vector<VertexXYZ> convert(std::vector<Vertex> v) {
std::vector<VertexXYZ> result(v.size());
std::transform(v.begin(), v.end(), result.begin(), convertToXYZ);
return result;
}
std::vector<Vertex> createRing(int nSegments, float radius, glm::vec4 colors) {
const int nVertices = nSegments + 1;
std::vector<Vertex> vertices(nVertices);
const float fsegments = static_cast<float>(nSegments);
for (int i = 0; i <= nSegments; ++i) {
const float fi = static_cast<float>(i);
const float theta = fi * glm::pi<float>() * 2.0f / fsegments; // 0 -> 2*PI
const float x = radius * cos(theta);
const float y = radius * sin(theta);
const float z = 0.0f;
const float u = cos(theta);
const float v = sin(theta);
vertices[i] = { x, y, z, u, v, colors.r, colors.g, colors.b, colors.a };
}
return vertices;
}
} // namespace openspace::rendering::helper