我前一天开始研究 libgdx。我想创建一个三角形,其点应该是两个角应该在左下角和右下角,一个点应该在屏幕的顶部中间。我正在使用透视相机。我的代码示例是:
public class Test1 implements ApplicationListener{
PerspectiveCamera camera;
Mesh triangle;
@Override
public void create() {
// TODO Auto-generated method stub
camera = new PerspectiveCamera(67, 45, 45 / (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()));
camera.near = 1;
camera.far = 200;
triangle = createTriangle();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void render() {
// TODO Auto-generated method stub
GL10 gl = Gdx.gl10;
gl.glClearColor(0, 0, 0, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL10.GL_DEPTH_TEST);
camera.update();
camera.apply(gl);
triangle.render(Gdx.gl10.GL_TRIANGLES);
}
public Mesh createTriangle() {
float[] vertices = {-45f, -27f, -67,
45f, -27f, -67,
0, 27f, -67
};
short[] indices = {0,1,2};
Mesh mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
mesh.setVertices(vertices);
mesh.setIndices(indices);
return mesh;
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
我读到 OpenGL 是无单位的,所以我决定有 45 个单位宽并相应地设置它的高度。当我执行应用程序时,三角形与我预期的不一样。它小于屏幕的宽度和高度。我之前没有 3D 方面的经验。请指导我哪里错了?这是屏幕截图: