View Full Version : select a point ?
10-03-2004, 11:14 PM
i've created a program to schow a huge terrain. This programm will be an editor for these terrain. my problem is how is it possible for me to detect witch point of these terrain i've selected with the mouse ?
I've seen many "pick object" tutorials but it is not the right way for me because the complete terrain is one object.
Can anybody help me ?
I'm using visual basic .net for opengl programming. But i know c++,too. Therfore it is no problem for me to translate c++ code to vb .net
Thanks forward !!
I think your first stop should be gluUnproject. From there on I remember reading a tutorial where a person color picked the depth (because with gluUnproject the z coordinate is clamped to [-1.0, 1.0] I think). Maybe you could do a search for "gluUnproject color pick" or something. Hope it helps!
10-04-2004, 03:23 AM
i've read a tutorial with gluunprojekt but it doesn't work correctly. If u click to a point of my terrain i will get a x,yx coordinate of it. Then i move my camera a little bit an click to the same point and i will get a other coordinate for the same point. This could not be correct.
I don't know what i should do.
But anyway: Thanks for your help.
here is my code:
Public Sub GetOGLPos(ByVal x As Integer, ByVal y As Integer)
Dim viewport(4) As Integer
Dim modelview(16) As Double
Dim projection(16) As Double
Dim winX, winY As Single
Dim winZ(1) As UInt32
GL.glGetDoublev(Convert.ToUInt32(GLFlags.GL_MODELV IEW_MATRIX), modelview)
GL.glGetDoublev(Convert.ToUInt32(GLFlags.GL_PROJEC TION_MATRIX), projection)
GL.glGetIntegerv(Convert.ToUInt32(GLFlags.GL_VIEWP ORT), viewport)
winX = Convert.ToSingle(x)
winY = Convert.ToSingle(viewport(3)) - Convert.ToSingle(y)
GL.glReadPixels(x, CInt(winY), 1, 1, Convert.ToUInt32(GLFlags.GL_DEPTH_COMPONENT), _
GL.gluUnProject(winX, winY, Convert.ToInt32(winZ(0)), modelview, projection, viewport, posX, posY, posZ)
MsgBox(CStr(posX) + ":" + CStr(posY) + ":" + CStr(posZ))
10-04-2004, 07:06 PM
What Moucard suggested certainly helps if you're tracing lines into the terrain (not a bad way to go, perhaps the preferred way, if I may be so bold). You can create the trace beginning and end points using UnProject, by supplying a 0 and 1 for the screen z parameter, respectively. Then, all you have to do is perform the actual line trace for the intersection point. If you're familiar with BSP trees at all, there's a way to do this using an implicit subdivision tree. This is more the stuff of Math and Algorithms, though.
OpenGL picking, as mentioned, will work too. Here's, what seems to be, a good tutorial on picking:
The trick with the picking would be rendering your points large enough to click on them (maybe use quads you can scale on-the-fly). Whereas with a line trace, you could simply select the vertex closest to the intersection point.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.