Capsule?

Zimbarbo
Posts: 14
Joined: Thu Jun 28, 2007 2:26 pm

Capsule?

Post by Zimbarbo »

I saw in another post, someone made a capsule. I see the enum in the BroadphaseNativeTypes, but is this supposed to be shape class type? Or is it easier than that? I am assuming a capsule is nothing more than two spheres and a box connecting them?
Thanks!
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Post by Dirk Gregorius »

There is a capsule type. For some reason it hasn't been in the project files. IIRC in version 2.53 you should find it again.
I am assuming a capsule is nothing more than two spheres and a box connecting them?
No, a capsule is a sphere swept along a line segment in other words the minkowski sum of the segment and the sphere. So all you need to do is add both support mappings. If you need a tapered capsule you take maximum support value of the two spheres. Gino calls this a generalization to collections of arbitrary convex objects. (s. page 138)
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Post by ola »

Hi,

I made a capsule like this:

Code: Select all

 
 btCollisionShape* avatar_shape = new btCapsuleShape(0.2, 1.43);

 btTransform local_transform;
 local_transform.setIdentity();
 local_transform.setRotation( btQuaternion( btVector3( 1.0, 0.0, 0.0), M_PI/2.0) );
 local_transform.setOrigin( btVector3( 0.0, 0.0, 0.0) );
 
 btCompoundShape* avatar_compound = new btCompoundShape();
 avatar_compound->addChildShape(local_transform, avatar_shape);

 btTransform avatar_transform;
 avatar_transform.setIdentity();
 avatar_transform.setOrigin(btVector3(0.0,0.0,-1.5));

 btVector3 avatar_inertia(0,0,0);
 btScalar avatar_mass(75.0);
 avatar_compound->calculateLocalInertia(avatar_mass, avatar_inertia);

 btDefaultMotionState* avatar_motion_state = new btDefaultMotionState(avatar_transform);
 
 btScalar linear_damping(0.1);
 btScalar angular_damping(0.1);
 btScalar friction(0.0);
 btScalar restitution(0.2);

 btRigidBody* avatar_body = new btRigidBody( avatar_mass,
                                             avatar_motion_state,
                                             avatar_compound,
                                             avatar_inertia,
                                             linear_damping,
                                             angular_damping,
                                             friction,
                                             restitution );

The transform is to match it with the 3d model used for the player inside the capsule.

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

Post by Erwin Coumans »

Dirk Gregorius wrote:There is a capsule type. For some reason it hasn't been in the project files. IIRC in version 2.53 you should find it again.
btCapsuleShape was added to the (automatic generated) projectfiles since previous C++ Bullet release (2.53). It is not available yet in the C# XNA version I think.
I am assuming a capsule is nothing more than two spheres and a box connecting them?
No, a capsule is a sphere swept along a line segment in other words the minkowski sum of the segment and the sphere. So all you need to do is add both support mappings. If you need a tapered capsule you take maximum support value of the two spheres. Gino calls this a generalization to collections of arbitrary convex objects. (s. page 138)
Actually, Bullet's btCapsuleShape is simply the convex hull of 2 spheres, so you can also use btMultiSphereShape with 2 spheres instead.

Erwin