196 } |
196 } |
197 }; |
197 }; |
198 |
198 |
199 glm::vec3 pointOnCurve(const BezierCurve& curve, float t); |
199 glm::vec3 pointOnCurve(const BezierCurve& curve, float t); |
200 glm::vec3 derivativeOnCurve(const BezierCurve& curve, float t); |
200 glm::vec3 derivativeOnCurve(const BezierCurve& curve, float t); |
|
201 |
|
202 template<typename Iter> |
|
203 std::optional<glm::mat3> calculateNormal(Iter&& begin, Iter&& end) |
|
204 { |
|
205 const long int n = end - begin; |
|
206 std::optional<glm::mat3> result; |
|
207 for (long int i = 0; i < n; ++i) { |
|
208 const glm::vec3& v1 = *(begin + (i + n - 1) % n); |
|
209 const glm::vec3& v2 = *(begin + i); |
|
210 const glm::vec3& v3 = *(begin + (i + 1) % n); |
|
211 const glm::vec3 xvec = v1 - v2; |
|
212 const glm::vec3 yvec = v3 - v2; |
|
213 constexpr float threshold = 1e-6f; |
|
214 if (glm::length(xvec) > threshold and glm::length(yvec) > threshold) { |
|
215 const glm::vec3 zvec = glm::cross(glm::normalize(xvec), glm::normalize(yvec)); |
|
216 if (glm::length(zvec) > threshold) { |
|
217 result = {xvec, yvec, zvec}; |
|
218 break; |
|
219 } |
|
220 } |
|
221 } |
|
222 return result; |
|
223 } |