Cogs.Core
CrossSectionGenerator.cpp
1#include "CrossSectionGenerator.h"
2
3#include <glm/gtc/quaternion.hpp>
4
5bool Cogs::Geometry::CrossSectionGenerator::generateCircularCrossection(glm::vec3 * vertices, int numSegments, float radius, float startAngle, float endAngle, bool wrapAround)
6{
7 if (!vertices || numSegments <= 0 || radius == 0 || endAngle <= startAngle) return false;
8
9 glm::vec3 vec(radius, 0.0f, 0.0f);
10 float totalAngle = endAngle - startAngle;
11
12 int extra = wrapAround ? 1 : 0;
13
14 float angleIncrement = (totalAngle / static_cast<float>(numSegments - extra));
15
16 for (int i = 0; i < numSegments; i++) {
17 auto rotation = glm::angleAxis(startAngle + angleIncrement * static_cast<float>(i), glm::vec3(0, 0, 1));
18
19 glm::vec3 arcIncrement = rotation * vec;
20
21 vertices[i] = arcIncrement;
22 }
23
24 return true;
25}