好吧所以我想知道为什么当我跑这个时我看不到子弹碰撞对象 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();
}
当我运行这个时,我希望看到碰撞对象的帧,但我什么也看不见...... 这是我创建的一个测试程序,因为有很多子弹问题..
答案 0 :(得分:2)
你正在做的一切都是正确的,只缺少一件事:
collisionWorld.addCollisionObject(collisiontestobject);
创建对象后,您仍需要将其添加到碰撞世界中。这就是DebugDrawer
不呈现任何内容的原因。它根本不知道这个对象。