31 #ifndef __SFTOOLS_CURVE_HPP__
32 #define __SFTOOLS_CURVE_HPP__
34 #include <SFML/Graphics.hpp>
68 auto f = [a, b](
float t) -> sf::Vector2f {
69 return { a * std::cos(t), b * std::sin(t) };
85 return elipse(r, r, begin, end, pointCount);
99 auto f = [a, b](
float t) -> sf::Vector2f {
100 return { a * t, b * std::sin(t) };
117 auto f = [a, b](
float t) -> sf::Vector2f {
118 return { a * t, b * std::cos(t) };
134 auto f = [a](
float t) -> sf::Vector2f {
135 return { a * std::pow(std::cos(t), 3), a * std::pow(std::sin(t), 3) };
160 public sf::Transformable
171 : m_vertices(sf::PrimitiveType::TrianglesStrip)
174 , m_thickness(thickness)
200 return m_vertices.getBounds();
278 m_thickness = thickness;
289 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const
291 states.transform *= getTransform();
292 target.draw(m_vertices, states);
303 auto const normalisedNormal = [](sf::Vector2f
const& a, sf::Vector2f
const& b) -> sf::Vector2f
305 sf::Vector2f
const v = a - b;
306 sf::Vector2f
const n = { v.y, -v.x };
307 float const length = std::sqrt(n.x * n.x + n.y * n.y);
309 return length != 0.0 ? n / length : n;
318 for (
unsigned int i = 0; i < m_info.
pointCount; ++i) {
319 float const t = m_info.
begin + step * i;
320 m_vertices[i * 2] = { m_info.
f(t), m_color };
324 for (
unsigned int i = 1; i < m_info.
pointCount * 2 - 1; i += 2) {
326 sf::Vector2f
const& p0 = m_vertices[i - 1].position;
327 sf::Vector2f
const& p2 = m_vertices[i + 1].position;
328 sf::Vector2f
const n = normalisedNormal(p0, p2);
329 sf::Vector2f
const m = (p0 + p2) / 2.f;
330 sf::Vector2f
const p1 = m + n * m_thickness;
332 m_vertices[i] = { p1, m_color };
341 void updateColorOnly()
343 for (
unsigned int i = 0; i < m_vertices.getVertexCount(); ++i) {
344 m_vertices[i].color = m_color;
349 sf::VertexArray m_vertices;
356 #endif // __SFTOOLS_CURVE_HPP__