Controllers

Ok, this isn't nearly as cool as some of the other things I've done, but I think this is necessary. I've implemented a bit of a Controllers suite, where by controller I mean helper class for applying forces, like the buoyancy controller I posted earlier.
Demo
Download
Details

See details for more info. Of particular interest is probably b2TensorDampingController, which despite its obscure name, is essentially a controller which allows you to do (one kind of) top down wheel behaviour, which a few people were asking about earlier.

Please please please comment on the design choice I made (e.g. perhaps you'd prefer this in the Box2D package, rather than my own). I'm gonna start porting to C++ now, so it's important to get it right.
The separate package doesn't matter me. In fact, I think I prefer it. The only complaint I have about your contributed code is that I have to patch the core Box2d classes all over the place. Upgrading when a new version comes out is going to be painful.

I've been working on some crazy gravity implementations, stuff like gravity that changes direction based on sin(x), gravity that's part linear / part radial (rounded rectangle), and I'm thinking of using your controllers for the final implementation. The base controller classes are general enough that I think a lot of useful stuff could be built on them...
Small side question, any idea why your side fails in firefox? The flash file works fine:
http://boristhebrave.com/sites/default/ ... abPack.swf
But it won't show up on the demo page...
works fine here with FF 3.0.3 on Vista x64. Any addons blocking it perhaps?
zappBrannigan wrote:works fine here with FF 3.0.3 on Vista x64. Any addons blocking it perhaps?
Only have adblock installed, but that's not blocking it. Also got firebug installed. I don't see any errors in the error console, and I can see with firebug that it does load the flash file.
I get jerkiness myself (FF3, vista, 32). I don't know what the problem is or how to fix it, though I'd love to hear. Firefox has never been good with Flash for some reason. I'm using SWFObject, which I thought would have dealt with any problems.

mayobutter wrote:The separate package doesn't matter me. In fact, I think I prefer it. The only complaint I have about your contributed code is that I have to patch the core Box2d classes all over the place. Upgrading when a new version comes out is going to be painful.

Hmm. This is really what source control etc is designed for. You don't need manually do all that patching, but instead make a patch from my contributed code, and apply it to the new version, or visa versa. I used to provide patches as well as .zip downloads, but it was apparent no one was using them. Also, the odds aren't too bad that the next version will come with some of this code.

mayobutter wrote:The base controller classes are general enough that I think a lot of useful stuff could be built on them...

Exactly the point. Now hopefully we will be able to share snippets of code easier without having do adapt it to different frameworks every time.
Wow, this is the first time I've seen the buoyancy one. Extra cool! Many thanks Boris.
This is awesome. Looking forward to the C++ port!
Hey,

I took a look at your code, but haven't got a chance to test it out yet. I think it's pretty clear, and nicely separated from the rest of the engine, at the moment.

I can imagine that if this is a useful enough feature, inclusion in the Box2D package would seem logical. (maybe in Box2D.dynamics.controllers ? ) (So that it works "out of the box" so to say).

API-wise, at this moment it seems straightforward enough, but again, if this becomes a standard feature, something along the lines of

Code: Select all

world.CreateController(....)

might be worth considering? Or am I overlooking something?
I did code exactly that up, but deleted it. Here are some reasons why I'm apprehensive, despite the obvious nicety of having a similar interface. Though none are especially compelling, there are quite a few...
  • Thus far, I haven't gone down the factory route of making matched Defs to go with each class, so it would be misleading to give a similar behaviour.
  • Controllers are order dependent, at least some of the non-force generating ones are (currently only TensorDamping, I think).
  • Box2D doesn't "know" which bodies a controller controls, and enabling this would be messy. This means sleep doesn't work properly, nor implicit destruction, or islands. The user must code around these problems.

Basically, once I "attach" controllers to the world, it is necessary to implement the full many-to-many relationship of controllers to bodies for consistency reasons, and re-implement a lot of the joint based features. And in box2d style the relationship would be represented by some sort of convoluted linked list. I'd really rather wait until Erin creates a pattern for dealing with dynamically sized arrays as he mentioned he might, before proceeding.

Original thread: https://box2d.org/forum/viewtopic.php?t=1567