How to create a torus??

Post Reply
gm09
Posts: 9
Joined: Fri Aug 05, 2011 1:27 am

How to create a torus??

Post by gm09 »

Hi,

Does anyone know how to create a torus (rigid body) in bullet?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How to create a torus??

Post by Flix »

See appGImpactTestDemo for it.

Long story: you need an array of vertices/triangle indices, and (for all concave meshes) turn it into a btStridingMeshInterface (or a derived class). Now you can use a btBvhTriangleMeshShape if the object is static, or a btGImpactMeshShape if the object is dynamic.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: How to create a torus??

Post by sparkprime »

You could also make it out of cylinders or something like that.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: How to create a torus??

Post by mi076 »

Code: Select all

{
double subdivisions = 16.0;
double outer_radius = 1.0;
double inner_radius = 0.15;
btVector3 forward(btScalar(0.0),btScalar(1.0),btScalar(0.0));
btVector3 side(btScalar(outer_radius),btScalar(0.0),btScalar(0.0));

// ПИФАГОР
double gap = sqrt(2.0*inner_radius*inner_radius
                         - 2.0*inner_radius*inner_radius*cos((2.0*SIMD_PI)/subdivisions));
btCylinderShapeZ * shape = new btCylinderShapeZ(btVector3(btScalar(inner_radius),
                                                          btScalar(inner_radius),
                                                          btScalar((SIMD_PI/subdivisions) + 0.5*gap)));

btTransform t;
btCompoundShape * torus_shape = new btCompoundShape();

    for (int x = 0; x < (int)subdivisions; x++)
    {
    btScalar angle = btScalar((x*2.0*SIMD_PI)/subdivisions);
    btVector3 position = side.rotate(forward, angle);
    btQuaternion q(forward, angle);
    t.setIdentity();
    t.setOrigin(position);
    t.setRotation(q);
    torus_shape->addChildShape(t, shape);
    }

}
Attachments
torus.jpg
torus.jpg (61.86 KiB) Viewed 8733 times
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: How to create a torus??

Post by sparkprime »

For example, like that :)
Post Reply