Get 3d Object under Mouse

Hello to everyone!

I’m quite new to openframeworks and trying to slowly get into it.
I hope my question is in the right place here…

I’ve managed to start and compile a new project (running on osx 10.8 and working with Xcode).
I have a 3d scene (a bunch of ofNodes drawn as spheres) and an ofEasyCam.

My question is:
Is there a way to find out if the mouse pointer is over one of the 3d spheres? I would like to make these 3d objects sort of “interactive” so that I can select one, know when I click one of the spheres (and which), and maybe draw these around.

Any suggestions?

Thank you for your help!

For 2D I use ofDist to detect and click inside circle with mouse, I don’t know for 3D object if ofDist work.
Here is an 2d circle example :

void testApp::mousePressed(int x, int y, int button){  
    float dist = ofDist(myCircleX, myCircleY, x, y);  
 	if(dist < myCircleRadius)  
 		// do things  

ofEasyCam is a ofCam which is a ofNode which has the worldToScreen()-function which calculates your 3d-coords to screen-coords.

greetings ascorbin

hi dP,
check the pointPickerExample in openframeworks/examples/3D
It deals exactly with what youre asking.

best regards

Thank you for your replies!

The worldToScreen scrrenToWorld functions did it.

Just a note: these functions are members of ofEasyCam and not of ofNode.