Ossory
YaBB Newbies
Offline
Posts: 6
Re: One question forward about the 'textured cube'
Reply #1 - Mar 11th , 2009, 1:12pm
I'm sorry, I cannot give you the code for this as I haven't got it anywhere, but here goes. The most generic approach to this is the following: You want to detect if the mouse is over an arbitrary object in an arbitrary 3D scene, assuming that the mouse position is determined by its X and Y coordinates (mouseX and mouseY) in the main PGraphics object. What you do is, you render the scene normally, as you want it to appear to the end user. THEN you render it to a separate offscreen PGraphics object, using unique color (ARGB) value for each object, giving you 2^32 possible combinations (right? :P), I'm not quite sure if you can use the alpha value for this, but that is still a lot without it (2^24). When you need to determine which object the mouse is over, you check the mouse position (mouseX, mouseY) against the color of the pixel in the "auxilliary" PGraphics object (using, say, PGraphics.get(x,y)). Knowing which color corresponds to which object (the colors are unique, remember), you can easily determine which object the mouse is over. This shouldn't be very slow, and in any case you can apply all sorts of easy-to-implement optimizations, like using a half-resolution auxilliary PGraphics object, rendering it only once every N frames and so on. I think, this technique is mentioned somewhere in hacks section. It utilizes the stencil buffer, which, I think, is not applicable to Processing 1.0 Sorry, if this sounds a bit complicated, there are probably easier solutions to this. I'll try to throw together some code, demonstrating this technique.