PDA

View Full Version : Picking using unique color IDs



m.gbt
01-16-2012, 02:24 PM
Hi everybody, I'm posting here as my last resource after exhausting days studying without success on this problem.

I have an application currently working which generates cones according to the mouse click, i.e. the total number of objects depends on the user entry, it's not predefined. Also, their colors are attributed randomly, because since they always appear side by side with each other, they can't be of similar colors otherwise the user won't notice the difference among the objects.

So, I followed many guides about picking using unique color IDs, mainly these two:
http://content.gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs
http://www.lighthouse3d.com/opengl/picking/index.php3?color1

But I neither have the objects in a list (and I don't know how to do it in my case), nor do I know their colors (random).

Any tips?
Thanks a lot! :)


void WhiteSpace::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
[...]
point->x = event->x();
point->y = event->y();
point->r = qrand()%256;
point->g = qrand()%256;
point->b = qrand()%256;
[...]
}
}

void WhiteSpace::paintGL()
{
[...]
glPushMatrix();
glColor3ub(point->r, point->g, point->b);
glTranslatef(point->x, point->y, 0.0);
[...]
qobj = gluNewQuadric();
gluQuadricNormals(qobj, GLU_SMOOTH);
glNewList(list, GL_COMPILE_AND_EXECUTE);
gluCylinder(qobj, 1024, 0.0, 1.0, precision, 1);
glEndList();
glDepthFunc(GL_LEQUAL);
glPopMatrix();
[...]
}

Kopelrativ
01-17-2012, 04:12 AM
If you are using colour picking, then you have to change your draw function so as to draw every unique object with a different colour. You do this in the back buffer, so it isn't shown to the user. This colour is only used for the picking, and temporarily replaces your random colour.

You need to define an algorithm that can translate from an object to a colour, and back.

I don't understand why it would be a problem to put the objects in a list, please explain more.