1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| void GLWidget::Picking()
{
rectangleSelection = rectangleSelection.normalized();
QPoint Coin1 = GetCoordonneesEcran(rectangleSelection.topLeft());
QPoint Coin2 = GetCoordonneesEcran(rectangleSelection.bottomRight());
QPoint Centre = GetCoordonneesEcran(rectangleSelection.center());
int x=Centre.x();
int y=Centre.y();
int l_width = MAX(2,abs((Coin1-Coin2).x()));
int l_height = MAX(2,abs((Coin1-Coin2).y()));
//Creation du Buffer
const GLint BUFFERSIZE = 4194288;
GLuint * BUFFER = new GLuint[BUFFERSIZE];
// on spécifi la zone mémoire pour le retour d'information de selection
glSelectBuffer (BUFFERSIZE, BUFFER);
// Entrer en mode Selection
glRenderMode (GL_SELECT);
// Initialisation de la pile de nom
glInitNames();
glPushName(0);
{
glPushMatrix ();
{
//on recupert le viewport
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
gluPickMatrix((GLdouble)x,(GLdouble)(viewport[3]-y),(GLdouble)l_width/2, (GLdouble)l_height/2,viewport);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// On applique les transformation
gluPerspective(20.0f, (GLdouble)width()/(GLdouble)height(), 0.000001, 10000000);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// Caméra
gluLookAt(PositionCamera.x(), PositionCamera.y(), PositionCamera.z(), CibleCamera.x(), CibleCamera.y(), CibleCamera.z(), 0, 1,0);
//On redessine la scene en mode picking
QMap <unsigned int, CAO_ItemClone*> ListePick;
glPushMatrix();
{
liste->PickingItem(ListePick);
}glPopMatrix ();
glFlush();
//On repasse en mode RENDER *
//et on recupère le nombre d'élement séléctionner
int hits = glRenderMode(GL_RENDER);
int sizeList = ListePick.size();
QVector <CAO_ItemClone*> listeASelectionner;
listeASelectionner.clear();
GLuint names, *ptr;
ptr = (GLuint *) BUFFER;
for (unsigned int i = 0; i < hits; i++)
{
//On recupère le numbre de pick
names = *ptr;
ptr++;
//coordonnée minimum
ptr++;
//coordonnée maximum
ptr++;
//et enfin on recupère tout les pickingID
for (unsigned int j = 0; j < names; j++)
{
printf ("%d ", *ptr);
if (ListePick.find(*ptr)!= ListePick.end())
{
listeASelectionner.push_back(ListePick[*ptr]);
qDebug() << "selection ID " << QString::number(*ptr);
}
else
{
qDebug() << "On a Selectionner un pickingID non existant ! ! !" << QString::number(*ptr);
}
ptr++;
}
}
qDebug() << "taille de la liste" << QString::number(sizeList);
liste->Selection(listeASelectionner);
//on vide le buffer
for (unsigned int i =0; i <BUFFERSIZE; i++)
BUFFER = 0;
delete BUFFER;
BUFFER = NULL;
}glPopMatrix ();
}glPopName();
} |
Partager