81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include "glm/glm.hpp"
|
|
#include "Attributes.hpp"
|
|
#include "math.hpp"
|
|
#include "extension.hpp"
|
|
|
|
class Curve
|
|
{
|
|
|
|
public:
|
|
|
|
float aspect;
|
|
std::vector<glm::vec3> unwrapped;
|
|
std::vector<sb::Attributes> position;
|
|
sb::Attributes color;
|
|
|
|
Curve (float aspect) : aspect(aspect) {}
|
|
|
|
/*!
|
|
* Add a vector of vertices to the curve. The vertices do not have to be wrapped to the screen space.
|
|
*
|
|
* The vertices will be stored both as the original vertices passed and as sb::Attributes wrapped to screen space if necessary.
|
|
*
|
|
* @vertices vector of vertices to add to curve
|
|
*/
|
|
void add(const std::vector<glm::vec3>& vertices);
|
|
|
|
/*!
|
|
* @return number of vertices in the unwrapped curve
|
|
*/
|
|
int length() const;
|
|
|
|
/*!
|
|
* @return the first point of the unwrapped curve
|
|
*/
|
|
const glm::vec3& front() const;
|
|
|
|
/*!
|
|
* @return size in bytes of the GL vertex data
|
|
*/
|
|
std::size_t size() const;
|
|
|
|
/*!
|
|
* @param index index of the vertex in the unwrapped curve vertices list
|
|
* @return vertex in the unwrapped vertices list at index
|
|
*/
|
|
glm::vec3 operator[](int index) const;
|
|
|
|
/*!
|
|
* Get the index of the curve at the relative position, where 0 is the beginning of the curve, and 1 is the end. The position can
|
|
* be outside of the range 0 - 1, in which case it will be wrapped to between 0 and 1.
|
|
*
|
|
* The returned index can be used with Curve::operator[](int) to get the vertex at the relative position.
|
|
*
|
|
* @param relative position between 0 and 1 relative to the ends of the curve
|
|
* @return curve index at position
|
|
*/
|
|
int index(float relative) const;
|
|
|
|
/*!
|
|
* Get the vertex at the given relative position on the curve, where 0 is the beginning of the curve, and 1 is the end. The position
|
|
* can be outside of the range 0 - 1, in which case it will be wrapped to between 0 and 1.
|
|
*
|
|
* This is a shortcut to using Curve::index(float) with Curve::operator[](int)
|
|
*
|
|
* @param relative position between 0 and 1 relative to the ends of the curve
|
|
* @return vertex value at position
|
|
*/
|
|
glm::vec3 relative(float relative) const;
|
|
|
|
/*!
|
|
* Wrap a vertex into this curve's space. The vertex doesn't need to be along the curve.
|
|
*
|
|
* @param vertex vertex in world space to wrap into the curve's world space
|
|
* @return wrapped vertex
|
|
*/
|
|
glm::vec3 wrap(const glm::vec3& vertex) const;
|
|
};
|