Android y轴上的OpenGL反演
我正在使用OpenGL触摸事件来移动形状,但发生的是屏幕另一侧的形状移动(x轴)。因此,如果尝试移动底部的形状,则顶部的形状将向内移动。右上角为(0480),左下角为(800,0)。我试着改变视图矩阵中的数字,但没有成功。为什么会这样 我确信我已经正确设置了视图和投影矩阵。给你Android y轴上的OpenGL反演,android,opengl-es,Android,Opengl Es,我正在使用OpenGL触摸事件来移动形状,但发生的是屏幕另一侧的形状移动(x轴)。因此,如果尝试移动底部的形状,则顶部的形状将向内移动。右上角为(0480),左下角为(800,0)。我试着改变视图矩阵中的数字,但没有成功。为什么会这样 我确信我已经正确设置了视图和投影矩阵。给你 @Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Set the background cle
@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");
}
if(shapeWmaxX){maxX=shapeW;}
如果(shapeHmaxY){maxY=shapeH;}
//Log.i(“Min&Max”+(i/4),String.valueOf(minX+”,“+maxX+”,“+minY+”,“+maxY));
如果(minX
从原点看,z轴正向您移动,负向屏幕移动。因此,如果我的假设是正确的,你的形状是在z=0平面上绘制的,那么你的眼睛实际上位于它们后面。因此,如果将对象向一个方向移动,它似乎会向另一个方向移动。尝试使用eyeZ的正值
例如,eye=(0,0,3),look=(0,0,0)会将眼睛定位在原点之外,朝向您向下看屏幕的方向。相比之下,使用eye=(0,0,-3),look=(0,0,0)会将眼睛放在屏幕上,向后看。您好,谢谢您的帮助,但它没有起作用。当我尝试旋转右上角的形状时,右下角的形状反而旋转。这是错误的。
setLookAtM
的第6到第8个参数定义了中心,它是一个点,而不是一个向量。对这些值使用全零是很好的。嗨,我还是不明白。这景色似乎渲染得很好。如果我平移它们,或者稍微改变顶点坐标,形状就会出现在我想要它们出现的屏幕上。不正确的是它如何记录触摸事件。有什么想法吗?同意@RetoKoradi,我的错误-相应地编辑了我的答案。我已经有几年没在生气的时候做这些了。。。