2023-06-19 22:59:11 -04:00
|
|
|
#include "Curve.hpp"
|
|
|
|
|
2023-06-22 14:40:06 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-19 22:59:11 -04:00
|
|
|
int Curve::length() const
|
|
|
|
{
|
|
|
|
return unwrapped.size();
|
|
|
|
}
|
|
|
|
|
2023-06-22 14:40:06 -04:00
|
|
|
const glm::vec3& Curve::front() const
|
2023-06-19 22:59:11 -04:00
|
|
|
{
|
|
|
|
return unwrapped.front();
|
|
|
|
}
|
|
|
|
|
2023-06-22 14:40:06 -04:00
|
|
|
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
|
2023-06-19 22:59:11 -04:00
|
|
|
{
|
|
|
|
return unwrapped[index];
|
|
|
|
}
|
2023-06-22 14:40:06 -04:00
|
|
|
|
|
|
|
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});
|
|
|
|
}
|