Skip to content
Snippets Groups Projects
Commit 7ae0b7c5 authored by PIETRI Mathieu's avatar PIETRI Mathieu
Browse files

version rendue

parent 021eaa09
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,8 @@ vector<ColoredPoint> CarreauDeBezier::discretise(float pas) { ...@@ -22,8 +22,8 @@ vector<ColoredPoint> CarreauDeBezier::discretise(float pas) {
vector<ColoredPoint> points; vector<ColoredPoint> points;
for (float i = 0; i <= 1 + pas; i+= pas) { for (float i = 0; i <= 1 + pas; i+= pas) {
for (float j = 0; j <= 1 + pas; j+= pas) { for (float j = 0; j <= 1 + pas; j+= pas) {
points.push_back(ColoredPoint(getValue(i, j), color));
qDebug() << "discrétisation carreau étape :" << i << ";" << j; qDebug() << "discrétisation carreau étape :" << i << ";" << j;
points.push_back(ColoredPoint(getValue(i, j), color));
} }
} }
return points; return points;
...@@ -40,18 +40,14 @@ Point CarreauDeBezier::getValue(float u, float v) { ...@@ -40,18 +40,14 @@ Point CarreauDeBezier::getValue(float u, float v) {
for (int j = 0; j < m; j++) { for (int j = 0; j < m; j++) {
auto bernst1 = bernstein(u, i, n-1); auto bernst1 = bernstein(u, i, n-1);
auto bernst2 = bernstein(v, j, m-1); auto bernst2 = bernstein(v, j, m-1);
//qDebug() << "bernstein 1 (" << u << ", "<< i << ", " << n << ") : " << bernst1;
//qDebug() << "bernstein 2 (" << v << ", "<< j << ", " << m << ") : " << bernst2;
x += bernst1 * bernst2 * points[i][j].getX(); x += bernst1 * bernst2 * points[i][j].getX();
y += bernst1 * bernst2 * points[i][j].getY(); y += bernst1 * bernst2 * points[i][j].getY();
z += bernst1 * bernst2 * points[i][j].getZ(); z += bernst1 * bernst2 * points[i][j].getZ();
qDebug() << i*3+j;
} }
} }
//qDebug() << "#";
Point p = Point(); Point p = Point();
p.setX(x), p.setY(y), p.setZ(z); p.setX(x), p.setY(y), p.setZ(z);
qDebug() << p.getX() << p.getY() << p.getZ(); qDebug() << "getValue(" << u << ", " << v << ") : [" << p.getX() << ";" << p.getY() << ";" << p.getZ() << "]";
return p; return p;
} }
......
...@@ -17,10 +17,25 @@ static const QString fragmentShaderFile = ":/basic.fsh"; ...@@ -17,10 +17,25 @@ static const QString fragmentShaderFile = ":/basic.fsh";
myOpenGLWidget::myOpenGLWidget(QWidget *parent) : myOpenGLWidget::myOpenGLWidget(QWidget *parent) :
QOpenGLWidget(parent), QOpenGLWidget(parent),
/*
*********************** Paramètres modifiables : ****************************
*/
MAIN_INDEX(4), // index de la forme affichée : {1 : le segment A-B de base | 2 : deux segments | 3 : une courbe de bézier | 4 : un carreau de bézier}
pas(0.02), // pas de la discrétisation du carreau de bézier et de la courbe si discrétisée de façon homogène
simple_discr(false),// la courbe de bézier sera discrétisée de façon homogène si vrai, et avec l'algorithme par avancée de front sinon.
axis(true), // affiche les axes ox oy et oz si vrai (désactivé forcément pour le carreau de bézier et le segment 1)
/*
*****************************************************************************
*/
vbo_filler(m_vbo), vbo_filler(m_vbo),
points_de_controle(), points_de_controle(),
carreau() carreau()
{ {
qDebug() << "init myOpenGLWidget" ; qDebug() << "init myOpenGLWidget" ;
QSurfaceFormat sf; QSurfaceFormat sf;
...@@ -59,6 +74,7 @@ void myOpenGLWidget::initializeGL() ...@@ -59,6 +74,7 @@ void myOpenGLWidget::initializeGL()
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
makeGLObjects_4(); makeGLObjects_4();
makeGLObjects_N(MAIN_INDEX);
//shaders //shaders
m_program = new QOpenGLShaderProgram(this); m_program = new QOpenGLShaderProgram(this);
...@@ -93,9 +109,8 @@ void myOpenGLWidget::drawPoints(vector<Point> points, Color color) { ...@@ -93,9 +109,8 @@ void myOpenGLWidget::drawPoints(vector<Point> points, Color color) {
coloredPoints.push_back(ColoredPoint(p, color)); coloredPoints.push_back(ColoredPoint(p, color));
} }
vbo_filler.makeObjects(coloredPoints); vbo_filler.makeObjects(coloredPoints, false);
//destruction des éléments de la phase 2
coloredPoints.erase(coloredPoints.begin(), coloredPoints.end()); coloredPoints.erase(coloredPoints.begin(), coloredPoints.end());
} }
...@@ -103,8 +118,15 @@ void myOpenGLWidget::drawBezierCurve(vector<Point> points, Color color = Color(1 ...@@ -103,8 +118,15 @@ void myOpenGLWidget::drawBezierCurve(vector<Point> points, Color color = Color(1
auto bez = CourbeBezier(points, color); auto bez = CourbeBezier(points, color);
qDebug() << "bezier degree " << bez.degree(); qDebug() << "bezier degree " << bez.degree();
vector<ColoredPoint> coloredPoints;
//2 Traduction en tableaux de floats //2 Traduction en tableaux de floats
auto coloredPoints = bez.discretise(delta, seuilBas, seuilHaut); if (simple_discr) {
coloredPoints = bez.simple_discretise(pas);
}
else {
coloredPoints = bez.discretise(delta, seuilBas, seuilHaut);
}
//auto coloredPoints = bez.simple_discretise(0.1); //auto coloredPoints = bez.simple_discretise(0.1);
//3 spécialisation OpenGL //3 spécialisation OpenGL
...@@ -137,13 +159,13 @@ void myOpenGLWidget::drawCarreau(vector<vector<Point>> controlePoints, Color col ...@@ -137,13 +159,13 @@ void myOpenGLWidget::drawCarreau(vector<vector<Point>> controlePoints, Color col
auto points = cdb.discretise(pas); auto points = cdb.discretise(pas);
vbo_filler.makeObjects(points); vbo_filler.makeObjects(points, false);
//destruction des éléments de la phase 2 //destruction des éléments de la phase 2
points.erase(points.begin(), points.end()); points.erase(points.begin(), points.end());
} }
void myOpenGLWidget::makeAxis() { void myOpenGLWidget::drawAxis() {
Point O, X, Y, Z; Point O, X, Y, Z;
float * coord = new float[3]; float * coord = new float[3];
...@@ -176,6 +198,26 @@ void myOpenGLWidget::makeAxis() { ...@@ -176,6 +198,26 @@ void myOpenGLWidget::makeAxis() {
} }
void myOpenGLWidget::makeGLObjects_N(int i) {
switch (i) {
case 1:
makeGLObjects_1();
break;
case 2:
makeGLObjects_2();
break;
case 3:
makeGLObjects_3();
break;
case 4:
makeGLObjects_4();
break;
default:
makeGLObjects_4();
break;
}
}
void myOpenGLWidget::makeGLObjects_4() { void myOpenGLWidget::makeGLObjects_4() {
tearGLObjects(); tearGLObjects();
points_de_controle.erase(points_de_controle.begin(), points_de_controle.end()); points_de_controle.erase(points_de_controle.begin(), points_de_controle.end());
...@@ -264,7 +306,8 @@ void myOpenGLWidget::makeGLObjects_4() { ...@@ -264,7 +306,8 @@ void myOpenGLWidget::makeGLObjects_4() {
drawCarreau(points, Color(0.9, 0.8, 0.3), pas); drawCarreau(points, Color(0.9, 0.8, 0.3), pas);
delete [] coord; delete [] coord;
//makeAxis(); if(axis)
;//drawAxis();
drawPoints(points_de_controle, Color(1, 0, 0)); drawPoints(points_de_controle, Color(1, 0, 0));
...@@ -316,7 +359,8 @@ void myOpenGLWidget::makeGLObjects_3() { ...@@ -316,7 +359,8 @@ void myOpenGLWidget::makeGLObjects_3() {
drawBezierCurve(points, Color(0.7, 0.9, 0.5)); drawBezierCurve(points, Color(0.7, 0.9, 0.5));
delete [] coord; delete [] coord;
//makeAxis(); if (axis)
drawAxis();
m_vbo.create(); m_vbo.create();
m_vbo.bind(); m_vbo.bind();
...@@ -332,12 +376,12 @@ void myOpenGLWidget::makeGLObjects_2() { ...@@ -332,12 +376,12 @@ void myOpenGLWidget::makeGLObjects_2() {
float * coord = new float[3]; float * coord = new float[3];
coord[0] = 1.0f; coord[0] = 1.0f;
coord[1] = 0.0f; coord[1] = 1.0f;
coord[2] = -1.0f; coord[2] = -1.0f;
A.set (coord); A.set (coord);
coord[0] = 1.0f; coord[0] = 1.0f;
coord[1] = 0.0f; coord[1] = 1.0f;
coord[2] = 1.0f; coord[2] = 1.0f;
B.set(coord); B.set(coord);
...@@ -362,7 +406,8 @@ void myOpenGLWidget::makeGLObjects_2() { ...@@ -362,7 +406,8 @@ void myOpenGLWidget::makeGLObjects_2() {
points_de_controle.push_back(A), points_de_controle.push_back(B); points_de_controle.push_back(A), points_de_controle.push_back(B);
delete [] coord; delete [] coord;
makeAxis(); if (axis)
drawAxis();
m_vbo.create(); m_vbo.create();
m_vbo.bind(); m_vbo.bind();
...@@ -370,7 +415,7 @@ void myOpenGLWidget::makeGLObjects_2() { ...@@ -370,7 +415,7 @@ void myOpenGLWidget::makeGLObjects_2() {
} }
void myOpenGLWidget::makeGLObjects() void myOpenGLWidget::makeGLObjects_1()
{ {
tearGLObjects(); tearGLObjects();
points_de_controle.erase(points_de_controle.begin(), points_de_controle.end()); points_de_controle.erase(points_de_controle.begin(), points_de_controle.end());
...@@ -380,12 +425,12 @@ void myOpenGLWidget::makeGLObjects() ...@@ -380,12 +425,12 @@ void myOpenGLWidget::makeGLObjects()
float * coord = new float[3]; float * coord = new float[3];
coord[0] = 0.0f; coord[0] = 0.0f;
coord[1] = 0.0f; coord[1] = 1.0f;
coord[2] = 0.0f; coord[2] = 0.0f;
A.set (coord); A.set (coord);
coord[0] = 1.0f; coord[0] = 1.0f;
coord[1] = 0.0f; coord[1] = -1.0f;
coord[2] = 0.0f; coord[2] = 0.0f;
B.set(coord); B.set(coord);
...@@ -458,8 +503,12 @@ void myOpenGLWidget::makeGLObjects() ...@@ -458,8 +503,12 @@ void myOpenGLWidget::makeGLObjects()
void myOpenGLWidget::tearGLObjects() void myOpenGLWidget::tearGLObjects()
{ {
vbo_filler.resetData();
m_vbo.destroy(); m_vbo.destroy();
glBindBuffer(GL_ARRAY_BUFFER, 0); //glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint buff = m_vbo.bufferId();
glDeleteBuffers(1 , &buff);
glGenBuffers(1 , &buff);
} }
...@@ -519,8 +568,14 @@ void myOpenGLWidget::paintGL() ...@@ -519,8 +568,14 @@ void myOpenGLWidget::paintGL()
m_program->enableAttributeArray("colAttr"); m_program->enableAttributeArray("colAttr");
glPointSize (5.0f); glPointSize (5.0f);
if (MAIN_INDEX == 1 || MAIN_INDEX == 2 || MAIN_INDEX == 3) {
glDrawArrays(GL_LINES, 0, 1000);
glDrawArrays(GL_POINTS, 0, 1000);
}
else {
glDrawArrays(GL_POINTS, 0, 100000); glDrawArrays(GL_POINTS, 0, 100000);
//glDrawArrays(GL_LINES, 0, 1000); }
m_program->disableAttributeArray("posAttr"); m_program->disableAttributeArray("posAttr");
m_program->disableAttributeArray("colAttr"); m_program->disableAttributeArray("colAttr");
......
...@@ -28,8 +28,10 @@ public: ...@@ -28,8 +28,10 @@ public:
void drawBezierCurve(vector<Point>, Color, float delta, float seuilBas, float seuilHaut); void drawBezierCurve(vector<Point>, Color, float delta, float seuilBas, float seuilHaut);
void drawSegment(Point a, Point b, Color, float pas); void drawSegment(Point a, Point b, Color, float pas);
void drawCarreau(vector<vector<Point>> controlePoints, Color color, float pas); void drawCarreau(vector<vector<Point>> controlePoints, Color color, float pas);
void makeAxis(); void drawAxis();
void makeGLObjects();
void makeGLObjects_N(int i);
void makeGLObjects_1();
void makeGLObjects_2(); void makeGLObjects_2();
void makeGLObjects_3(); void makeGLObjects_3();
void makeGLObjects_4(); void makeGLObjects_4();
...@@ -37,7 +39,7 @@ public: ...@@ -37,7 +39,7 @@ public:
CarreauDeBezier * getCarreau(); CarreauDeBezier * getCarreau();
void setPas(float pas); void setPas(float pas);
public slots: public:
signals: // On ne les implémente pas, elles seront générées par MOC ; signals: // On ne les implémente pas, elles seront générées par MOC ;
// les paramètres seront passés aux slots connectés. // les paramètres seront passés aux slots connectés.
...@@ -58,6 +60,11 @@ protected: ...@@ -58,6 +60,11 @@ protected:
private: private:
int MAIN_INDEX;
float pas;
bool simple_discr;
bool axis;
VBO_Filler vbo_filler; VBO_Filler vbo_filler;
double m_angle = 0; double m_angle = 0;
QTimer *m_timer = nullptr; QTimer *m_timer = nullptr;
...@@ -65,7 +72,6 @@ private: ...@@ -65,7 +72,6 @@ private:
vector<Point> points_de_controle; vector<Point> points_de_controle;
CarreauDeBezier carreau; CarreauDeBezier carreau;
float pas = 0.1;
//RR matrices utiles //RR matrices utiles
QMatrix4x4 m_modelView; QMatrix4x4 m_modelView;
......
...@@ -24,7 +24,7 @@ void VBO_Filler::makePoint(ColoredPoint point) { ...@@ -24,7 +24,7 @@ void VBO_Filler::makePoint(ColoredPoint point) {
void VBO_Filler::makeObjects(vector<ColoredPoint> & points) { void VBO_Filler::makeObjects(vector<ColoredPoint> & points, bool drawLines) {
bool b = false; bool b = false;
...@@ -44,7 +44,7 @@ void VBO_Filler::makeObjects(vector<ColoredPoint> & points) { ...@@ -44,7 +44,7 @@ void VBO_Filler::makeObjects(vector<ColoredPoint> & points) {
// vertData.append((float)i/500); // vertData.append((float)i/500);
// vertData.append((float)i/500); // vertData.append((float)i/500);
// vertData.append(0); // vertData.append(0);
if (drawLines) {
if (i > 0 && i < points.size() - 1 && !b) { if (i > 0 && i < points.size() - 1 && !b) {
b = true; b = true;
i--; i--;
...@@ -53,6 +53,7 @@ void VBO_Filler::makeObjects(vector<ColoredPoint> & points) { ...@@ -53,6 +53,7 @@ void VBO_Filler::makeObjects(vector<ColoredPoint> & points) {
b = false; b = false;
} }
} }
}
qDebug() << "vertData size :" << vertData.count(); qDebug() << "vertData size :" << vertData.count();
} }
......
...@@ -22,7 +22,7 @@ class VBO_Filler ...@@ -22,7 +22,7 @@ class VBO_Filler
public: public:
VBO_Filler(QOpenGLBuffer &); VBO_Filler(QOpenGLBuffer &);
void makePoint(ColoredPoint); void makePoint(ColoredPoint);
void makeObjects(vector<ColoredPoint> &); void makeObjects(vector<ColoredPoint> &, bool drawlines = true);
const QVector<GLfloat> & getVertData(); const QVector<GLfloat> & getVertData();
void resetData(); void resetData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment