How to capture mouse events on OpenGL Rendered Objects?

I'm new to juce and trying to learn it by porting over an old Rubik cube program I wrote several years ago using OpenGL and SDL.  Following the JuceDemo I was able to render my cube's fine and was able to rotate the whole cube.

I need help on capturing the mouse events when a particular face in the cube is clicked.  When the mouse is dragged, either in the x, or y, direction, I only want to rotate the row/col that was selected. I have the matrix logic on what needs to be done, just not sure how to capture the mouse event.

My code is structured like:

Face.cpp - Handles drawing the faces of the cubes.

Cube.cpp - Handles the creation and positioning of the faces.

OpenGLCanvas.cpp - Component : OpenGLRenderer - Handles the GLRendering and mouse event for the whole cube.

 

What do I need to do to Face.cpp and Cube.cpp to have them capture mouse events as well?

 

Thanks,

Rob

 

I think the better OpenGL system is to reverse project a cone - it better represents the view frustum.

But there used to be some pretty cool tricks, involving an extra drawing phase... let me think... something like drawing every block on the cube in a different color, then you draw into a buffer used just for picking. Then you end up just sampling the color in your fake buffer according to the mouse click. 

Does that make sense? It's not a general solution, but an old trick.  It would give you which face they clicked on, and you find the row and column as you need from that.

Bruce

Edit: what did you used to do - in the previous version?

Before I did something similar to what Hugh had suggested.  Basically I put OpenGL into selection mode, zoom into a small portion of the screen where the mouse was, apply a gluPerspective and rerender the cube, switching back to render mode to see if we have any hits.  If I had any hits, I take the one on top as my cube face to work with.

I probably can use that method, I just wanted to see if their was a way to do it using juce components instead of OpenGL api's. 

Thanks,

Rob 

Nope. OpenGLComponents have no special knowledge of what you've drawn in them. Not sure there's any OpenGL helper stuff in there yet either. If you come up with something good, please consider asking to have it added to Juce!

Bruce