| 31 | } |
| 32 | |
| 33 | cpp::Group Streamlines::buildGroup() const |
| 34 | { |
| 35 | cpp::Geometry slGeom("curve"); |
| 36 | |
| 37 | std::vector<vec4f> points; |
| 38 | std::vector<unsigned int> indices; |
| 39 | std::vector<vec4f> colors; |
| 40 | |
| 41 | std::mt19937 rng(randomSeed); |
| 42 | utility::uniform_real_distribution<float> radDist(0.5f, 1.5f); |
| 43 | utility::uniform_real_distribution<float> stepDist(0.001f, 0.1f); |
| 44 | utility::uniform_real_distribution<float> sDist(0, 360); |
| 45 | utility::uniform_real_distribution<float> dDist(360, 720); |
| 46 | utility::uniform_real_distribution<float> freqDist(0.5f, 1.5f); |
| 47 | |
| 48 | // create multiple lines |
| 49 | int numLines = 100; |
| 50 | for (int l = 0; l < numLines; l++) { |
| 51 | int dStart = sDist(rng); |
| 52 | int dEnd = dDist(rng); |
| 53 | float radius = radDist(rng); |
| 54 | float h = 0; |
| 55 | float hStep = stepDist(rng); |
| 56 | float f = freqDist(rng); |
| 57 | |
| 58 | float r = (720 - dEnd) / 360.f; |
| 59 | vec4f c(r, 1 - r, 1 - r / 2, 1.f); |
| 60 | |
| 61 | // spiral up with changing radius of curvature |
| 62 | for (int d = dStart; d < dStart + dEnd; d += 10, h += hStep) { |
| 63 | vec3f p, q; |
| 64 | float startRadius, endRadius; |
| 65 | |
| 66 | p.x = radius * std::sin(d * M_PI / 180.f); |
| 67 | p.y = h - 2; |
| 68 | p.z = radius * std::cos(d * M_PI / 180.f); |
| 69 | startRadius = 0.015f * std::sin(f * d * M_PI / 180) + 0.02f; |
| 70 | |
| 71 | q.x = (radius - 0.05f) * std::sin((d + 10) * M_PI / 180.f); |
| 72 | q.y = h + hStep - 2; |
| 73 | q.z = (radius - 0.05f) * std::cos((d + 10) * M_PI / 180.f); |
| 74 | endRadius = 0.015f * std::sin(f * (d + 10) * M_PI / 180) + 0.02f; |
| 75 | if (d == dStart) { |
| 76 | const vec3f rim = lerp(1.f + endRadius / length(q - p), q, p); |
| 77 | const vec3f cap = lerp(1.f + startRadius / length(rim - p), p, rim); |
| 78 | points.push_back(vec4f(cap, 0.f)); |
| 79 | points.push_back(vec4f(rim, 0.f)); |
| 80 | points.push_back(vec4f(p, startRadius)); |
| 81 | points.push_back(vec4f(q, endRadius)); |
| 82 | indices.push_back(points.size() - 4); |
| 83 | colors.push_back(c); |
| 84 | colors.push_back(c); |
| 85 | } else if (d + 10 < dStart + dEnd && d + 20 > dStart + dEnd) { |
| 86 | const vec3f rim = lerp(1.f + startRadius / length(p - q), p, q); |
| 87 | const vec3f cap = lerp(1.f + endRadius / length(rim - q), q, rim); |
| 88 | points.push_back(vec4f(p, startRadius)); |
| 89 | points.push_back(vec4f(q, endRadius)); |
| 90 | points.push_back(vec4f(rim, 0.f)); |