gpt4 book ai didi

android - y 轴上的 OpenGL 反转

转载 作者:行者123 更新时间:2023-11-30 01:53:52 25 4
gpt4 key购买 nike

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

我确定我已经正确设置了 View 和投影矩阵。他们在这里。

@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);
}

更新

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

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

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");
}

最佳答案

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

例如,eye = (0, 0, 3), look = (0, 0, 0) 会将眼睛定位在原点之外,朝向您俯视屏幕。相反,使用 eye = (0, 0, -3),look = (0, 0, 0) 会使眼睛进入屏幕并向后看。

关于android - y 轴上的 OpenGL 反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32574868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com