We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › One question forward about the 'textured cube'
Page Index Toggle Pages: 1
One question forward about the 'textured cube' (Read 627 times)
One question forward about the 'textured cube'
Mar 11th, 2009, 2:50am
 
I read the 'textured cube' at the page
http://processing.org/learning/3d/texturecube.html  
and I want to write some code to interact with the cube more precisely,i.e.,let an event occur when you placed your cursor right onto the image of the cube.

I think the point is to make the computer be awared of the relative position between the cursor and the projection of the cube on the X-Y plane?Thanks for hints.If you already have code for such cases,that will be wonderful!Smiley
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.
Re: One question forward about the 'textured cube'
Reply #2 - Mar 12th, 2009, 1:07am
 
I'm no VIP,but it seems you regard me like that.Nice to see you pal,wish you a good day!
I'm just impressed by the way you talk with people--comprehensive and gentle,a model for me,yes!  
Re: One question forward about the 'textured cube'
Reply #3 - Mar 12th, 2009, 3:55pm
 
I see now,the function screenX/Y/Z is useful for describing the projections of one cube's six vertice on x-y plane,and another thing important is to make a covex hull for these projected vertice,which are planar!
If a convex hull is made without much calculation for general situation and an algorithm is written to judge if a 2d point is inside it,then many 3d shapes could be played by a cursor placed right inside their projections,which seems interesting!I'm working on that algorithm now,and looking forward to your ideas,too.
Page Index Toggle Pages: 1