ewjordan
Ex Member
Re: collision detection
Reply #4 - Aug 8th , 2007, 9:33am
Alas, it's not done like that internally. Processing doesn't use Java3d for 3D, for one, instead it uses JOGL bindings (or its own internal software renderer if you're using P3D). What happens when you make a box in Processing is essentially that it creates, transforms, and immediately draws 12 triangles (6 faces * 2 triangles/face) to the screen without storing them anywhere (in fact, if you look in the source code, you'll see that P3D reuses the same PTriangle object over and over; with OpenGL it sends a separate drawing command for each triangle right as they are created). So when you draw another box, all record of the first box is gone (except whichever pixels were drawn to the screen), so it's not possible to do collision detection that way. The only way is either by hand or via a library - something else has to sit between you and the drawing functions to handle this stuff. Otherwise, you probably want to just dig directly into Java3d programming rather than trying to make Processing interoperate appropriately. Out of curiosity, what do you need this for? Are we talking about a few simple shapes on screen and just making sure that they don't interpenetrate, or are you trying to set up a physics engine to run thousands of rigid bodies in real time? I ask because there are easy ways to implement this stuff, and hard ways. The easy ways will do the job, but they won't do it fast enough to handle massive amounts of geometry (like for a physics-based FPS or anything like that). If you need major speed, you're in for a large amount of research and work - people have literally written entire textbooks about how to do this stuff in real time, and entire PhD theses exist on fairly small pieces of this problem. But if it's for something fairly simple, you might be able to get away with pairwise triangle-intersection tests, which are really easy to code.