
Picking/Selection with OpenTK 1.0 RC1
Posted Wednesday, 29 September, 2010 - 08:11 by CDoubleU inHello everybody,
I try to do picking and I found a lot of tutorials how to do this in OpenGL. But unfortunately the GLU functions aren't any longer in OpenTK. And I couldn't figure out how to do this with the existing methods in OpenTK 1.0 RC1.
And by the way: Using the compatibility DLL isn't a possibility for me. I want to know how to simulate the GLU functions.
Thanks in advance
CDoubleU


Comments
Re: Picking/Selection with OpenTK 1.0 RC1
Hi, ...
Go to this link Triedimax (simple 3D editor-modeler), download the source code, run the program in debug mode and study the source code. I think you will find all the answers you seek.
Regards, ...
Re: Picking/Selection with OpenTK 1.0 RC1
For the present, I do Picking/Selection by using OcclusionQuery .
Make variables for each objects' query, and call GL.BeginQuery(QueryTarget.SamplesPassed, QueryID) and GL.EndQuery(QueryTarget.SamplesPassed) around drawing .
After that , call GL.GetQueryObject(QueryID, GetQueryObjectParam.QueryResult, out Pass) . It returns result into Pass that how many pixels were drawn .
Then, if the area where you need is only drawn, you can get result (not equals zero) .
So, you must draw the only area where you need .
I use this function for it.
Multiplying this matrix to ProjectionMatrix in advance, you can draw only object around the coordinate specified by arguments .
This way needs you to do drawing for Selection . Of course, textures are needless and only need very low resolution .
You can do Picking/Selection by using this result .
However, to tell you the truth, I don't know whether this way is right or not .
And this way has a problem that getting depth value is hard .
I want to know smarter ways too.
I'm sorry for my poor English .
Re: Picking/Selection with OpenTK 1.0 RC1
Thanks for the fast help. I was able to create the pick matrix.
But I still have a problem with picking. It seems, that picking area is not the same as the area I select with my mouse. Maybe there is something wrong with my perspective but I really don't know.
Here is my code for this:
Re: Picking/Selection with OpenTK 1.0 RC1
Hi, ...
I found a test project I did long ago, hope you find it useful.
Regards, ...
Re: Picking/Selection with OpenTK 1.0 RC1
Thanks for you test project.
Unfortunatly I didn't get my code doing yomething useful using GL.Ortho(...). And I don't want to use the opentk.compatibility.dll, because else I get some namespace problems. This means I don't want to use GLU.
I want to know how to do this with plain opentk functionality. And the code, I posted above, seems to work nearly perfekt. But the part, which is selected for rendering in select mode, isn't exactly the position I selected with the mouse.
So, what is wrong with my code? Can someone show me what I have to fix to get it working?
Thanks in advance
CDoubleu
Re: Picking/Selection with OpenTK 1.0 RC1
isn't exactly the position I selected with the mouse
How far off are you (min/max)?
Re: Picking/Selection with OpenTK 1.0 RC1
I can't say exaclty how far I'm off, but it seems to me, that the farer I'm off from the center of the screen (with my mouseclick), the greater is the difference between clicked position and selected area.
If you'll try my sourcecode you'll see this effect immediatly.
Re: Picking/Selection with OpenTK 1.0 RC1
Was just thinking you may have some off-by-one error (ClientArea width/height, transformations) but that seems unlikely if it's an effect that depends on the distance to the center.
Is the selection correct at the center? Does it change if you force the ClientArea to 0,0 to width-1,height-1 (disabled border etc.)?
Re: Picking/Selection with OpenTK 1.0 RC1
Yes, the sellection at the center seems to be correct. Maybe there is a problem with may matrices, but I'm not good enough in this special math stuff to be sure of this.
EDIT:
By the way: it seems to work when I have a rectangular window (width = height).
Re: Picking/Selection with OpenTK 1.0 RC1
After having rewritten gluPickMatrix and gluPerspective by myself, everything works fine.
And here is my working code: