2

I'm new at Bullet and all 3D and phisycs stuffs, so don't be angry :) I neen to create a big static rigid sphere and a little dynamic one inside. I want to use the big one like a bottle, so little sphere can move inside, but cann't leave the sphere, exept one plase on the top. I have written 2 models in Blender (of course i've made a hole in big sphere), created a world and placed objects inside. But when i start the application, the little sphere just throw out of the big one with extreme speed. Also I'm using Bullet with GDX library for Android, if it helps.

This code initializes the world.

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;
}

And some code for creating a big sphere

    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);

Code for a little sphere

    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);

Constructor class just creates btRigidBodyConstructionInfo and btCollisionShape objects, constructs spheres and place there in the world.

So, could you tell me how can i create an empty sphere with a ball inside?

P.S. Please, don't tell me to google, i've already done it

P.P.S Sorry for my english

  • Perhaps the little sphere thinks it´s the bullet ;) But more seriously, how did you construct the big sphere, is it empty inside? – flup May 20 '13 at 14:15
  • I think so. I've read some manuals before. An example http://blog.pdark.de/2007/11/12/hollow-sphere-in-blender/ – massaraksh111 May 20 '13 at 15:13

2 Answers2

1

Since your big sphere is not convex, you should not be using btSphereShape for it. You could try btBvhTriangleMeshShape, or some of the other non-convex shapes.

It is a bit more complicated to construct, but looking at some examples might provide ideas. Anyway, there is no simple way to get what you want, because it is not even a regular empty sphere (I think the libgdx framework you are using only takes your sphereS model for rendering).

Gnurfos
  • 980
  • 2
  • 10
  • 29
1
Model sphere = modelBuilder.createSphere(-100f, 100f, 100f, 20, 20, new  Material(ColorAttribute.createDiffuse(Color.BLUE)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

ModelInstance instance = new ModelInstance(sphere);

btBvhTriangleMeshShape  sphereShape = new btBvhTriangleMeshShape(instance.model.meshParts);

btRigidBody.btRigidBodyConstructionInfo constructionInfo = new btRigidBody.btRigidBodyConstructionInfo(0, null, sphereShape, new Vector3(0,0,0));

btRigidBody body = new btRigidBody(constructionInfo);

body.setCollisionFlags(body.getCollisionFlags()| btCollisionObject.CollisionFlags.CF_STATIC_OBJECT);

dynamicsWorld.addRigidBody(body);

it works

Alex
  • 11
  • 1