Box2d Raycasting

I was checking the Andengine forums for some new additions to our stuff (box2D mostly) and came across a nice patch by HexWave that adds raycasting support to the Box2D wrapper. I included it in SVN and the nightlies, enjoy. Major props to HexWave for the patch, we appreciate it. To bad noone at Andengine felt the need to inform us about it (or include it in their own fork…).

Thanks HexWave!

I also fixed a couple of other things like the EarCutTriangulator.

So much for the holiday break… I crawl back to my cave now.


A number of commonly useful collection classes have been added to the utils package. Here is a quick rundown:

  • Array An ordered, resizable array of objects. This can be used in place of ArrayList. This class is a tiny bit more efficient than ArrayList for get/put and exposes the size and underlying items array. The items array can be typed, which facilitates System.arraycopy. It can be used with the enhanced for loop syntax without allocation (it caches a single instance of an iterator, so this isn’t thread safe). The methods indexOf, contains, and removeValue can either use equals() or identity (==).
  • Bag An unordered, resizable array of objects. All the same features as Array, except when an element is removed, it is simply swapped with the last element in the bag. This avoids the memory copy that occurs when an element is removed from an Array.
  • ArrayPool and BagPool These are the same as Array and Bag respectively, except instead of giving the object to add, add() is called without parameters and returns a new object. The pool knows how to create the object via an abstract newObject() method. This allows elements in the pool to be reused to avoid garbage generation. The pool can be used as a simple store for objects used elsewhere, or can be used itself as a collection of objects.
  • IntArray, FloatArray, and LongArray These are the same as Array, except store primitives. This avoids the boxing that would happen with ArrayList while still providing the convenience of an automatically resizing collection.
  • IntBag, FloatBag, and LongBag These are the same as Bag, except store primitives. Again, this avoids boxing.
  • IntHashMap and LongHashMap These are hash maps that use an int or long as the key. This is more efficient than using object keys and avoids boxing. The entries, keys, or values can be iterated without allocation and remove() is supported. The containsValue method can use equals() or identity (==).

Libgdx Holiday Thoughts

When i implemented the Awesomium extension yesterday i noticed that some desktop semantics for mouse events are not available in libgdx. This is on purpose as i originally aimed libgdx primarily at Android. But now i have more and more use for it on the desktop as well and it would be nice to have full desktop mouse semantics, e.g. left/right/middle button recognition, mouse move (not button down) and scroll wheel. I pondered on how to include that in the Input and InputProcessor interface. Here’s the first draft of InputProcessor (mouse/touch related stuff only):

So the old methods get an additional parameter. touchDown/Up will be triggered each time a mouse button goes down with the button parameter set to the button that was pressed/released. touchDragged also gets a new parameter. However, it encodes all currently pressed buttons not just one. Otherwise we’d have to generate multiple drag events per button, that wouldn’t be good. touchMoved() only reports the x and y coordinate and will be triggered when no button is pressed but the mouse is moved. On Android this will not get triggered as their’s no equivalent to this on a touch screen. The scrolled() method is triggered by using the mouse wheel with the scroll amount passed in as a parameter.

That’s the best thing i could come up with. You’ll have to modify your existing apps to accomodate the new parameters. Other than that nothing has changed really, your programs will continue to work as before without any further adjustment. However, the new additions allow us to write fullfeatured editors and the like for the desktop, with context menus and so on. Something i might consider doing in the future.

Any input appreciated. A replacement for the touchXXX would be nice too. mouseXXX isn’t exactly correct either. You have until the 28th 🙂