cakefoot/src/Curve.cpp

56 lines
1.2 KiB
C++

#include "Curve.hpp"
void Curve::add(const std::vector<glm::vec3>& vertices)
{
sb::extend(unwrapped, vertices);
for (const std::vector<glm::vec3>& wrapped : sb::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(1.0f, 1.0f, 1.0f, 1.0f);
}
}
}
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::wrap_point(vertex, {-aspect, -1.0f, 0.0f}, {aspect, 1.0f, 1.0f});
}