cakefoot/src/Curve.cpp
Cocktail Frank 5ce93a9bfa Add swivel idle animation
Add swivel idle animation which slightly rotates the play field back
and forth.

Configure bg shader uniform values to vary the bg shader parameters between levels.

Add copyright information to shaders.
2025-05-01 12:51:48 -04:00

61 lines
1.4 KiB
C++

#include "Curve.hpp"
void Curve::add(const std::vector<glm::vec3>& vertices)
{
sb::extend(unwrapped, vertices);
std::vector<float> alpha {
0.1f, 0.3f, 0.6f, 0.9f, 1.0f, 0.95f, 0.9f, 0.85f, 0.8f, 0.75f, 0.7f, 0.65f, 0.6f, 0.55f,
0.5f, 0.45f, 0.4f, 0.35f, 0.3f, 0.275f, 0.25f, 0.225f, 0.2f, 0.175f, 0.15f, 0.125f, 0.1f, 0.05f
};
for (const std::vector<glm::vec3>& wrapped :
sb::math::wrap_curve(vertices, {-aspect, -1.0f, 0.0f}, {aspect, 1.0f, 1.0f}))
{
position.push_back(sb::Attributes(wrapped));
for (std::size_t jj = 0; jj < wrapped.size(); jj++)
{
color.add(0.8f, 0.8f, 0.8f, alpha[jj % alpha.size()]);
}
}
}
int Curve::length() const
{
return unwrapped.size();
}
const glm::vec3& Curve::front() const
{
return unwrapped.front();
}
std::size_t Curve::size() const
{
std::size_t byte_count = 0;
for (const auto& attr : position)
{
byte_count += attr.size();
}
byte_count += color.size();
return byte_count;
}
glm::vec3 Curve::operator[](int index) const
{
return unwrapped[index];
}
int Curve::index(float relative) const
{
return std::round(glm::mod(relative, 1.0f) * length());
}
glm::vec3 Curve::relative(float relative) const
{
return unwrapped[index(relative)];
}
glm::vec3 Curve::wrap(const glm::vec3& vertex) const
{
return sb::math::wrap_point(vertex, {-aspect, -1.0f, 0.0f}, {aspect, 1.0f, 1.0f});
}