Hi,
Does anyone know how to create a torus (rigid body) in bullet?
How to create a torus??
Re: How to create a torus??
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.
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.
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
- Contact:
Re: How to create a torus??
You could also make it out of cylinders or something like that.
Re: How to create a torus??
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 (61.86 KiB) Viewed 8733 times
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
- Contact:
Re: How to create a torus??
For example, like that