Jump to content
  • Advertisement
Sign in to follow this  
backspin

OpenGL Points Selection

This topic is 3835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can someone help me with selection? I am drawing a big cloud of points (over 5000) and want to select the points with mouse and highlight them (nearest single point). The example with planets from opengl books doesn't help me much, because I am not defining any names to the points and I not using SWITCH function (too much data). Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by backspin
Can someone help me with selection? I am drawing a big cloud of points (over 5000) and want to select the points with mouse and highlight them (nearest single point). The example with planets from opengl books doesn't help me much, because I am not defining any names to the points and I not using SWITCH function (too much data). Thanks
I would use a 'picking volume' for this. Using this method, you would build a list of points contained by the volume, and then select the one closest to the camera view plane.

The details kind of depend on what tools you're using. Are you using a math library of some sort? What language are you programming in?

Share this post


Link to post
Share on other sites
I am writing an application in Visual C++ 6.0 in MFC. I am not using any complicated tools or methods. I was trying to use GLUT library, but the effect was not so good. I just want to draw point (already done) and select them with mouse click.

Share this post


Link to post
Share on other sites
Ok, but what with the Names? Should I give every single point a name? I was also thinking about reading OpenGL coordinates and then after mouse click save one(x,y) and compare with the rest, but somethings wrong with my points translation and also I get huge numbers after rotating, moving or zooming.

Share this post


Link to post
Share on other sites
It seems likely that your transformation problems stem from getting confused between object space, camera space and screen space.

Between the world and the screen a vertex is subjected to a shearing (perspective) and projection transformation. It gets 'flattened' into screen x,y coordinates and given a depth value. These screen coordinates are not the same as the world coordinates, even if your screen and world axes are aligned, and the depth value is not even the same type of value as a world z value... it is more like a layer number in photoshop. The original 3D data about the vertex is discarded, which is why GL employs the technique of redrawing objects to a selection buffer and giving them names so you can tell what it is that you picked.

If you want each individual point to be selectable then you give them each a name (an integer value)... if they are all in one array then you can use the index value as the name, then when your picking result is the name '27' you know that vertex[27] was selected.

[Edited by - ElectricVoodoo on February 13, 2008 5:49:17 AM]

Share this post


Link to post
Share on other sites
thats my drawing function:

for(int i=0; i<points_limit; i++)
{
glBegin(GL_POINTS);
glLoadName(i);
glVertex3f(xpoint, ypoint, zpoint);
glEnd();

if(i<points_limit && line_link[i+1]=="" && lines_or_dots==0)
{
glBegin(GL_LINES);
glLoadName(i);
glVertex3f(xpoint, ypoint, zpoint);
glVertex3f(xpoint[i+1], ypoint[i+1], zpoint[i+1]);
glEnd();
}
}

my question is the LoadName() function correct? Then I get no errors or warnings in my code by still the hits value is zero. I know that the point are very small and it is hard to hit one but I have a big cloud of point, so I think I shoud hit something. Is there something to set the range around a point?

Share this post


Link to post
Share on other sites
Have you created a suitable buffer and passed it to GL with glSelectBuffer()?
Have you properly initialized the name stack by calling glInitNames and glPushName(0)?
Have you enabled glRenderMode(GL_SELECT)?
Have you taken into account that GL screen coordinates start from the bottom left although window coordinates start from the top left?

To increase the size of the hit region:

gluPickMatrix(mousex,
mousey,
PICK_REGION_SIZE, PICK_REGION_SIZE,
viewport);

PICK_REGION_SIZE is the size of your square hit region.

Share this post


Link to post
Share on other sites
It is much faster if each point is rendered with another color into the back buffer (16m or 2³² should be enough) After that read the pixel below the mouse with glReadPixel. The opengl picking is not supported in hardware on many cards...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!