BSpline class

This commit is contained in:
Pierre Cholet 2018-09-12 20:30:13 +02:00
parent 9d90a00e8e
commit 08e3667ffb
2 changed files with 76 additions and 0 deletions

50
src/bspline.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "bspline.h"
BSpline::BSpline(int k, double step, int np1)
{
// Initialisation des valeurs
// Ordre k = 2
_k = k;
_step = step;
_np1 = np1;
// Vecteur Nodal Uniforme de np1 valeurs
for(int i = 0; i < k+np1; ++i)
_vecteurNodal.push_back(i);
// Points de contrôle
_pointsDeControle.push_back(glm::vec3(-3, 0, 0));
_pointsDeControle.push_back(glm::vec3(-1, 0, 0));
_pointsDeControle.push_back(glm::vec3(-1, 0, 2));
_pointsDeControle.push_back(glm::vec3( 1, 0, 2));
_pointsDeControle.push_back(glm::vec3( 1, 0, 0));
_pointsDeControle.push_back(glm::vec3( 3, 0, 0));
computeSpline();
}
void BSpline::computeSpline()
{
// Init
int dec = 0, i = _k;
double u = 0;
std::vector<glm::vec3> vecteursPointsControle (_np1);
for(u = _k - 1; u < _np1; u += _step){
while(u > _vecteurNodal[i]){
++dec;
++i;
}
for(int i = 0; i < _k; i++){
vecteursPointsControle[i] = _pointsDeControle[dec + i];
}
std::vector<GLfloat> newVertices = floraison(u, dec, _k);
_vertices.insert(_vertices.end(), newVertices.begin(), newVertices.end());
}
}
std::vector<GLfloat> BSpline::floraison(double u, int dec, int k)
{
return std::vector<GLfloat>({0.0f, 0.0f, 0.0f});
}

26
src/bspline.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef BSPLINE_H
#define BSPLINE_H
#include "opengl_stuff.h"
#include <vector>
class BSpline
{
public:
BSpline(int k = 2, double step = 0.1, int np1 = 6);
private:
std::vector<double> _vecteurNodal;
std::vector<glm::vec3> _pointsDeControle;
int _k;
int _np1;
double _step;
std::vector<GLfloat> _vertices;
void computeSpline();
std::vector<GLfloat> floraison(double u, int dec, int k);
};
#endif // BSPLINE_H