我是 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 对象,构造球体并将其放置在世界中。
那么,你能告诉我如何创建一个里面有一个球的空球体吗?
PS拜托,不要告诉我谷歌,我已经做到了
PPS 对不起我的英语