OpenGL에서지도를 그렸습니다. 내가 원하는 것은 사용자가 화면을 터치 할 때마다 나는 화면 좌표가 아닌 OpenGL 맵을 기준으로 좌표를 가져와야합니다. 다음실제 좌표를 얻는 방법
내가 시도 코드의 내 작품이다하지만 정확한 좌표를 받고 있지 않다 :보기 재정 onTouch 방법에 대한
// Initialize auxiliary variables.
PointF worldPos = new PointF();
// Auxiliary matrix and vectors
// to deal with ogl.
float[] invertedMatrix, transformMatrix,
normalizedInPoint, outPoint;
invertedMatrix = new float[16];
transformMatrix = new float[16];
normalizedInPoint = new float[4];
outPoint = new float[4];
// Invert y coordinate, as android uses
// top-left, and ogl bottom-left.
int oglTouchY = (int) (scrheigth - touch.Y);
/* Transform the screen point to clip
space in ogl (-1,1) */
normalizedInPoint[0] =
(float) ((touch.X) * 2.0f/scrwidth - 1.0);
normalizedInPoint[1] =
(float) ((oglTouchY) * 2.0f/scrheigth - 1.0);
normalizedInPoint[2] = - 1.0f;
normalizedInPoint[3] = 1.0f;
/* Obtain the transform matrix and
then the inverse. */
Matrix.multiplyMM(
transformMatrix, 0,
mProjMatrix, 0,
mMVPMatrix, 0);
Matrix.invertM(invertedMatrix, 0,
transformMatrix, 0);
/* Apply the inverse to the point
in clip space */
Matrix.multiplyMV(
outPoint, 0,
invertedMatrix, 0,
normalizedInPoint, 0);
if (outPoint[3] == 0.0)
{
// Avoid /0 error.
Log.e("World coords", "ERROR!");
return worldPos;
}
실제로 내가 원하는 것은 OpenGL에 의해 그려진지도의 접촉점의 절대 위치를 얻는 것입니다. –