detecting point on object under line

Hi,

Was wondering how am I able to detect points or edges of an object under a drawn line.

Take this example for intance, I load a cube object and I draw a line in front of it, making it look like 2 seperate halves.(how the line is drawn is by using the mouse dragged event and temporary disable the depth test)

Now I would like to detect the points/edges under the line that can be seen on screen.How am I able to do that…?

Thanks for the help…

Hi!

Do you speak about picking? If so, have a look at glSelectBuffer, glRenderMode, gluPickMatrix, glInitNames, glPushName, glPopName and glReadPixels. Maybe you could find an example on nehe.gamedev.net or in the Red Book.

I don’t think this question is about picking.

Project your vertices onto the screen plane (convert the 3D coordinates that you feed into OpenGL to the 2D coordinates where they appear on the screen - you can retrieve the projection matrix from OpenGL to do this) and use Line2D.relativeCCW(…stuff…) to determine which side of the line they are on. Remember to handle the difference between lines draw left-to-right and right-to-left.

Alternatively, construct a plane parallel to your drawn line segment and extending directly away from the camera (will also require the projection matrix), and a simple dot product with each vertex will tell you if it’s above or below that plane.

The first option is easier.

Well, I am also not very sure what I am doing is picking or not as I am still a newbie to this.
But I read the book that taught about selection/picking. It returns with the hits based on the location of the mouse.
But the problem here is that I do not really want it to be just based on a single mouse click… but a mouse dragged that draws a line. and this line drawn will be the selected region.

Wonder how am I able to do that?

Another thing is that how am I able to shade faces of of a particular drawn object? for example:
Initally I load a ball object from an object file, then I want to shade half of the ball to the color say red.Are there sample codes around?Because I am having a real hard time on this… Had been working on it for a long time and still cant get anything…

Thanks for the help… :slight_smile: