gpt4 book ai didi

android - 使用 Bullet 在球体内的球

转载 作者:行者123 更新时间:2023-11-29 00:29:39 24 4
gpt4 key购买 nike

我是 Bullet 以及所有 3D 和物理学方面的新手,所以不要生气 :)我需要创建一个大的静态刚性球体和一个小的动态球体。我想像瓶子一样使用大的,所以小球体可以在里面移动,但不能离开球体,除了顶部的一个。我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com