OpenGL Object at mouse click

I’ve seen similar topics in here, but they are trying to do something more complex.

I would like to be able to find the object within my scene, which could fall directly under the mouse at x,y when I click.

The other threads I read had topics like moving an element through 3D space with the mouse click-and-drag. I do not need to do anything that complex.

I did this before, years ago, but I no longer have any of that code, and cannot remember how I accomplished it.

Thanks in advance!

Have you tried Rect.Contains?

e.g.

Dim p As New Realbasic.Point(X, Y) Dim r As New Realbasic.Rect(left, top, width, height) If r.Contains(p) Then

I just realized you’re not talking about 2-D, so disregard that.

Hi Chris,

Perhaps this tutorial might be of use to you:

real3dtutorials.com: Tutorial 10 - Take your pick

It was written for the old RealStudio but might give you some ideas for how to achieve mouse clicks in OpenGL with Xojo.

I think that the best (fastest) method to pick up an object in OpenGL environment depends a lot on the types of objects you use.
For many years I used the GL_SELECTION render mode, but later, as my application was very particular with the type of objects used, I changed the way to pick up these objects, and now it is done with my own code.

Anyway, although probably you have visited it, this is the official page about GL_SELECTION render mode:
https://www.opengl.org/archives/resources/faq/technical/selection.htm

The above suggestions are great. Here is a quick example that I put together which interacts with the Xojo pixel position and moves the circle in the OpenGLSurface control.

OpenGLMoveCircleWithMouse.zip

Here is a link to the YouTube video where I move the circle on my computer.

YouTube Video

Press the button ShowOpenGL Surface to show the control and then click and drag your mouse on the blue circle. The additional step of a button is needed as there is a small bug in Xojo at the moment.

Happy to help.

I converted the YouTube video to a format that can be viewed on the forums:

I’m using the tutorials at http://www.real3dtutorials.com/. They are great. I’ve done most of my implementation using this.

I think what I really need to do is simply translate the XYZ of any given vector to screen coordinates.
Then I’ll loop through the closest to furthest from the camera, and stop if I find find one that is within a reasonable buffer for a mouse click.

I’ve been trying to find an example of how to do this, but I’m lost in the noise.

I think Ramon’s suggestion might include the closest means to do this, but it seems like it’s not quite what I’m looking for (I could be wrong).

Once I have a camera position, and quaternions etc all stacking up to create the scene pre-rendering, I’m not sure how to untangle to figure out how the point’s XYZ relate to the screen world.

Does this help?

http://antongerdelan.net/opengl/raycasting.html

or https://www.bfilipek.com/2012/06/select-mouse-opengl.html