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