案例位置:examples/Cuda/Rigidbody/GL_CollisionMask
功能介绍:该案例展示了 RigidBodyInfo 类 CollisionMask 属性的的基本使用。案例展示了三维几何模型碰撞掩码功能。该功能能屏蔽指定形状的几何体间的碰撞,支持几何基本单元之间的接触点、接触点法向和穿透距离等计算。
案例说明:案例中最大的球体和正方体设置了掩码功能,所以在掉落的时候不会发生碰撞。其它球体与球体,正方体与正方体能正常发生碰撞。
接下来介绍案例的实现过程:
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
// Boxes are set to being able to collided with other boxes only
rigidBody.collisionMask = CT_BoxOnly;
BoxInfo box;
for (int i = 8; i > 1; i--)
for (int j = 0; j < i + 1; j++)
{
box.center = 0.5f * Vec3f(0.5f, 1.1 - 0.13 * i, 0.12f + 0.21 * j + 0.1 * (8 - i));
box.halfLength = 0.5f * Vec3f(0.065, 0.065, 0.1);
rigid->addBox(box, rigidBody);
}
SphereInfo sphere;
sphere.center = Vec3f(0.5f, 0.75f, 0.5f);
sphere.radius = 0.025f;
RigidBodyInfo rigidSphere;
// Spheres are set to being able to collided with other spheres only
rigidSphere.collisionMask = CT_SphereOnly;
rigid->addSphere(sphere, rigidSphere);
sphere.center = Vec3f(0.5f, 0.95f, 0.5f);
sphere.radius = 0.025f;
rigid->addSphere(sphere, rigidSphere);
sphere.center = Vec3f(0.5f, 0.65f, 0.5f);
sphere.radius = 0.05f;
rigid->addSphere(sphere, rigidSphere);
TetInfo tet;
tet.v[0] = Vec3f(0.5f, 1.1f, 0.5f);
tet.v[1] = Vec3f(0.5f, 1.2f, 0.5f);
tet.v[2] = Vec3f(0.6f, 1.1f, 0.5f);
tet.v[3] = Vec3f(0.5f, 1.1f, 0.6f);
rigid->addTet(tet, rigidSphere);
auto mapper = std::make_shared<DiscreteElementsToTriangleSet<DataType3f>>();
rigid->stateTopology()->connect(mapper->inDiscreteElements());
rigid->graphicsPipeline()->pushModule(mapper);
auto sRender = std::make_shared<GLSurfaceVisualModule>();
sRender->setColor(Vec3f(1, 1, 0));
mapper->outTriangleSet()->connect(sRender->inTriangleSet());
rigid->graphicsPipeline()->pushModule(sRender);