android - 使用 Bullet 将球置于球体内

标签 android libgdx physics bullet bulletphysics

我是 Bullet 以及所有 3D 和 phisycs 内容的新手,所以不要生气:) 我需要创建一个大的静态刚性球体和一个小的动态球体。我想像瓶子一样使用大的,这样小球体可以在里面移动,但不能离开球体,除了顶部有一个球体。 我在 Blender 中编写了 2 个模型(当然我在大球体上打了一个洞),创建了一个世界并在里面放置了物体。但是当我启动应用程序时,小球体以极快的速度从大球体中抛出。 另外,我正在将 Bullet 与适用于 Android 的 GDX 库一起使用,如果有帮助的话。

此代码初始化世界。

public final btCollisionConfiguration collisionConfiguration;
public final btCollisionDispatcher dispatcher;
public final btBroadphaseInterface broadphase;
public final btConstraintSolver solver;
public final btCollisionWorld collisionWorld;
public PerformanceCounter performanceCounter;
public final Vector3 gravity;   

public int maxSubSteps = 5;

public World() {
    Vector3 gravity = new Vector3(0, -10, 0);

    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);
    broadphase = new btDbvtBroadphase();
    solver = new btSequentialImpulseConstraintSolver();
    collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
    ((btDynamicsWorld)collisionWorld).setGravity(gravity);
    this.gravity = gravity;
}

以及一些用于创建大球体的代码

    final StillModel sphereS = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/Ssphere.obj"));
    sphereS.subMeshes[0].getMesh().scale(3f, 3f, 3f);

    final BoundingBox sphereSBounds = new BoundingBox();
    sphereS.getBoundingBox(sphereSBounds);
    final Constructor sphereSConstructor = new Constructor(sphereS, 0f, new btSphereShape(sphereSBounds.getDimensions().x));
    sphereSConstructor.bodyInfo.setM_restitution(1f);
    world.addConstructor("sphereS", sphereSConstructor);

小球体的代码

    final StillModel sphereModel =          ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/sphere.obj"));
    sphereModel.subMeshes[0].getMesh().scale(0.8f, 0.8f, 0.8f);
    final BoundingBox sphereBounds = new BoundingBox();
    sphereModel.getBoundingBox(sphereBounds);

    final Constructor sphereConstructor = new Constructor(sphereModel, 0.25f, new btSphereShape(sphereBounds.getDimensions().x * 0.5f));
    sphereConstructor.bodyInfo.setM_restitution(1f); 
    world.addConstructor("sphere", sphereConstructor);

构造函数类仅创建 btRigidBodyConstructionInfo 和 btCollisionShape 对象,构造球体并将其放置在世界中。

那么,你能告诉我如何创建一个里面有球的空球体吗?

附注请不要告诉我去谷歌,我已经做到了

P.P.S 对不起我的英语

最佳答案

由于您的大球体不是凸球,因此您不应该使用 btSphereShape。 您可以尝试 btBvhTriangleMeshShape 或其他一些非凸形状。

它的构建有点复杂,但是查看一些示例可能会提供一些想法。不管怎样,没有简单的方法可以得到你想要的东西,因为它甚至不是一个常规的空球体(我认为你使用的 libgdx 框架只需要你的 sphereS 模型进行渲染)。

关于android - 使用 Bullet 将球置于球体内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16651089/

相关文章:

android - 如何在android中使用时间范围剪切音频文件?

android - 如何使用android开发者演示

java - 当 box2d 实体数量超过 300 时,在移动设备上的性能非常低

simulation - 果冻物理 3d

android - 使用警报管理器时出现 java.lang.NullPointerException 错误

android - 依赖配置

java - Assets 在处置和重新加载后不会被渲染

Android 无法使用 LibGDX 打开文件

javascript - 重力如何影响矢量

java - JBullet - 静态时凸形状无法正常工作