2D physics on iPhone with bullet?

DiegoBM
Posts: 4
Joined: Sat Feb 28, 2009 6:58 pm

2D physics on iPhone with bullet?

Post by DiegoBM »

Hello guys

I've heard that Bullet is mainly a 3D physics SDK, but I'd like to know whether Bullet implementation for iPhone performs well on 2D-like physics calculations (interactions among polygon-planes lying and moving just on X-Y axes) or there are better solutions out there for this kind of issues.

I think that since Bullet performs really great on 3D calculations it should also do on 2D calculations, but trying to find the optimal solution (in order to save CPU cycles), would Bullet be the better 2D iPhone approach?

Thanks a lot in advance!

Regards!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: 2D physics on iPhone with bullet?

Post by Erwin Coumans »

You might want to try Box2D, if you only need 2D simulation.

As 2D is a subset of 3D, it would be easy to add some 2D collision shapes and some methods to allow pure 2D simulation with Bullet, as well as mixing 2D and 3D simulations.

Are you interested in helping out and trying to get 2D and/or 2D/3D mix working with Bullet?
Thanks,
Erwin
DiegoBM
Posts: 4
Joined: Sat Feb 28, 2009 6:58 pm

Re: 2D physics on iPhone with bullet?

Post by DiegoBM »

Thanks for your answer Erwing,

I had considered to use Box2D or Chipmunk, but I was certainly interested in Bullet because it's accuracy and performance is well known in the industry. This is my main reason to ask about its 2D performance.

Even though Bullet is supposed to be a 3D physics SDK, it would be nice that it could be also optimized for 2D calculations if needed, making it a complete package and thus avoiding people to start wondering around which 2D or 3D package to use. I guess that people say that Bullet is not optimal for 2D because it spends CPU cycles computing the Z calculations when they are not supposed to be needed, but I am not really sure because I haven't started working on it.

Of course I am interested in helping out with 2D for Bullet

Regards!

Diego de Blas
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: 2D physics on iPhone with bullet?

Post by Erwin Coumans »

DiegoBM wrote:I guess that people say that Bullet is not optimal for 2D because it spends CPU cycles computing the Z calculations when they are not supposed to be needed
Don't worry about the z component, SIMD can take 4 components in one go. Some of the algorithms become much simpler in 2D though, Bullet is very modular so registration of those 2D algorithms should be easy.

We could pick up this discussion after GDC (we are very busy with that), the end of this month.
Thanks,
Erwin
DiegoBM
Posts: 4
Joined: Sat Feb 28, 2009 6:58 pm

Re: 2D physics on iPhone with bullet?

Post by DiegoBM »

Sure! No problem

Thanks

Diego de Blas
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: 2D physics on iPhone with bullet?

Post by Erwin Coumans »

It is now easier to use 1D or 2D physics with Bullet, check out the latest trunk:
  • btRigidBody::setLinearFactor takes a btVector3 as argument, where its x,y and z correspond to worldspace motion along those axis. Use a 1 to allow motion, and 0 to disallow motion along a certain axis.
  • btRigidBody::setAngularFactor, where x,y and z corresponds to rotation along those axis.
For example, if you want to limit the motion of objects in the X-Z plane, and only rotation along the Y axis, use:

Code: Select all

body->setLinearFactor(btVector3(1,0,1));
body->setAngularFactor(btVector3(0,1,0));
This will be available in Bullet 2.75, and if you can't wait just download the latest SVN trunk version from the Bullet code repository at Google Code.

Now we just have to add simplified 2D collision detection algorithms and 2d collision shapes. We'll add a btBox2dShape and corresponding 2d collision algorithms in Bullet 2.75.

Hope this helps,
Erwin
DiegoBM
Posts: 4
Joined: Sat Feb 28, 2009 6:58 pm

Re: 2D physics on iPhone with bullet?

Post by DiegoBM »

It really does!

Thank you very much for this update Erwin! :D
isav
Posts: 3
Joined: Sat Feb 14, 2009 6:16 pm

Re: 2D physics on iPhone with bullet?

Post by isav »

Erwin Coumans wrote:
Now we just have to add simplified 2D collision detection algorithms and 2d collision shapes. We'll add a btBox2dShape and corresponding 2d collision algorithms in Bullet 2.75.
I don't understand, is bullet 2.75 will completely supports 2D physics?
It's will be great!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: 2D physics on iPhone with bullet?

