2

Alright so I would like to know why when i run this i cannot see the bullet collision objects Prob. a rookie mistake

    public static PerspectiveCamera cam;
static btCollisionWorld collisionWorld;
DebugDrawer debugDrawer;
public ModelBatch modelBatch;
btCollisionConfiguration collisionConfig;
static btDispatcher dispatcher;
btBroadphaseInterface broadphase;
public static btCollisionShape voxelShape;
public static Model model;
public static ModelInstance test;
public static btCollisionShape collisiontest;
public static btCollisionObject collisiontestobject;

@Override
public void create () {
    Bullet.init();
    collisionConfig = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfig);
    broadphase = new btDbvtBroadphase();
    collisionWorld = new btCollisionWorld(dispatcher, broadphase, collisionConfig);

    cam = new PerspectiveCamera(67, 1280, 720);
    cam.position.set(10f,10f,10f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    modelBatch = new ModelBatch();


    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(3f, 3f, 3f,
            new Material(ColorAttribute.createDiffuse(Color.BLUE)),
            Usage.Position | Usage.Normal);

    test = new ModelInstance(model);

    test.transform.setTranslation(0,0,0);

    collisiontest = new btBoxShape(new Vector3 (6f,6f,6f));

    collisiontestobject = new btCollisionObject();
    collisiontestobject.setCollisionShape(collisiontest);
    collisiontestobject.setWorldTransform(new Matrix4());

    debugDrawer = new DebugDrawer();
    debugDrawer.setDebugMode(btIDebugDraw.DebugDrawModes.DBG_MAX_DEBUG_DRAW_MODE);

    collisionWorld.setDebugDrawer(debugDrawer);


}

@Override
public void render () {

    cam.update();


    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);


    debugDrawer.begin(cam);
    collisionWorld.debugDrawWorld();
    debugDrawer.end();

    //modelBatch.begin(cam);
    //modelBatch.render(test);
    //modelBatch.end();


}

When i run this I expected to see the frames of the collision objects but instead I see nothing... This was a test program i created due to having alot of bullet issues..

1 Answers1

2

You are doing everything correct, only a single thing is missing:

collisionWorld.addCollisionObject(collisiontestobject);

After creating the object, you still need to add it to the collision world. That's why the DebugDrawer does not render anything. It simply doesn't know about this object.

noone
  • 19,520
  • 5
  • 61
  • 76
  • 0.0 You sir have helped me so much *I think this is why i've been having so many issues with bullet! i never added it to a world 0.0.* Again thank you so much! –  Jul 30 '14 at 15:01