
How to get 3D coordinates from glControl by clicking or selecting with the mouse??
Posted Thursday, 24 June, 2010 - 09:46 by t7.reyeslua inHello :)
I'm doing some 3d plotter with OpenTK and I need the user to be able to select each individual plotted point and know the coordinates of it. Obviously I know the 3Dcoordinates of all points because that's how i plot them. What I'm not sure how to do is to get the coordinates FROM the glControl with is what the user interacts with. It would be nice if the user could click some point in the glcontrol and know its coordinates. Any ideas/examples of how to do that?
Thanks!! :D


Comments
Re: How to get 3D coordinates from glControl by clicking or ...
Look for project/unproject method.
Google is your friend !
Re: How to get 3D coordinates from glControl by clicking or ...
Hey....thanks for the quick response! :) ...I've been reading about it and that's exactly what I need! The problem is that I can't seem to find the method anywhere in the OpenTK version I'm using (v1.0). Idon't know if it has not been ported to this version or what. I'm no openGL/TK expert, so if someone could point me where/how to find it, it would be great! :D Thanks again.
EDIT: I'm gonna try with OpenTK.Compatibility where I suppose it is.
Re: How to get 3D coordinates from glControl by clicking or ...
From XNA Viewport :
Hope it will help...
Re: How to get 3D coordinates from glControl by clicking or ...
Q1) Anyone has codes howing how to efficiently pick triangle of a mesh object picked by a ray cast using OpenTK unproject? I have looked into the picking example of Opentk, not sure how that is related to Unproject of GL.
Q2) is it possible to get local coordinate space from this method to calculate texture coordinates associated with that interception point?
Re: How to get 3D coordinates from glControl by clicking or ...
Hey!
I finally got it :) ... I post here what it worked for me so if someone else needs to do something similar it can be found here. Actually I took most of it from http://www.opentk.com/node/480 and just made small changes.
In my code I have a 3D coordinate system where I plot some points. The user must check a checkbox to be allowed to "select" points by clicking them.
In order to get the UnProject method I had to add the OpenTK.Compatibility.dll to my project. The problem was that by adding it there were some "conflicts" with the regular OpenTK.dll. That's why I had to specify in my whole code the "OpenTK.Graphics.OpenGL.GL" in the functions where I had before just "GL". It seems as if the Compatibility dll is just not so compatible after all :P
Re: How to get 3D coordinates from glControl by clicking or ...
OpenTK.Compatibility is there to support projects using the Tao framework or older OpenTK versions. It's not really meant to be used outside of those circumstances (namespaces clashes will arise if you try to include namespaces from both OpenTK and OpenTK.Compatilibity in the same source file).
Re: How to get 3D coordinates from glControl by clicking or ...
Hi t7.reyeslua
I want to do a project and it seems like your's. I am using Java and JOGL (OpenGL bindings for java)
It is like Opentk. I dont know about openttk I just search about getting world position from mouse click.
I used your algorithm for getting the correct values. And I got wrong values. Here is my code. Can you suggest something
Re: How to get 3D coordinates from glControl by clicking or ...
Disclaimer: I may be 100% wrong about this...
...but I think you're in the wrong place. OpenTK is accessible by .Net languages, like C#, F#, VB.net and IronPython. There may be a few Java devs here, but it's not very likely that you'll get the help you need.
I did some googling for you and found this thread on Gamedev, which seems to be what you're looking for. Hopefully that helps!
Re: How to get 3D coordinates from glControl by clicking or ...
I had to do this a little while back for my research project, basically I just ported the code from elsewhere. No need to use the compatibility dll, just write your own little UnProject() instead of using glu's one.
I used this is my glCtrl_MouseMove function, with a mouseDrag boolean variable set in glCtrl_MouseDown/glCtrl_MouseUp.
This assumes your render code looks something like:
...that way, these operations are reversed and you get the 3D position on the surface of the model for any other operations you want to do to it, which I've found rather useful for visualization purposes.
These are the functions that do the actual 'work':
Hope that helps!
Re: How to get 3D coordinates from glControl by clicking or ...
Yes I know I am wrong place :) but I just want to get some suggestions from you.
They are typically same.
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
with this code you get viewport, modelview matrix and projection matris. Yes I can do that with opengl and then
you use
glu.gluUnProject((double)x,(double)realy,0,mvmatrix,0,projmatrix,0,viewport,0,wcoordnear,0);
Ok I use the gluunProject with same input values. First with znear=0 and second zvalue=1
I get the values. I thought they are same methods. I used.But then I use the second part with finding the nearest point
Someone use one algorithm and I though maybe it will work for me :)
Thanks everone