Я создаю приложение для Android, использующее OpenGL ES 2.0, и я столкнулся с стеной. Я пытаюсь преобразовать координаты экрана (где пользователь прикасается) к мировым координатам. Я пробовал читать и играть с GLU.gluUnProject, но я либо делаю это неправильно, либо просто не понимаю.
Это моя попытка...
public void getWorldFromScreen(float x, float y) {
int viewport[] = { 0, 0, width , height};
float startY = ((float) (height) - y);
float[] near = { 0.0f, 0.0f, 0.0f, 0.0f };
float[] far = { 0.0f, 0.0f, 0.0f, 0.0f };
float[] mv = new float[16];
Matrix.multiplyMM(mv, 0, mViewMatrix, 0, mModelMatrix, 0);
GLU.gluUnProject(x, startY, 0, mv, 0, mProjectionMatrix, 0, viewport, 0, near, 0);
GLU.gluUnProject(x, startY, 1, mv, 0, mProjectionMatrix, 0, viewport, 0, far, 0);
float nearX = near[0] / near[3];
float nearY = near[1] / near[3];
float nearZ = near[2] / near[3];
float farX = far[0] / far[3];
float farY = far[1] / far[3];
float farZ = far[2] / far[3];
}
Цифры, которые я получаю, кажутся неправильными, это правильный способ использовать этот метод? Он работает для OpenGL ES 2.0? Должен ли я сделать модельную матрицу единичной матрицей перед этими вычислениями (Matrix.setIdentityM(mModelMatix, 0))?
Как продолжение, если это так, как я могу выбрать выход Z? В принципе, я всегда знаю, на каком расстоянии я хочу, чтобы координаты мира были, но параметр Z в GLU.gluUnProject кажется некоторой интерполяцией между ближней и дальней плоскостью. Это просто линейная интерполяция?
Заранее спасибо