I'm building a fairly complex application in Java, with JBox2D (actually, PBox2D, a wrapper for Processing). One component of this Java application is in Processing (PApplet), containing a JBox2D world. This is so I can use the excellent Processing drawing functions later in the life of the project.
When the applet gets resized, however, objects in the world do not respect the world boundaries, or the boundaries drift. Please see this video:
The boxes are where the boundaries should be... they are what is drawn in Processing. However, PBox does not maintain the same locations for its boundaries... for some reason, when the applet window changes sizes, the PBox world shifts to stick to the bottom of the window, while the Processing objects do not. Maddeningly, if I make the window bigger along the X axis, the PBox elements retain their original (correct) locations.
All of the Processing code seems functional and predictable. I cannot isolate the position changes for PBox... I'm at a loss as to what causes this, and how to fix it. My hunch is that it involves the PBox ground body, but that could be wrong.
This applet will be embedded in a Swing GUI in the future, and it misbehaves there too.
I'm having a bit of trouble using Java Swing, Eclipse, and two PApplets in Swing JFrames. Wondering if anybody can help me out... I've attached some pseudocode below that I think covers all the bases.
Basically, via its constructor, the second class PApplet Bar receives a copy of the first class PApplet Foo. The code compiles fine, all imports work OK, the JFrames render correctly, and Eclipse doesn't complain.
Bar can see Foo; the first println statement in Bar's draw() matches the corresponding println in Foo's draw(); both have the same output. The getNumber() method works perfectly in Foo. However, when Bar attempts to access foo.getNumber(), Eclipse throws a null pointer exception.
All methods are public. I've tried accessing static variables and loads of other stuff, but nothing seems to get Bar to see inside Foo.
Thanks, I'd appreciate any help or ideas. I'm at my wits end, and have tried everything I can think of.
When using the Fisica library, in particular via SVGs from Geomerative, I've been having two problems I have not been able to surmount.
The first that shapes often stick together when in a world. The Fisica library (or the JBox2D library under it) provides mechanisms to keep shapes from overlapping, but sometimes it fails, and shapes will not separate. This is readily apparent when using the Fisica WingedStar example.
I've tried a lot of kluges, but have not managed to reliably convince the engine to separate shapes once they have joined together.
The other problem with the Fisica/Geomerative combination is that imported SVGs routinely produce these errors:
Is it possible to get data for a Processing applet from the URI of the page it is running on?
Basically, I have one Processing sketch that will need to have dozens of versions running concurrently, the only difference being some initial variables. I want to have a single HTML page linking to the processing sketch, which then passes a user selection to the sketch; it seems the logical way to do this is with a pull-down menu form, which the Processing sketch uses to populate initial variables.
For example, if my Processing sketch is hosted at:
Installed the ProHTML library in standard sketchbook location. Restarted Processing as usual.
When trying to run an example or two, the library objects aren't working. For example, with the HtmlElement example, Processing craps out saying "The constructor HtmlElement(String, null) is undefined"
I have begun developing the first of a long series of Processing sketches for use in a high school chemistry curriculum. The idea is to use simulations of molecular activity to supplement lab and reading activity in learning chemistry concepts. So far Processing has been a great tool for this project; my supervisor has been pleased with the functionality of Processing visualizations over previous Flash and Netlogo attempts.
I've run into a particular problem with molecule interactions, however. My question:
How can I make two irregular shapes, floating across the Processing canvas, "bounce" off of one another when they overlap?
Initially, I was rendering molecules in Processing with a series of different sized ellipses; making molecules bounce was a matter of calculating the radii of the atoms in a molecule, returning these radii in an array, and checking the array against the radii array of another molecule; if any radii overlapped, the molecules would bounce. Pretty straightforward.
However, the visual sophistication and variation between various molecules, in addition to requests for frequent updates in molecular structure and appearance, has pushed me toward creating the molecules in Adobe Illustrator, and importing Illustrator SVG files into Processing for use in my sketches. Thus, since the files are SVG imports, I don't think I have access to their boundaries... the only thing I can think of is calculating which pixels the shapes occupy: this seems a horrible kluge, and I'm not sure how to do it.
Does anyone have any other ideas? I'm all ears.
If you would like to see an early version of this project (with molecules drawn via Processing ellipses):