Bug floraison

This commit is contained in:
ao 2018-10-08 23:53:06 +02:00
parent 89a19a6ab6
commit 060aaeb0bf
4 changed files with 69 additions and 16 deletions

View File

@ -11,12 +11,12 @@ BSpline::BSpline(int k, double step, int np1)
for(int i = 0; i < k+np1; ++i) for(int i = 0; i < k+np1; ++i)
_vecteurNodal.push_back(i); _vecteurNodal.push_back(i);
// Points de contrôle // Points de contrôle
_pointsDeControle.push_back(glm::vec3(-3, 0, 0)); _pointsDeControle.push_back(glm::vec3(-2, 0, -5));
_pointsDeControle.push_back(glm::vec3(-1, 0, 0)); _pointsDeControle.push_back(glm::vec3(-1, 0, -5));
_pointsDeControle.push_back(glm::vec3(-1, 0, 2)); _pointsDeControle.push_back(glm::vec3(-1, 1, -5));
_pointsDeControle.push_back(glm::vec3( 1, 0, 2)); _pointsDeControle.push_back(glm::vec3( 1, 1, -5));
_pointsDeControle.push_back(glm::vec3( 1, 0, 0)); _pointsDeControle.push_back(glm::vec3( 1, 0, -5));
_pointsDeControle.push_back(glm::vec3( 3, 0, 0)); _pointsDeControle.push_back(glm::vec3( 2, 0, -5));
computeSpline(); computeSpline();
} }
@ -30,21 +30,68 @@ void BSpline::computeSpline()
std::vector<glm::vec3> vecteursPointsControle (_np1); std::vector<glm::vec3> vecteursPointsControle (_np1);
for(u = _k - 1; u < _np1; u += _step){ for(u = _k - 1; u < _np1; u += _step){
// Réinitialiser dec et i ?
while(u > _vecteurNodal[i]){ while(u > _vecteurNodal[i]){
++dec; ++dec;
++i; ++i;
} }
// int i à virer ?
for(int i = 0; i < _k; i++){ for(int i = 0; i < _k; i++){
vecteursPointsControle[i] = _pointsDeControle[dec + i]; vecteursPointsControle[i] = _pointsDeControle[dec + i];
} }
std::vector<GLfloat> newVertices = floraison(u, dec, _k); glm::vec3 newVertex = floraison(u, dec, _k, vecteursPointsControle);
_vertices.insert(_vertices.end(), newVertices.begin(), newVertices.end()); //std::cout << newVertex.x << " " << newVertex.y << " " << newVertex.z << std::endl;
_vertices.push_back(newVertex);
} }
} }
std::vector<GLfloat> BSpline::floraison(double u, int dec, int k) glm::vec3 BSpline::floraison(float u, int dec, int k, std::vector<glm::vec3> vecteursPointsControle)
{ {
return std::vector<GLfloat>({0.0f, 0.0f, 0.0f}); if(k == 0)
return vecteursPointsControle.front();
for(int i = 0; i < k - 1; ++i)
vecteursPointsControle[i] =
(((_vecteurNodal[dec + k + i] - u) / (_vecteurNodal[dec + k + i] - _vecteurNodal[dec + 1 + i])) * vecteursPointsControle[i]) *
(((u - _vecteurNodal[dec + 1 + i]) / (_vecteurNodal[dec + k + i] - _vecteurNodal[dec + 1 + i])) * vecteursPointsControle[i+1]);
floraison(u, dec+1, k-1, vecteursPointsControle);
}
std::vector<GLfloat> const BSpline::getVertices()
{
std::vector<GLfloat> vertices;
// Ajout des points de contrôle
for(glm::vec3 point: _pointsDeControle)
vertices.insert(vertices.end(), {point.x, point.y, point.z});
// Ajout des points issus de la floraison
for(glm::vec3 point: _vertices)
vertices.insert(vertices.end(), {point.x, point.y, point.z});
return vertices;
}
std::vector<GLfloat> const BSpline::getNormals()
{
std::vector<GLfloat> normals;
for(glm::vec3 point: _pointsDeControle)
normals.insert(normals.end(), {point.x, point.y, point.z});
// Ajout des normales des points issus de la floraison
for(glm::vec3 point: _vertices)
normals.insert(normals.end(), {point.x, point.y, point.z});
return normals;
}
std::vector<GLuint> const BSpline::getIndices()
{
std::vector<GLuint> indices;
for(uint i = 0; i < _pointsDeControle.size() - 1; ++i)
indices.insert(indices.end(), {i, i, i+1});
// Ajout des indices pour les points issus de la floraison
for(uint i = 0; i < _vertices.size() - 1; ++i)
indices.insert(indices.end(), {i, i, i+1});
return indices;
} }

View File

@ -9,18 +9,20 @@ class BSpline
{ {
public: public:
BSpline(int k = 2, double step = 0.1, int np1 = 6); BSpline(int k = 2, double step = 0.1, int np1 = 6);
std::vector<GLfloat> const getVertices();
std::vector<GLfloat> const getNormals();
std::vector<GLuint> const getIndices();
private: private:
std::vector<double> _vecteurNodal; std::vector<float> _vecteurNodal;
std::vector<glm::vec3> _pointsDeControle; std::vector<glm::vec3> _pointsDeControle;
int _k; int _k;
int _np1; int _np1;
double _step; double _step;
std::vector<GLfloat> _vertices; std::vector<glm::vec3> _vertices;
void computeSpline(); void computeSpline();
std::vector<GLfloat> floraison(double u, int dec, int k); glm::vec3 floraison(float u, int dec, int k, std::vector<glm::vec3> vecteursPointsControle);
}; };
#endif // BSPLINE_H #endif // BSPLINE_H

View File

@ -13,8 +13,8 @@ SimpleSphere::SimpleSphere(int width, int height, MainWindow* w) : Scene(width,
// Compute the shape to draw -> Menu ? // Compute the shape to draw -> Menu ?
//drawCube(0.1f); //drawCube(0.1f);
drawUVSphere(50, _radius); //drawUVSphere(50, _radius);
//drawIcoSphere(5, _radius); drawIcoSphere(6, _radius);
std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl; std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl;
std::cout << "Edges count: " << _indices.size() << std::endl; std::cout << "Edges count: " << _indices.size() << std::endl;

View File

@ -11,6 +11,10 @@ SimpleSpline::SimpleSpline(int width, int height, MainWindow* w) : Scene(width,
_lastFragment = _w->fragmentShader; _lastFragment = _w->fragmentShader;
// LOAD B-SPLINE // LOAD B-SPLINE
BSpline bspline1D = BSpline();
_vertices = bspline1D.getVertices();
_indices = bspline1D.getIndices();
_normals = bspline1D.getNormals();
std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl; std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl;
std::cout << "Edges count: " << _indices.size() << std::endl; std::cout << "Edges count: " << _indices.size() << std::endl;