Post by Erwin Coumans »

The next Bullet release will have full support for 2D physics, including interaction between 2D-2D and 2D-3D physics objects.

The initial implementation only includes a limited selection of 2d collision shapes, such as the btBox2dShape. We add specific optimized 2D collision algorithms for those.

You can track progress here: http://code.google.com/p/bullet/issues/detail?id=208
Thanks,
Erwin
eSalt
Posts: 15
Joined: Tue Jul 19, 2011 4:08 pm

Re: 2D physics on iPhone with bullet?

Post by eSalt »

Would it possibly support 2.5D like I mentioned in my thread a while back? I do have an idea of what to do otherwise (modify/wrap box2d so that it still sees 2 dimensions, but functions in the 3rd dimension). It definitely isn't top priority, just curious. :)

Edit: remember the 2.5d I'm thinking of would weave through the environment, meaning it will possibly not be world axis-aligned...

Edit 2: Don't know if you saw the edit (probably not), but yeah, I would like it flexible. As long as these 2d collision objects can travel along a plane aligned to a local axis, or otherwise non-axis-aligned plane, I believe I have a method of doing the rest. :wink:

Edit 3 (why did it say edited 1 time total before this?): I've realized that the 2d physics objects' plane must be aligned to an axis. What would happen when two 2d physics objects meet at an angle of 45 degrees? My best bet here seems to be to have the physics objects along a plane, and transpose the corresponding meshes to the proper visual location. Sorry for the inconvenience everyone. Whatever restrictions the new release has, it should suit my needs. :mrgreen:
Last edited by eSalt on Tue Aug 02, 2011 2:29 pm, edited 2 times in total.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: 2D physics on iPhone with bullet?

Post by Mako_energy02 »

My current game that is a work in progress is a 2.5D game, that uses SetLinearFactor() on all of the moveable objects. Thing is though the "plane" things are locked onto when using that can't be tilted. They are absolute to X, Y, or Z planes. For me this isn't a problem. I just have it setup so nothing can move on the Z axis. I thought you had wanted the plane to be more flexible then that.
eSalt
Posts: 15
Joined: Tue Jul 19, 2011 4:08 pm

Re: 2D physics on iPhone with bullet?

Post by eSalt »

I'm sorry everyone. I just realized this thread is two years old. I don't know how I bumped such an old thread. I seem to remember seeing this on the first page of the forum, but...how could that happen? I hadn't done any searches... Did someone bump it before me and get deleted while I was replying? Does bullet support 2d objects at this time, or was that feature canned? How I found this thread to reply to is a mystery to me. Sorry again for being so socially inept...
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: 2D physics on iPhone with bullet?

Post by Erwin Coumans »

Yes, Bullet can do 2d physics as well, using setLinearFactor/setAngularFactor and specific 2d shapes. See also the Bullet/Demos/Box2dDemo
(As Mako_energy02 already mentioned)

The motion is restricted to the X, Y or Z world axis when using setLinearFactor/setAngularFactor. Is that not sufficient for you?

Another option that allows arbitrary planes is using the btGeneric6DofConstaint, and lock the motion using the appropriate degrees of freedom. It will cost more CPU time though.
Thanks,
Erwin
eSalt
Posts: 15
Joined: Tue Jul 19, 2011 4:08 pm

Re: 2D physics on iPhone with bullet?

Post by eSalt »

Thank you, that should be more than sufficient. Sorry for pestering everyone about this. I do tend to obsess about things sometimes (part of my condition). I also tend to overlook details in conversations, hence why I repeat myself without reason. I'll start digging back into my game first thing tomorrow morning, armed with this new information. Particularly knowing btGeneric6DofConstraint can indeed use arbitrary planes. As my game's graphics are planned to be fairly low-detail (it takes place in a dream, and I'm only one person at the moment), I should be fine with the increase in cycles. Really, dealing with transposing the collision objects' graphical representations to the proper locations would probably take almost as many cycles.

I will take a look at that demo, as well as the other demos, tonight. As I've been dealing with bullet through a precompiled wrapper (irrBullet), I hadn't really looked through the folders of the actual bullet installation. Demos ahoy! :D

Again sorry for bumping this topic. I'm still not quite sure how I came across this one, and I probably never will be. :?