在我的游戏中,我需要找出玩家触摸的位置。MotionEvent.getX() 和 MotionEvent.getY() 返回窗口坐标。所以我做了这个函数来测试将窗口坐标转换为OpenGL坐标:
public void ConvertCoordinates(GL10 gl) {
float location[] = new float[4];
final MatrixGrabber mg = new MatrixGrabber(); //From the SpriteText demo in the samples.
mg.getCurrentProjection(gl);
mg.getCurrentModelView(gl);
int viewport[] = {0,0,WinWidth,WinHeight};
GLU.gluUnProject((float) WinWidth/2, (float) WinHeight/2, (float) 0, mg.mModelView, 0, mg.mProjection, 0, viewport, 0, location,0);
Log.d("Location",location[1]+", "+location[2]+", "+location[3]+"");
}
X 和 y 从几乎 -33 振荡到几乎 +33。Z 通常是 10。我使用 MatrixGrabber 是不是错了?