简体   繁体   English

在横向模式下缝制Android OpenGL ES 3D多维数据集

[英]Android OpenGL ES 3D cube is scewed when in landscape mode

So I have looked absolutely everywhere and can't find the anser. 所以我到处都是绝对的,找不到发疯的人。 When I draw a 3d cube in opengl es for android it seems to look fine as long as I'm in portrait mode but when I switch to landscape it looks more like a diamond. 当我在opengl es中为Android绘制3d立方体时,只要我处于纵向模式,它看起来就很好,但是当我切换到横向时,它看起来更像钻石。 I assume the issue is with the ratio but I really cant say so here's the code i'm using for the ratios. 我认为问题出在比率上,但我真的不能说,因此这是我用于比率的代码。

public void onSurfaceChanged(GL10 gl, int width, int height){
    gl.glViewport(0, 0, width, height);

    float ratio = (float) width/height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 11);
}

The other option that may be the issue I believe is the cube its self but again not sure so here's the vertices and indices. 我认为,另一个可能是问题的选择是多维数据集本身,但同样不确定,因此这里是顶点和索引。

private int vertices[] = {
        -one, -one, -one,
        one, -one, -one,
        one, one, -one,
        -one, one, -one,
        -one, -one, one,
        one, -one, one,
        one, one, one,
        -one, one, one
};

private byte indices[] = {
        0, 4, 5, 0, 5, 1,
        1, 5, 6, 1, 6, 2,
        2, 6, 7, 2, 7, 3,
        3, 7, 4, 3, 4, 0,
        4, 7, 6, 4, 6, 5,
        3, 0, 1, 3, 1, 2
};

Alright so I guess I'm gonna answer my own question here and for all who need it. 好吧,我想我将在这里以及所有需要它的人回答我自己的问题。 I used this ratio code instead under the onSurfaceChanged method. 我在onSurfaceChanged方法下使用了此比率代码。

    double w = width/4.5;
    gl.glViewport(0, (int)-w, width, width);

    float ratio = (float) width/width;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 14);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM