PDA

View Full Version : Ray Picking



Atomic_Sheep
08-18-2013, 10:49 PM
Hi guys, I know there's heaps of hits on picking on google but I've got some questions that I've been unable to find answers for so here it goes:

I'm obviously interested in getting some picking happening in my application. I'm aware that ray tracing is the best method so that's the direction that I'm leaning and I more or less understand the pseudo code for ray tracing... up until the point of actually getting it to work with my display lists. What I mean by that is:

1.) How do I determine which display list a triangle belongs to? The way I see it:


for(iterate through display lists)
{
perform a ray triangle intercept test
if(hit occors)
return(object index) //we found a hit
}

Given this pseudo code, I don't understand how this is any different to simply doing something along the lines of (I'm just trying to implement a button click detection):

[CODE]for(iterate through display lists)
{
if(mouse click is < right most point of display list coord && mouse click > left most point of display list coordinate && mouse click < upper most point of display list coordinates && mouse click is > bottom most point of dsiplay list
return(object index) //we found a hit
}

Obviously this isn't the most elegant solution but it will work but it will also require a lot of stuffing around in terms of doing #defines or writing a lot of switch case statements later on to do certain things if a certain button is clicked, so it becomes quite big and ugly.

Can someone explain a way of doing box picking without having so much hard coding? Just trying to make a simply button interface.

2.) How do I access a display list vertex? Say I want to do something along the lines of:

vector ReturnListObjectCoordinates(GLuint ListObject)
{
return vector;
}

thokra
08-19-2013, 02:46 AM
I find your post to be a little confusing.

To summarize: you want to do picking of GUI elements you somehow manage in your application and render with OpenGL and want to simulate classic event handling when a ray cast hits a GUI element, right? This is all 2D? Are GUI elements always perpendicular to the camera's direction? Are all elements rectangular and not rotated (i.e edges are parallel or perpendicular (depending on the axis) to the screen edges and do they coincide with the near-plane?

Atomic_Sheep
08-19-2013, 03:22 AM
Yes to all those qs, if you have some info on having all this work with keyboard inputs as well, that would be good. In other words techniques for re-using code in the parts of the program that take input from keystrokes.