我正在尝试使用贴花作为广告牌。贴花似乎被涂好了但是当我移动相机时,贴花似乎是静态的,并且不会转向面对相机。这是我的代码
void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new PerspectiveCamera(75, 10, 10*h/w);
camera.position.set(2.5f,2.5f,5);
camera.direction.set(-1, -1, -1);
camera.up.set(0,1,0);
camera.near = GameConfig.getInstance().camera.wiew_distance_near;
camera.far = GameConfig.getInstance().camera.view_distance_far;
// load textures
plant = Decal.newDecal(1,1,new TextureRegion(textureTree),true);
plant2 = Decal.newDecal(1,1,new TextureRegion(textureTree),true);
plant3 = Decal.newDecal(1,1,new TextureRegion(textureTree),true);
plant.setPosition(1, 2, 0);
plant2.setPosition(3, 5, 0);
plant3.setPosition(5, 5, 0);
decalBatch = new DecalBatch();
for(int z = 0; z < 10; z++) {
for(int x = 0; x < 10; x++) {
sprites[x][z] = new Sprite(texture);
sprites[x][z].setPosition(x,z);
sprites[x][z].setSize(1, 1);
}
}
matrix.setToRotation(new Vector3(1, 0, 0), 90);
}
render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
controller.update(Gdx.graphics.getDeltaTime());
camera.update();
batch.begin();
batch.setProjectionMatrix(camera.combined);
batch.setTransformMatrix(matrix);
for(int z = 0; z < 10; z++) {
for(int x = 0; x < 10; x++) {
sprites[x][z].draw(batch);
}
}
batch.end();
updateDecals();
// decals
decalBatch.add(plant);
decalBatch.add(plant2);
decalBatch.add(plant3);
decalBatch.flush();
Matrix4 viewMatrix = new Matrix4();
viewMatrix.setToOrtho2D(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
UIbatch.setProjectionMatrix(viewMatrix);
UIbatch.begin();
renderUI(UIbatch);
UIbatch.end();
}
void updateDecals() {
plant.lookAt(camera.position.cpy(), new Vector3(0,0,-1));
plant2.lookAt(camera.position.cpy(), new Vector3(0,0,-1));
plant3.lookAt(camera.position.cpy(), new Vector3(0,0,-1));
}
我认为问题出在前一轮旋转以绘制瓷砖地板,但贴花批次无法旋转。