【发布时间】:2018-02-22 16:15:03
【问题描述】:
我想为我的 3D 环境使用 SpriteBatch 创建一个平面空间。为此,我使用了一组简单的方形图像(500*500 像素)在 create() 方法中创建精灵,如下所示。 '坐标'变量是样本建筑模型的位置:
texture = new Texture("tile.png");
matrix.setToRotation(new Vector3(1, 0, 0), 90);
for (int z = 0; z < 10; z++) {
for (int x = 0; x < 10; x++) {
sprites[x][z] = new Sprite(texture);
sprites[x][z].setPosition(coordinate.getEast() + 10 * x, coordinate.getNorth() + 10 * z);
sprites[x][z].setSize(10,10);
}
}
spriteBatch = new SpriteBatch();
然后在 render() 部分中,我使用这个 sn-p 将 spriteBatch 转换并投影到 3D 模型所在的 x-z 平面。 'cam' 是 PerspectiveCamera 的实例。
if (loading && assetManager.update()) {
loadingModel();
}
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glClearColor(0.2f, 0.5f, 0.5f, 1);
/* rendering 3D models */
for (MyModel g : instances) {
g.renderModel(cam);
}
/* rendering sprites */
spriteBatch.setProjectionMatrix(cam.combined);
spriteBatch.setTransformMatrix(matrix);
spriteBatch.begin();
for (int z = 0; z < 10; z++) {
for (int x = 0; x < 10; x++) {
sprites[x][z].draw(spriteBatch);
}
}
spriteBatch.end();
问题:当相机放在地面上时,我的精灵表面显示正常(图 1)。但是当相机的高度增加时,表面似乎也被抬高了,覆盖了地面上的一些建筑物(图2)。投影有问题吗?
【问题讨论】: