Bullet integration with Cocos2D, review?

Show what you made with Bullet Physics SDK: Games, Demos, Integrations with a graphics engine, modeler or any other application
Post Reply
yarri
Posts: 2
Joined: Thu Jul 23, 2009 8:54 pm

Bullet integration with Cocos2D, review?

Post by yarri »

Hi, sorry for the cross post but I've contributed an integration I did of Bullet to the iPhone 2D graphics engine called Cocos2D and have a few questions:
http://www.cocos2d-iphone.org/forum/topic/841


Riq Quesada from Cocos2D asked for a sample app, and I just posted one for him. I used the Bullet 2.74 source and tried to follow your examples but not sure if I found the best way to do things. If you have time, would you mind reviewing for us:

http://www.playngive.com/bulletCocos2D.zip
http://www.playngive.com/cocos2d.zip

Some questions:

- For these static world spaces, isn't there a better way to set up the AABB; I use four cubes to define the outer bounds -- should use 6 I guess, but isn't there a way to create a cube with inverted normals to contain the world more directly?

- You can see from the game the collisions aren't as precise as you'd like; increasing the step size doesn't seem to help however and I wonder if that's an issue with your 2D collision solver?

- I'm missing the math to do this, but one problem with using Bullet in a 2D game is the angular rotation is 3D of course, so when I try to map a sphere's angular rotation to a 2D projection (ie., a disk) it's not smooth; is there something better than the method I'm using:

Code: Select all

				btTransform trans = body->getWorldTransform();
				btQuaternion rot = trans.getRotation();
				[sprite setRotation: (float) CC_RADIANS_TO_DEGREES( rot.z() )];

Thanks,
--yarri
trydis
Posts: 3
Joined: Sun Nov 08, 2009 11:59 pm

Re: Bullet integration with Cocos2D, review?

Post by trydis »

bump
lucaspcamargo
Posts: 3
Joined: Sat Dec 12, 2009 1:32 pm

Re: Bullet integration with Cocos2D, review?

Post by lucaspcamargo »

yarri wrote:I'm missing the math to do this, but one problem with using Bullet in a 2D game is the angular rotation is 3D of course, so when I try to map a sphere's angular rotation to a 2D projection (ie., a disk) it's not smooth; is there something better than the method I'm using
Perhaps you should set the rigid body's rotation in both x and y axis to zero, every frame. This way, the simulation runs as if the rotation in those two axis were always null, which is the affect you're looking for. Try this:

Code: Select all

				btTransform trans = body->getWorldTransform();
				btQuaternion rot = trans.getRotation();
				[sprite setRotation: (float) CC_RADIANS_TO_DEGREES( rot.z() )];
				rot.setX(0);
				rot.setY(0);
				trans.setRotation(rot);
				body->setWorldTransform(trans);
I'm not very sure about the method names, but you got the point :wink:

Cheers, Lucas.
rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: Bullet integration with Cocos2D, review?

Post by rrck »

In latest Bullet trunk (or maybe even in 2.75 version) was introduced some improvements for 2D.
You can use setAngularFactor and setLinearFactor to limit velocities in desired axises, also was added 2D shapes, try to look Bullet/Demos/Box2dDemo
Post Reply