Controllers

Discuss issues specific to the Flash/AS3 port of Box2D
BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Controllers

Postby BorisTheBrave » Sun Oct 05, 2008 5:03 pm

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.

mayobutter
Posts: 915
Joined: Fri Dec 14, 2007 8:07 pm
Contact:

Re: Controllers

Postby mayobutter » Sun Oct 05, 2008 7:19 pm

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...

Daid
Posts: 138
Joined: Wed Sep 10, 2008 8:03 am

Re: Controllers

Postby Daid » Mon Oct 06, 2008 2:29 am

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...

zappBrannigan
Posts: 102
Joined: Tue Apr 29, 2008 1:55 am

Re: Controllers

Postby zappBrannigan » Mon Oct 06, 2008 4:19 am

works fine here with FF 3.0.3 on Vista x64. Any addons blocking it perhaps?

Daid
Posts: 138
Joined: Wed Sep 10, 2008 8:03 am

Re: Controllers

Postby Daid » Mon Oct 06, 2008 4:51 am

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.

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Controllers

Postby BorisTheBrave » Mon Oct 06, 2008 5:53 am

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.

irresistible force
Posts: 1988
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Controllers

Postby irresistible force » Mon Oct 06, 2008 6:02 am

Wow, this is the first time I've seen the buoyancy one. Extra cool! Many thanks Boris.

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: Controllers

Postby kne » Mon Oct 06, 2008 8:56 am

This is awesome. Looking forward to the C++ port!

android
Posts: 280
Joined: Fri May 16, 2008 2:52 pm
Contact:

Re: Controllers

Postby android » Tue Oct 07, 2008 3:00 am

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?

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Controllers

Postby BorisTheBrave » Tue Oct 07, 2008 4:17 am

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.


Return to “Flash”



Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 1 guest