Cogs.Core
ProfileGenerator.cpp
1#include "ProfileGenerator.h"
2
3namespace Cogs
4{
5 namespace Geometry
6 {
7 namespace ProfileGenerator
8 {
9 void
10 generateConnector(std::vector<float> & depths,
11 std::vector<glm::vec2> & profile,
12 const float startDepth,
13 const float endDepth,
14 const float startRadius,
15 const float outerRadius,
16 const float endRadius,
17 const float depthAnchor)
18 {
19 profile.push_back(glm::vec2(startRadius, startDepth - depthAnchor)); depths.push_back(depthAnchor);
20 profile.push_back(glm::vec2(outerRadius, startDepth - depthAnchor)); depths.push_back(depthAnchor);
21
22 profile.push_back(glm::vec2(outerRadius, endDepth - depthAnchor)); depths.push_back(depthAnchor);
23 profile.push_back(glm::vec2(endRadius, endDepth - depthAnchor)); depths.push_back(depthAnchor);
24 }
25
26 void
27 generateCurvedProfile(std::vector<float> & depths,
28 std::vector<glm::vec2> & profile,
29 const float startDepth,
30 const float endDepth,
31 const float startRadius,
32 const float endRadius,
33 const float numSections)
34 {
35 float scaledOuterRadius = startRadius;
36 float flexStart = startDepth;
37 float flexBulgeScaleRange = endRadius - startRadius;
38 float flexBulgeLength = endDepth - startDepth;
39
40 for (int i = 0; i <= numSections; ++i) {
41 const float increment = (float) i / (float) numSections;
42 const float value = increment < 0.5 ? increment * increment * 2 : 1 - (1 - increment) * (1 - increment) * 2;
43
44 profile.push_back(glm::vec2(scaledOuterRadius + flexBulgeScaleRange * value, 0)); depths.push_back(flexStart + flexBulgeLength * increment);
45 }
46 }
47
48 void
49 insertPoints(std::vector<float> & depths,
50 std::vector<glm::vec2> & profile,
51 const float radius,
52 const float startDepth,
53 const float endDepth,
54 std::vector<float>::const_iterator it,
55 std::vector<float>::const_iterator end)
56 {
57 while (it != end && *it <= startDepth) {
58 ++it;
59 }
60
61 while (it != end && *it < endDepth) {
62 profile.push_back(glm::vec2(radius, 0)); depths.push_back(*it++);
63 }
64 }
65
66 void
67 insertPointsReverse(std::vector<float> & depths,
68 std::vector<glm::vec2> & profile,
69 const float radius,
70 const float startDepth,
71 const float endDepth,
72 std::vector<float>::const_iterator it)
73 {
74 it--;
75
76 while (*it >= endDepth) {
77 it--;
78 }
79
80 while (*it > startDepth) {
81 profile.push_back(glm::vec2(radius, 0)); depths.push_back(*it--);
82 }
83 }
84
88 void
89 reverseProfile(std::vector<float> & depths, std::vector<glm::vec2> & profile, const float startDepth, const float endDepth)
90 {
91 for (size_t i = 0; i < profile.size(); ++i) {
92 depths[i] = endDepth - (depths[i] - startDepth);
93
94 // When reversing the running direction of the profile, the directional part of the offsets must be reversed.
95 profile[i][1] = -profile[i][1];
96 }
97
98 std::reverse(depths.begin(), depths.end());
99 std::reverse(profile.begin(), profile.end());
100 }
101 }
102 }
103}
@ Geometry
Store entity vector fields (vector<vec3>, vector<vec2>, vector<int>, vector<float>).
void reverseProfile(std::vector< float > &depths, std::vector< glm::vec2 > &profile, const float startDepth, const float endDepth)
Reverses the given profile.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23