Blog about (Web-) Programming, Graphics and Games.


Java Physics Demo: Boxes

This demo uses parts of the the JBullet and the Vecmath library. I extracted essential classes and put them all into 1 java source file. Thus this demo dont needs external libraries.

On Objectstacks
I also changed the used JBullet parts, so that they dont use Objectstacks. Objectstacks were introduced to manage temporary objects in a threadsafe way. There are 3 possibilities to deal with temporary objects:
  • 1) Just instantiate a temporary object as you need it. Problem: this can result in a lot instantiated objects, garbage collector has alot todo, runtime performance might drop. Though, intelligent jit-compilers could possibly handle multiply temporary instantiations and could in a way inline them..
  • 2) Add (private) auxiliary objectvariables to the class. You can use this objects in computation and dont need to instantiate new ones. Problem: if different threads invoke the same method at the same time, an object could be used twice, with unexpected results. This approach is not thread-safe.
  • 3) Use objectstacks. Retrieve auxiliary objects from a pool and return them to the pool, when computation is over. This way in most cases only limited number of instantitions is needed (opposed to possibly unlimited instantiations in approach 1) and this method is threadsafe (opposed to approach 2).
The original JBullet library uses objectstacks. In this demo I omitted them, because the original approach requires an instrumentation step in the build process. During this step auxiliary classes are generated using an ant-build-file. A simple compile doesnt work. For sake of simplicity I thus dont use objectstacks here, but above second technique. Thus this demo is not thread-safe, but its usecase is only single threaded, so it doesnt matter.

How to build
  • Make sure, that a JDK is installed.
  • Put the source file into a directory 'net/plsw/bullet'.
  • Compile it with 'javac net/plsw/bullet/'.
  • Run it with 'java net.plsw.bullet.BoxDemo'.

1 Kommentar:

hechizos hat gesagt…

Gravitation /keine Erfindung (irgendeines) Gottes
sondern ist entstanden aus nichts und abernichts / so Hawking
keiner war da, der vor der Schaffung des Universums
daran dachte, dass Gravitation notwendig ist, ansonst
es schon gar nicht zu einem Universum kommen konnte