简体   繁体   English

为OpenGL ES设置ViewPort-Android

[英]Setting Up ViewPort for OpenGL ES - Android

I have an OpenGL ES object which I am trying to draw. 我有一个正试图绘制的OpenGL ES对象。 The object has fairly large vertice values with the x and y co-ordinates lying between -30,000 and +30,000. 该对象的顶点值相当大,x和y坐标在-30,000和+30,000之间。 The z values are between 2000 and -2000. z值在2000到-2000之间。

Can anybody advise me how I should be setting up my viewport ? 有人可以建议我如何设置视口吗? I am using the following code : 我正在使用以下代码:

public void onSurfaceChanged(GL10 gl, int width, int height) {
    //Define the view frustrum
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    float ratio = (float)width/height;
    GLU.gluPerspective(gl, 45.0f, ratio, 1, 100f);
}

public void onDrawFrame (GL10 gl) {
    // Clear the screen to black.
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    //Position the model.
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, 0.0f);
    //gl.glScalef(0.000015f,0.000015f,0.000015f);

This compiles ok, but I cannot see my object at all. 这样可以编译,但是我根本看不到我的对象。

Thank you. 谢谢。

You probably can't see it because your camera's inside the object. 您可能看不到它,因为相机位于对象内部。 Maybe try first scaling it by 0.001 to get it down to about 60 units across, translate it by -50 in the z direction (to get it to the middle of your z range), and see if it shows up then. 也许先尝试将其缩放0.001,以将其缩小到大约60个单位,然后将其在z方向上平移-50(以使其达到z范围的中间),然后查看它是否出现。

Alternatively you could just make your z-range a lot bigger, and translate it by some -50,000 units in the z direction to move the object back from the camera. 另外,您也可以扩大z范围,并在z方向上平移-50,000单位以将对象从相机移回。 You'll have to adjust znear/zfar then to be much larger. 您必须将znear / zfar调整为更大。

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

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