在y轴上的OpenGL反转

时间:2015-09-14 22:23:38

标签: android opengl-es

我使用OpenGL触摸事件来移动形状,但会发生的是屏幕另一侧的形状移动(x轴)。因此,如果您尝试在底部移动形状,则顶部的形状将移动到内部。右上角是(0,480),左下角是(800,0)。我试过在视图矩阵中更改数字,但它没有用。为什么会这样?

我确定我已正确设置了我的视图和投影矩阵。他们在这里。

@Override
    public void onSurfaceCreated(GL10 unused, EGLConfig config) {

        // Set the background clear color to gray.
        GLES20.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);

        GLES20.glFrontFace(GLES20.GL_CCW); // Counter-clockwise winding.
        GLES20.glEnable(GLES20.GL_CULL_FACE);// Use culling to remove back faces.
        GLES20.glCullFace(GLES20.GL_BACK);// What faces to remove with the face culling.
        GLES20.glEnable(GLES20.GL_DEPTH_TEST);// Enable depth testing

        // Position the eye behind the origin.
        final float eyeX = 0.0f;
        final float eyeY = 0.0f;
        final float eyeZ = -3.0f;

        // We are looking toward the distance
        final float lookX = 0.0f;
        final float lookY = 0.0f;
        final float lookZ = 0.0f;

        // Set our up vector. This is where our head would be pointing were we holding the camera.
        final float upX = 0.0f;
        final float upY = 1.0f;
        final float upZ = 0.0f;

        Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
        Matrix.setIdentityM(mViewMatrix, 0);

    }

    @Override
    public void onSurfaceChanged(GL10 unused, int width, int height) {
        // Sets the current view port to the new size.
        GLES20.glViewport(0, 0, width, height);

        float RATIO = (float) width / (float) height;

        // this projection matrix is applied to object coordinates in the onDrawFrame() method
        Matrix.frustumM(mProjectionMatrix, 0, -RATIO, RATIO, -1, 1, 1, 10);
        Matrix.setIdentityM(mProjectionMatrix, 0);
    }

更新

视图似乎正确呈现。如果我翻译它们,或者稍微改变顶点坐标,形状将出现在我想要它们的屏幕上。什么不对,它是如何记录触摸事件的。有什么想法吗?

这是我检查触摸事件的方式。

if(shapeW < minX){minX = shapeW;}
                if(shapeW > maxX){maxX = shapeW;}
                if(shapeH < minY){minY = shapeH;}
                if(shapeH > maxY){maxY = shapeH;}

                //Log.i("Min&Max" + (i / 4), String.valueOf(minX + ", " + maxX + ", " + minY + ", " + maxY));

                if(minX < MyGLSurfaceView.touchedX && MyGLSurfaceView.touchedX < maxX && minY < MyGLSurfaceView.touchedY && MyGLSurfaceView.touchedY < maxY)
                {
                    xAng[j] = xAngle;
                    yAng[j] = yAngle;
                    Log.i("cube "+j, " pressed");
                   }

1 个答案:

答案 0 :(得分:1)

从原点开始,z轴正向你走,负向走向屏幕。因此,如果我的假设是正确的,你的形状是在z = 0平面上绘制的,那么你的眼睛实际上就位于它们后面。因此,如果您以一种方式移动对象,则它会以另一种方式移动。请尝试使用eyeZ的正值。

例如,eye =(0,0,3),look =(0,0,0)会将眼睛从原点朝向俯视屏幕的方向定位。相比之下,使用eye =(0,0,-3),look =(0,0,0)会将眼睛放回屏幕中向后看。

相关问题