2

好的,所以我想知道为什么当我运行它时我看不到子弹碰撞对象Prob。菜鸟的错误

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


}

当我运行它时,我希望看到碰撞对象的框架,但我什么也没看到......这是我创建的一个测试程序,因为有很多子弹问题......

4

1 回答 1

2

您所做的一切都是正确的,只缺少一件事:

collisionWorld.addCollisionObject(collisiontestobject);

创建对象后,您仍然需要将其添加到碰撞世界中。这就是为什么DebugDrawer不渲染任何东西的原因。它根本不知道这个对象。

于 2014-07-30T04:59:41.133 回答