void drawBezier(p2d* bezierpoints, unsigned int num, int smooth) { int i; p2d tmpp; glBegin(GL_LINE_STRIP); for(i=0;i<=smooth;i++) { tmpp = bezierInterpolation(bezierpoints, num, ((float)i)/smooth); glVertex3f(tmpp[0], tmpp[1], 0); releasp2d(tmpp); } glEnd(); }
void Spline::update() { if (m_vertices.size() == 0) { m_sfmlVertices.clear(); m_handlesVertices.clear(); return; } const unsigned int pointsPerVertex{ m_interpolationSteps + 1u }; m_sfmlVertices.resize(((m_vertices.size() - 1) * pointsPerVertex) + 1); m_handlesVertices.resize((m_vertices.size()) * 4); std::vector<sf::Vertex>::iterator itHandle = m_handlesVertices.begin(); for (std::vector<Vertex>::iterator begin = m_vertices.begin(), end = m_vertices.end(), it = begin; it != end; ++it) { itHandle->color = sf::Color(255, 255, 128, 32); itHandle++->position = it->position; itHandle->color = sf::Color(0, 255, 0, 128); itHandle++->position = it->position + it->backHandle; itHandle->color = sf::Color(255, 255, 128, 32); itHandle++->position = it->position; itHandle->color = sf::Color(0, 255, 0, 128); itHandle++->position = it->position + it->frontHandle; std::vector<sf::Vertex>::iterator itSfml = m_sfmlVertices.begin() + (it - begin) * pointsPerVertex; if (it != end - 1) { for (unsigned int i{ 0u }; i < pointsPerVertex; ++i) { if (m_useBezier) itSfml->position = bezierInterpolation(it->position, (it + 1)->position, it->frontHandle, (it + 1)->backHandle, static_cast<float>(i) / pointsPerVertex); else itSfml->position = linearInterpolation(it->position, (it + 1)->position, static_cast<float>(i) / pointsPerVertex); itSfml->color = m_color; ++itSfml; } } else { itSfml->position = it->position; itSfml->color = m_color; } } }