more templates in point

This commit is contained in:
2020-03-15 12:53:14 -04:00
parent f06f92bd9b
commit 2277036c02
2 changed files with 31 additions and 25 deletions

View File

@@ -161,15 +161,15 @@ V gram_schmidt_last(std::vector<V> vecs) {
return normalized(vecs[vecs.size() - 1]); return normalized(vecs[vecs.size() - 1]);
} }
template<class V> template<class V, class C>
V barycentric(const std::vector<V> &basis, const std::vector<float> &coords) { V barycentric(const std::vector<V> &basis, const C &coords) {
V res{}; V res{};
int N = std::min(basis.size(), coords.size()); int N = std::min(basis.size(), coords.size());
for (int i = 0; i < N; ++i) { for (int i = 0; i < N; ++i) {
res += basis[i] * coords[i]; res += basis[i] * coords[i];
} }
return normalized(res); return res;
} }
template<class V> template<class V>

View File

@@ -68,7 +68,8 @@ auto hull(const tc::Group &group, T begin, T end) {
return parts; return parts;
} }
std::vector<vec4> points(const tc::Group &group, const std::vector<float> &coords) { template<class C>
std::vector<vec4> points(const tc::Group &group, const C &coords) {
auto cosets = group.solve(); auto cosets = group.solve();
auto mirrors = mirror<5>(group); auto mirrors = mirror<5>(group);
@@ -118,14 +119,14 @@ struct Slice {
Slice(Slice &&) noexcept = default; Slice(Slice &&) noexcept = default;
void draw() { void draw() const {
vao.bound([&]() { vao.bound([&]() {
glDrawArrays(GL_POINTS, 0, ibo.count() * N); glDrawArrays(GL_POINTS, 0, ibo.count() * N);
}); });
} }
template<class T> template<class T, class C>
static Slice<N> build(const tc::Group &g, const std::vector<float> &coords, vec4 color, T begin, T end) { static Slice<N> build(const tc::Group &g, const C &coords, vec4 color, T begin, T end) {
Slice<N> res(GL_POINTS, color); Slice<N> res(GL_POINTS, color);
res.vbo.put(points(g, coords)); res.vbo.put(points(g, coords));
@@ -158,18 +159,25 @@ void run(GLFWwindow *window) {
auto group = tc::schlafli({5, 3, 3, 2}); auto group = tc::schlafli({5, 3, 3, 2});
const auto combos = Combos<int>({0, 1, 2, 3, 4}, 3); const auto combos = Combos<int>({0, 1, 2, 3, 4}, 3);
const auto last = Combos<int>({0,2,3,4},3);
auto white = Slice<4>::build( auto slices = {
group, Slice<4>::build(
{0.3f, 0.1f, 0.1f, 0.1f, 0.05f}, group,
{0.9f, 0.9f, 0.9f, 1.0f}, (vec5) {0.5, 0.05, 0.05, 0.05, 0.025},
combos.begin(), combos.end()); {0.9f, 0.9f, 0.9f, 1.0f},
combos.begin(), combos.end()),
auto black = Slice<4>::build( Slice<4>::build(
group, group,
{1.0f, 0.1f, 0.1f, 0.1f, 0.5f}, (vec5) {0.5, 0.05, 0.05, 0.05, 0.025} * 2.0,
{0.3f, 0.3f, 0.3f, 1.0f}, {0.3f, 0.3f, 0.3f, 1.0f},
combos.begin()++, combos.end()); combos.begin()++, combos.end()),
Slice<4>::build(
group,
(vec5) {0.5, 0.05, 0.05, 0.05, 0.2} * 1.2,
{0.3f, 0.3f, 0.3f, 1.0f},
last.begin(), last.end()),
};
auto ubo = cgl::Buffer<Matrices>(); auto ubo = cgl::Buffer<Matrices>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
@@ -188,13 +196,11 @@ void run(GLFWwindow *window) {
glLineWidth(1.5); glLineWidth(1.5);
slice_pipe.bound([&]() { slice_pipe.bound([&]() {
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, white.vbo); for (const auto &slice : slices) {
glProgramUniform4fv(sh.solid, 2, 1, &white.color.front()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, slice.vbo);
white.draw(); glProgramUniform4fv(sh.solid, 2, 1, &slice.color.front());
slice.draw();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, black.vbo); }
glProgramUniform4fv(sh.solid, 2, 1, &black.color.front());
black.draw();
}); });
glfwSwapInterval(2); glfwSwapInterval(2);