Accueil > > > View2D.cpp
AFFICHER DES COURBES DE BEZIER
View2D.cpp
Informations sur ce code source
Bonjour à Tous suite à un Problème que je rencontre actuellement :
http://www.cppfrance.com/forum/sujet-CREER-GRAND-CARREAU-NURBS_1542679.aspx
J'ai décider d’écrire le Bout de Programme qui va bien pour m'aidé à voir ou je vais avec les Courb
Fichier : View2D.cpp
Nombre de lignes : 230 lignes
Afficher ce fichier en plein écran
- #include<QDebug>
- #include "Window.h"
- #include "View2D.h"
-
-
- #define PRECISION_BEZIER 100
-
-
- View2D::View2D(QWidget *parent) :
- QGLWidget(parent), m_Win((Window*)parent)
- {
- qDebug() << "Appel au Constructeur" << endl;
- setMinimumSize(300,300);
-
- makeCurrent();
- m_XMax = 35.0;
- m_XMin = -10.0;
- m_YMax = 10.0;
- m_YMin = -10.0;
-
- m_Step_x = m_Step_y = 5;
- }
- void View2D::resizeGL (int width, int height)
- {
-
-
-
- qDebug() << "Appel au ResizeGL()" << endl;
-
- glViewport (0, 0, width, height);
-
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glOrtho(m_XMin-1, m_XMax+1, m_YMin-1, m_YMax+1, 10, 15);
-
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ();
- }
-
-
- void View2D::initializeGL(void)
- {
- qDebug() << "Appel au initializeGL()" << endl;
- glClearColor(0.8,0.8,0.85,0);
- glEnable(GL_DEPTH_TEST);
-
- }
-
- void View2D::Init(void)
- {
- qDebug() << "Appel au Init()" << endl;
-
- glClearColor(0.4,0.4,0.4,0);
-
-
-
- }
- void View2D::paintGL(void)
- {
- qDebug() << "Appel au paintGL()" << endl;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(0, 0, -11);
- DessinAxe();
- DessinPoints();
- Dessin();
- glPopMatrix();
- }
-
-
- void View2D::Dessin(void)
- {
-
-
-
-
- }
-
- void View2D::DessinPoints(void)
- {
-
-
- glEnable(GL_POINT_SIZE);
- glEnable(GL_POINT_SMOOTH);
- glPointSize(9);
-
-
-
- for(int Courbe=0; Courbe<m_Win->m_ListeCourbe.size(); ++Courbe)
- {
- Window::GestionCourbe* Crb = &(m_Win->m_ListeCourbe[Courbe]);
- for(int Pt=0; Pt<Crb->size(); ++Pt)
- {
- switch(Courbe)
- {
- case 1:
- glColor4f(1.0, 0.0, 0.0, 1.0);
- break;
- case 2:
- glColor4f(0.0, 1.0, 0.0, 1.0);
- break;
- case 3:
- glColor4f(0.0, 0.0, 1.0, 1.0);
- break;
- case 4:
- glColor4f(1.0, 1.0, 0.0, 1.0);
- break;
- case 5:
- glColor4f(1.0, 0.0, 1.0, 1.0);
- break;
- case 6:
- glColor4f(0.0, 1.0, 1.0, 1.0);
- break;
-
- default:
- glColor4f(0.0, 0.0, 0.0, 1.0);
- break;
- };
-
- glPushMatrix();
- glBegin(GL_POINTS);
- glVertex3f(Crb->at(Pt).m_x, Crb->at(Pt).m_y, 0);
- glEnd();
- glPopMatrix();
-
-
- glLineWidth(3);
- InitCourbe(Courbe);
- glMapGrid1f(PRECISION_BEZIER, 0.0, 1.0);
- glEvalMesh1(GL_LINE, 0, PRECISION_BEZIER);
- }
- }
-
-
- for(int Courbe=0; Courbe<m_Win->m_ListeCourbe.size(); ++Courbe)
- {
-
- }
-
-
- }
-
-
- void View2D::DessinAxe(void)
- {
-
- glEnable(GL_LINE_WIDTH);
- glLineWidth(5);
- // Dessinde l'Axe Principal ...
- glPushMatrix();
- glBegin(GL_LINES);
- glColor4f(0.0, 0.0, 0.0, 1.0);
- glVertex3f(m_XMin, 0, 0);
- glVertex3f(m_XMax, 0, 0);
- glEnd();
-
-
- glBegin(GL_LINES);
- glVertex3f(0, m_YMin, 0);
- glVertex3f(0, m_YMax, 0);
- glEnd();
- glPopMatrix();
-
-
- glLineWidth(1);
-
- // Dessinde l'Axe Secondaire ...
-
- for(int loop=m_XMin; loop<=(m_XMax-m_XMin);++loop)
- {
- if(loop % m_Step_x)
- {
- glColor4f(0.9, 0.9, 0.9, 1.0);
- }
- else
- {
- glColor4f(0.0, 0.0, 0.0, 1.0);
-
- }
- glBegin(GL_LINES);
- glVertex3f(m_XMin + loop, m_YMin, 0);
- glVertex3f(m_XMin + loop, m_YMax, 0);
- glEnd();
- }
- for(int loop=m_YMin; loop<=(m_YMax-m_YMin);++loop)
- {
- if(loop % m_Step_y)
- {
- glColor4f(0.9, 0.9, 0.9, 1.0);
- }
- else
- {
- glColor4f(0.0, 0.0, 0.0, 1.0);
-
- }
- glBegin(GL_LINES);
- glVertex3f(m_XMin, m_YMin + loop, 0);
- glVertex3f(m_XMax, m_YMin + loop, 0);
- glEnd();
- }
-
-
- glDisable(GL_LINE_WIDTH);
- }
-
-
-
-
-
- void View2D::InitCourbe(int No)
- {
-
- GLfloat ctrlpoints[8][3];
-
- Window::GestionCourbe* Crb = &(m_Win->m_ListeCourbe[No]);
-
- for(int nPt=0; nPt< Crb->size(); ++nPt)
- {
- ctrlpoints[nPt][0] = Crb->at(nPt).m_x;
- ctrlpoints[nPt][1] = Crb->at(nPt).m_y;
- ctrlpoints[nPt][2] = 0;
- }
-
- glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, Crb->size(), &ctrlpoints[0][0]);
- glEnable(GL_MAP1_VERTEX_3);
-
-
- }
|