Unravel Engine C++ Reference
Loading...
Searching...
No Matches
knot_path.cpp
Go to the documentation of this file.
1#include "knot_path.hpp"
2
3using namespace generator;
4
5namespace
6{
7
8gml::dvec3 knot(int p, int q, double t)
9{
10 t *= gml::radians(360.0);
11
12 const double pt = p * t;
13 const double qt = q * t;
14
15 const double sinpt = std::sin(pt);
16 const double cospt = std::cos(pt);
17 const double sinqt = std::sin(qt);
18 const double cosqt = std::cos(qt);
19
20 const double r = 0.5 * (2.0 + sinqt);
21
22 return gml::dvec3{r * cospt, r * sinpt, r * cosqt};
23}
24} // namespace
25
27 : parametric_path_{[p, q](double t)
28 {
29 path_vertex_t vertex;
30
31 vertex.position = knot(p, q, t);
32
33 const gml::dvec3 prev = knot(p, q, t - 0.01);
34 const gml::dvec3 next = knot(p, q, t + 0.01);
35
36 vertex.tangent = normalize(next - prev);
37
38 vertex.normal = normalize(cross(next - prev, next + prev));
39
40 vertex.tex_coord = t;
41
42 return vertex;
43 },
45{
46}
knot_path_t(int p=2, int q=3, int segments=96)
Definition knot_path.cpp:26
const segment_list * segments